10
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

分散表現の可視化はwhatliesが楽

10
Last updated at Posted at 2022-07-19

はじめに

BERTやWord2Vecの分散表現の可視化がインタラクティブでできるライブラリです。
transformersやgensimのimportも不要です。

バージョン:whatlies==0.6.3

実行ノートブック:

分散表現空間

from whatlies import EmbeddingSet
from whatlies.language import HFTransformersLanguage
from whatlies.transformers import Pca

lang = HFTransformersLanguage('cl-tohoku/bert-base-japanese-whole-word-masking')

words = ["先生", "教師", "学生", "社員", "研究者", "会社員", "医者", "銀行員"]
emb = EmbeddingSet(*[lang[w] for w in words])
emb.transform(Pca(2))
emb.plot_interactive()
"""widthとheightも設定できる
res = emb.plot_interactive()
res.config = {"view": {"continuousWidth": 1500, "continuousHeight": 1500}}
"""

visualization.png

ベクトル

lang[""].plot(kind="arrow")
lang[""].plot(kind="arrow")
lang[""].plot(kind="arrow")

Unknown.png

参考

10
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?