如何保存gensim doc2vec模型

时间:2017-06-18 09:32:35

标签: python gensim doc2vec

训练模型后,我使用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`

1 个答案:

答案 0 :(得分:0)

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