简体   繁体   中英

How to save gensim doc2vec model

after train the model, I use infer_vector() to get the vector successfully. but after I save the model and load again, error appears as follows:

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()

the whole code is:`

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`

如上所述,使用最新版本的gensim(2.1.0)解决了此问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM