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

Fix Doc2Vec.infer_vector after loading old Doc2Vec (gensim<=3.2). Fix #1952 #1974

Merged
merged 3 commits into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion gensim/models/deprecated/doc2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def load_old_doc2vec(*args, **kwargs):
'dbow_words': old_model.dbow_words,
'dm_concat': old_model.dm_concat,
'dm_tag_count': old_model.dm_tag_count,
'docvecs': old_model.__dict__.get('docvecs', None),
'docvecs_mapfile': old_model.__dict__.get('docvecs_mapfile', None),
'comment': old_model.__dict__.get('comment', None),
'size': old_model.vector_size,
Expand Down
2 changes: 1 addition & 1 deletion gensim/models/keyedvectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,7 @@ def index_to_doctag(self, i_index):
"""Return string key for given i_index, if available. Otherwise return raw int doctag (same int)."""
candidate_offset = i_index - self.max_rawint - 1
if 0 <= candidate_offset < len(self.offset2doctag):
return self.ffset2doctag[candidate_offset]
return self.offset2doctag[candidate_offset]
else:
return i_index

Expand Down
4 changes: 4 additions & 0 deletions gensim/test/test_doc2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def testLoadOldModel(self):
self.assertTrue(model.docvecs.max_rawint == 299)
self.assertTrue(model.docvecs.count == 300)

self.model_sanity(model)

# Model stored in multiple files
model_file = 'doc2vec_old_sep'
model = doc2vec.Doc2Vec.load(datapath(model_file))
Expand All @@ -118,6 +120,8 @@ def testLoadOldModel(self):
self.assertTrue(model.docvecs.max_rawint == 299)
self.assertTrue(model.docvecs.count == 300)

self.model_sanity(model)

def test_unicode_in_doctag(self):
"""Test storing document vectors of a model with unicode titles."""
model = doc2vec.Doc2Vec(DocsLeeCorpus(unicode_tags=True), min_count=1)
Expand Down