我正在运行下面的代码,但gensim word2vec正在抛出一个词而不是词汇错误.你能让我知道解决方案吗?
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'])
Run Code Online (Sandbox Code Playgroud)
输出:
KeyError: "word 'quick' not in vocabulary"
Run Code Online (Sandbox Code Playgroud)
但如果我用这个
print(model['The quick brown fox jumped over the lazy dog'])
Run Code Online (Sandbox Code Playgroud)
它打印一个列表
[ 1.60348183e-03 -9.17983416e-04 -8.30831763e-04 9.46367683e-04
Run Code Online (Sandbox Code Playgroud)