2017-10-31 7 views
0

私は以下のコードを実行していますが、gensim word2vecは語彙エラーでない言葉を投げています。あなたは私に解決策を教えてもらえますか?gensim:KeyError例外:「言葉は語彙に 『速い』ではない」

import logging 
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO) 

sentences = [["The quick brown fox jumped over the lazy dog"], 
     ["The sun is shining bright"]] 

from gensim.models import word2vec 
model = word2vec.Word2Vec(sentences, iter=10, min_count=1, size=300, workers=4) 

print(model['quick']) 

出力:

KeyError: "word 'quick' not in vocabulary" 

しかし、私はこの

print(model['The quick brown fox jumped over the lazy dog']) 

を使用している場合、それはリスト

[ 1.60348183e-03 -9.17983416e-04 -8.30831763e-04 9.46367683e-04 

答えて

4

文はすなわち

、トークンのリストでなければなりません印刷しますそれの後

sentences = ["The quick brown fox jumped over the lazy dog".split(), 
      "The sun is shining bright".split()] 

から210

変更

sentences = [["The quick brown fox jumped over the lazy dog"], 
      ["The sun is shining bright"]] 

- すべてが正常にご返信用

print(model['quick']) 

[ 1.44969602e-03 1.22959237e-03 -6.55176700e-04 -4.09452856e-04 8.06640834e-04 1.05476158e-03 -9.90176341e-04 ...

+0

おかげで動作します。 –

関連する問題