0

当我从 pkl 文件加载 doc2vec 模型时,出现此错误。

    ---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-45-5ed9dc71f3a6> in <module>()
----> 1 temp_docky.infer_vector(['paypal'])

C:\Users\Laxmikant\Anaconda\lib\site-packages\gensim\models\doc2vec.pyc in infer_vector(self, doc_words, alpha, min_alpha, steps)
    750                 train_document_dm(self, doc_words, doctag_indexes, alpha, work, neu1,
    751                                   learn_words=False, learn_hidden=False,
--> 752                                   doctag_vectors=doctag_vectors, doctag_locks=doctag_locks)
    753             alpha = ((alpha - min_alpha) / (steps - i)) + min_alpha
    754 

C:\Users\Laxmikant\Anaconda\lib\site-packages\gensim\models\doc2vec_inner.pyx in gensim.models.doc2vec_inner.train_document_dm (./gensim/models/doc2vec_inner.c:5165)()
    406     # default vectors, locks from syn0/doctag_syn0
    407     if word_vectors is None:
--> 408        word_vectors = model.wv.syn0
    409     _word_vectors = <REAL_t *>(np.PyArray_DATA(word_vectors))
    410     if doctag_vectors is None:

AttributeError: 'Doc2Vec' object has no attribute 'wv'

你能帮忙解决错误吗?

4

1 回答 1

0

模型是从哪个版本的 gensim 中保存的,您要将它加载到哪个版本中?(在最近的版本中,词向量在模型中的存储方式发生了变化。)

通常 gensim 已尝试确保旧模型正确加载,但某些版本在这种向后兼容性方面存在疏忽......所以也值得尝试最新的 gensim,看看它是否加载您的旧模型而没有此错误。(如果它给出了相同的错误,请在项目讨论列表Github 项目错误跟踪器上将其报告为错误。)

于 2017-05-15T22:54:31.940 回答