我在gensim中有一個word2vec模型,通過98892文檔進行了培訓。對於在句子數組中不存在的任何給定的句子(即,我對該模型進行訓練的集合),我需要用該句子更新模型,以便下次查詢它會給出一些結果。我這樣做是這樣的:更新gensim word2vec模型
new_sentence = ['moscow', 'weather', 'cold']
model.train(new_sentence)
和其打印此爲日誌:
2014-03-01 16:46:58,061 : INFO : training model with 1 workers on 98892 vocabulary and 100 features
2014-03-01 16:46:58,211 : INFO : reached the end of input; waiting to finish 1 outstanding jobs
2014-03-01 16:46:58,235 : INFO : training on 10 words took 0.1s, 174 words/s
現在,當我有類似new_sentence大多數陽性查詢(如model.most_similar(positive=new_sentence)
)它給出了錯誤:
Traceback (most recent call last):
File "<pyshell#220>", line 1, in <module>
model.most_similar(positive=['moscow', 'weather', 'cold'])
File "/Library/Python/2.7/site-packages/gensim/models/word2vec.py", line 405, in most_similar
raise KeyError("word '%s' not in vocabulary" % word)
KeyError: "word 'cold' not in vocabulary"
這表明「冷」這個詞不是我訓練這個東西的詞彙的一部分(我是對的)嗎?
所以問題是:如何更新模型,以便給出給定新句子的所有可能的相似性?
有人已將genism的「Word2Vec」更新爲「在線Word2Vec」。你可以在哪裏使用在線學習來更新詞彙表並學習新詞彙。我還沒有嘗試過,但檢查出來在: http://rutumulkar.com/blog/2015/word2vec/ –