0

训练模型后,我使用 infer_vector() 成功获取向量。但是我保存模型并再次加载后,出现如下错误:

print "infer:", model.infer_vector(sents[0]).tolist()
File "/Users/zhangweimin/anaconda/lib/python2.7/site-packages/gensim/models/doc2vec.py", line 752, in infer_vector
    doctag_vectors=doctag_vectors, doctag_locks=doctag_locks)
File "gensim/models/doc2vec_inner.pyx", line 426, in gensim.models.doc2vec_inner.train_document_dm (./gensim/models/doc2vec_inner.c:5401)
TypeError: object of type 'NoneType' has no len()

整个代码是:`

model = train_d2v(labeled_docs, model_file, word_file, 3)

# OK
print "before infer:", model.infer_vector(sents[0]).tolist()

model = Doc2Vec.load(model_file)

print "sents[0]:", sents[0]
print "type:", type(model)
print "infer:", model.infer_vector(sents[0]).tolist() #ERROR`
4

1 回答 1

0

根据上面的评论,使用更新版本的 gensim (2.1.0) 解决了这个问题。

于 2017-06-20T20:09:07.710 回答