You can use the wrapper provided by gensim.
gensim: models.wrappers.fasttext – FastText Word Embeddings
Model learning:
$ fasttext skipgram -input data.txt -output model
$ ls model*
model.bin model.vec
gensim installation:
$ pip install gensim
How to use:
>>> from gensim.models.wrappers.fasttext import FastText
>>> model = FastText.load_fasttext_format('model')
>>> model['Sales']
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('Sales')
[('Sales position', 0.7841936945915222),
('Teleapo', 0.7670873403549194),
('Dive', 0.7659018039703369),
('Telephone sales', 0.7384717464447021),
...]
The model learning itself can be done from the wrapper of gensim, but it seems that there is not much merit, so it is omitted.
Recommended Posts