LoginSignup
20

More than 5 years have passed since last update.

fastTextの学習済みモデルをPythonから使う

Last updated at Posted at 2017-03-21

gensim が提供しているラッパーが使える。

gensim: models.wrappers.fasttext – FastText Word Embeddings

モデル学習:

$ fasttext skipgram -input data.txt -output model
$ ls model*
model.bin  model.vec

gensim のインストール:

$ pip install gensim

使い方:

>>> from gensim.models.wrappers.fasttext import FastText
>>> model = FastText.load_fasttext_format('model')
>>> model['営業']
array([-0.03654   ,  0.19302   ,  0.2026    ,  0.14026   ,  0.06685   ,
        0.10969   , -0.095857  , -0.20964   , -0.27291   , -0.33750001,
        ...
        0.47084001, -0.030295  , -0.003683  , -0.10061   ,  0.17308   ], dtype=float32)
>>> m.most_similar('営業')
[('営業職', 0.7841936945915222),
 ('テレアポ', 0.7670873403549194),
 ('飛込', 0.7659018039703369),
 ('電話営業', 0.7384717464447021),
 ...]

モデル学習自体を gensim のラッパーから行うこともできるが、あまりメリットが無さそうなので省略。

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
20