Fasttext for Python - module 'fasttext' has no attribute 'load_model'

spencerktm30 picture spencerktm30 · Jul 28, 2017 · Viewed 11.3k times · Source

Please forgive my newbness here, but fasttext is not working for me on python. I am using anaconda running python 3.6. My code is as follows(just an example):

import fasttext 

model = fasttext.load_model('/home/sproc/share/fastText/model.bin')
print(model.words)

This returns the following error:

Traceback (most recent call last):
  File "/media/sf_VBoxShare/LiClipseWorkspace/test/testpack/fasttext.py", line 1, in <module>
    import fasttext 
  File "/media/sf_VBoxShare/LiClipseWorkspace/test/testpack/fasttext.py", line 3, in <module>
   model = fasttext.load_model('/home/sproc/share/fastText/model.bin')
AttributeError: module 'fasttext' has no attribute 'load_model'

Does the same thing with cbow and skipgram when trying to create word vectors. I check the init.py file from the .../site-packages/fasttext directory and it imports said attributes, but they are not part of the model.py module. I'm guessing this has something to do with the shared object file but I am not sure. Any help is greatly appreciated.

Answer

sammy ongaya picture sammy ongaya · Feb 24, 2019

Here is a solution that worked for me when I got the error you are getting;

Import FastText

from gensim.models.wrappers import FastText 

Load the binary

model=FastText.load_fasttext_format('wiki.simple.bin')