2017-01-18 205 views
0

我也在Gensim支持論壇上對Google進行了研究,但是我找不到一個好答案。Gensim分割錯誤

基本上,我實現用Gensim爲Doc2Vec在線學習,但Gensim不斷拋出我所謂的「分割

隨機誤差

請看看我的示例代碼

from gensim.models import Doc2Vec 
from gensim.models.doc2vec import LabeledSentence 
import random 
import logging 

if __name__ == "__main__": 
    logging.basicConfig(level=logging.INFO) 

    sentence1 = "this is a test" 
    sentence2 = "test test 123 test" 
    sentence3 = "qqq zzz" 
    sentence4 = "ppp" 

    sentences = [ 
     LabeledSentence(sentence1.split(), ["p1"]), 
     LabeledSentence(sentence2.split(), ["p2"]) 
    ] 
    model = Doc2Vec(min_count=1, window=5, size=400, sample=1e-4, negative=5, workers=1) 
    model.build_vocab(sentences) 

    for a in range(2): 
     random.shuffle(sentences) 
     print([s.tags[0] for s in sentences]) 
     model.train(sentences) 
    model.save("test.d2v") 

    new_model = Doc2Vec.load("test.d2v") 
    new_sentences = [ 
     LabeledSentence(sentence1.split(), ["n1"]), 
     LabeledSentence(sentence3.split(), ["n2"]) 
    ] 
    new_model.build_vocab(new_sentences, update=True) 

    for a in range(4): 
     random.shuffle(new_sentences) 
     print([s.tags[0] for s in new_sentences]) 
     new_model.train(new_sentences) 

這裏是我的錯誤

INFO:gensim.models.word2vec:training model with 1 workers on 7 vocabulary and 400 features, using sg=0 hs=0 sample=0.0001 negative=5 window=5 
INFO:gensim.models.word2vec:expecting 2 sentences, matching count from corpus used for vocabulary survey 
Segmentation fault 

誰能給我解釋一下爲什麼?如何解決這個問題?

謝謝

回答

0

段錯誤 - 即非法內存訪問 - 幾乎不可能從您的Python代碼觸發。這表明這可能是特定於您的安裝/配置的問題 - 操作系統,Python,gensim,支持庫 - 甚至是損壞的文件。

嘗試清除&重新安裝Python環境&支持庫(如NumPy的和SciPy的),並確認其中的一些例子捆綁gensim運行無段故障 - 在docs/notebooks/doc2vec-lee.ipynb像例如筆記本計算機。如果使用捆綁的示例或自己的代碼仍然會出現此類錯誤,請打開調試日誌記錄,捕獲所有輸出,並在OS/Python/gensim/etc版本中報告有關完整詳細信息的問題。

+0

如何知道我的操作系統,Python或gensim有問題?我使用Docker與python:3映像來運行該代碼(請參閱我的問題)。 –

+0

這些都很難調試 - 但也很罕見,一旦你有正確/最新版本的東西。 Docker鏡像中的OS /版本是什麼?新鮮開始(或卸載/重新安裝所有主要軟件包)是否做出任何更改?你有沒有試過在gensim裏面運行例子來看它們是否工作?採取這些措施是如何縮小問題的範圍。 – gojomo