Gensim 的 Doc2vec 中的 Index2word 引发属性错误

Index2word in Gensim's Doc2vec raises an Attribute error

我训练了一个 doc2vec (gensim.models.Doc2Vec) 模型,现在我正在使用这一行:

print(dict([(model.index2word[i], similarity) for i, similarity in enumerate(model.similar_by_word('igdumd32.dll@0x', topn=False))])['igdumd64.dll@0x'])

但它产生了这个错误: AttributeError: 'Doc2Vec' 对象没有属性 'index2word'

我正在使用 gensim 1.0.1

你能帮忙吗?

词向量的 index2word 列表在最近的 gensim 版本中已经移动到模型的 wv 属性,所以你会说 model.index2word 的地方你必须现在使用 model.wv.index2word

(请注意,这仍然只是词向量,仅由 "DM" dm=1 Doc2Vec 模式训练。文档向量位于 model.docvecs 对象中,而您可以在 model.docvecs.offset2doctag 中看到文档向量可能关联的字符串标签列表。)