简体   繁体   中英

Gensim: how to load pretrained doc2vec model?

I'm trying to read my pretrained doc2vec model:

from gensim.models import Doc2Vec
model = Doc2Vec.load('/path/to/pretrained/model')

However, an error appears during reading process. Could anyone suggest how to deal with this? Here is the error:

AttributeErrorTraceback (most recent call last)
<ipython-input-9-819b254ac835> in <module>()
----> 1 model = Doc2Vec.load('/path/to/pretrained/model')

/opt/jupyter-notebook/.local/lib/python2.7/site-packages/gensim/models/word2vec.pyc in load(cls, *args, **kwargs)
   1682     @classmethod    
   1683     def load(cls, *args, **kwargs):
-> 1684         model = super(Word2Vec, cls).load(*args, **kwargs)
   1685         # update older models
   1686         if hasattr(model, 'table'):

/opt/jupyter-notebook/.local/lib/python2.7/site-packages/gensim/utils.pyc in load(cls, fname, mmap)
    246         compress, subname = SaveLoad._adapt_by_suffix(fname)
    247 
--> 248         obj = unpickle(fname)
    249         obj._load_specials(fname, mmap, compress, subname)
    250         return obj

/opt/jupyter-notebook/.local/lib/python2.7/site-packages/gensim/utils.pyc in unpickle(fname)
    909     with smart_open(fname) as f:
    910         # Because of loading from S3 load can't be used (missing readline in smart_open)
--> 911         return _pickle.loads(f.read())
    912 
    913 

AttributeError: 'module' object has no attribute 'defaultdict'

正如对该问题的评论所述,这很可能与gensim中的一个问题有关,该问题已在0.13.4版本中修复。

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