我尝试使用 word2vec,但在尝试对任何单词执行任何操作时都会出错。这似乎是一个编码问题,这是我所做的:
初始化 word2vec:
import gensim, logging
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
model = gensim.models.Word2Vec.load_word2vec_format('freebase-vectors-skipgram1000/knowledge-vectors-skipgram1000.bin', binary=True)
model.init_sims(replace=True)
稍微测试一下:
print(model)
# prints: Word2Vec(vocab=1422903, size=1000, alpha=0.025)
print(model.index2word[0])
# prints: u'/m/0dgps15'
# I would expect a readable word, how to fix that?
错误:
print(model.similarity('word', 'sound'))
# An error happen: KeyError: 'word'
我也尝试用 加载模型binary=False
,但这在加载时出错。