2017-10-31 10 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

문장이 토큰의 목록이어야합니다 목록, 즉를 출력 사용하는 경우

,691,363 (210)

변화

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

그 후

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

에 - 모두가 제대로 답장을 보내

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

덕분에 작동합니다. –