2017-07-28 28 views
0

請原諒我在這裏的新鮮感,但是fasttext在Python上並不適合我。我正在使用運行python 3.6的anaconda。我的代碼如下(只是一個例子):Fasttext for Python - 模塊'fasttext'沒有屬性'load_model'

import fasttext 

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

這將返回以下錯誤:

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' 

試圖創建詞矢量時做同樣的事情與cbow和skipgram。我檢查.../site-packages/fasttext目錄中的init .py文件,並且它會導入所述屬性,但它們不是model.py模塊的一部分。我猜這與共享對象文件有關,但我不確定。任何幫助是極大的讚賞。

+0

它看起來像一些二進制文件丟失 – Akshay

+0

@akshay任何想法可能是什麼?我在'〜/ share/fasttext'下安裝了fasttext(標準c工具),並且我使用'pip install fasttext'安裝了fasttext,所以我不確定可能是什麼問題。 – spencerktm30

+0

您是否在使用Anaconda。如果是這樣的話,Cython應該能夠編譯它。如果不嘗試安裝Anaconda,然後用pip – Akshay

回答

0

@ spencerktm30我推薦你使用pyfasttext而不是fasttext,它不再活躍,它有很多bug。鏈接到pyfasttext

實際上,當我嘗試加載一個C++預訓練模型時遇到了類似的問題,我不得不切換到使用pyfasttext使其工作。

所以這應該有希望爲你工作:

>>> from pyfasttext import FastText 
>>> model = FastText('/home/sproc/share/fastText/model.bin') 
+0

雖然這可能在理論上回答這個問題,但[這將是更可取的](// meta.stackoverflow.com/q/8259)在此包含答案的基本部分,並提供供參考的鏈接。 –

+1

@MatthiasSeifert我編輯了評論,我希望它看起來更好。 – Rihab

相關問題