Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issues while loading word2vec and doc2vec models saved using old Gensim versions. Fix #2000, #1977 #2012

Merged
merged 13 commits into from
Apr 12, 2018
Merged
5 changes: 3 additions & 2 deletions gensim/models/deprecated/doc2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,12 @@ def load_old_doc2vec(*args, **kwargs):
# set doc2vec vocabulary attributes
new_model.docvecs.doctags = old_model.docvecs.doctags
new_model.docvecs.count = old_model.docvecs.count
if hasattr(old_model.docvecs, 'max_rawint'): # `doc2vec` models before `0.12.3` do not have these 2 attributes
if hasattr(old_model.docvecs, 'max_rawint'): # `doc2vec` models before `0.12.3` do not have these 2 attributes
new_model.docvecs.max_rawint = old_model.docvecs.__dict__.get('max_rawint')
new_model.docvecs.offset2doctag = old_model.docvecs.__dict__.get('offset2doctag')
else:
new_model.docvecs.max_rawint = len(old_model.docvecs.index2doctag) if old_model.docvecs.index2doctag else old_model.docvecs.count
new_model.docvecs.max_rawint = \
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic: definitely deserves a comment.

len(old_model.docvecs.index2doctag) - 1 if old_model.docvecs.index2doctag else old_model.docvecs.count - 1
new_model.docvecs.offset2doctag = old_model.docvecs.index2doctag

new_model.train_count = old_model.__dict__.get('train_count', None)
Expand Down