0
0

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.

FastTextで単語の類似度が出るまで

Posted at

今後どこかで使いそうなのでメモ程度に

項目

  1. 学習済みのモデルを取ってくる
  2. gensimに持ってきたモデルをロード
  3. 単語のベクトル化や単語同士の類似度を出す

1.学習済みのモデルを取ってくる

ここからcc.ja.300.vec.gzというファイルをダウンロード。
(japanで検索すれば見つかるはず)

2.gensimに持ってきたモデルをロード

python
import gensim

model_path = '/content/drive/MyDrive/Colab Notebooks/fasttextmodel/cc.ja.300.vec.gz'
model = gensim.models.KeyedVectors.load_word2vec_format(model_path, binary=False)

3. 単語のベクトルやそれら類似度を出す

python
# ベクトルが近い単語を一括して出力
print(model.most_similar('~~~~', topn=10))

# 単語同士の類似度を出力
print(model.similarity('~~~', '~~~'))
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?