Skip to content

Commit

Permalink
Fix backwards compatibility bug in Word2Vec (#3415)
Browse files Browse the repository at this point in the history
* add missing model file

* update test
  • Loading branch information
mpenkov committed Dec 16, 2022
1 parent 45d35ee commit db90a6a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 0 additions & 3 deletions gensim/models/word2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1986,9 +1986,6 @@ def _load_specials(self, *args, **kwargs):
for a in ('hashfxn', 'layer1_size', 'seed', 'syn1neg', 'syn1'):
if hasattr(self.trainables, a):
setattr(self, a, getattr(self.trainables, a))
if hasattr(self, 'syn1'):
self.syn1 = self.syn1
del self.syn1
del self.trainables
if not hasattr(self, 'shrink_windows'):
self.shrink_windows = True
Expand Down
Binary file added gensim/test/test_data/model-from-gensim-3.8.0.w2v
Binary file not shown.
7 changes: 7 additions & 0 deletions gensim/test/test_word2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,13 @@ def test_persistence(self):
self.assertTrue(np.allclose(wv.vectors, loaded_wv.vectors))
self.assertEqual(len(wv), len(loaded_wv))

def test_persistence_backwards_compatible(self):
"""Can we still load a model created with an older gensim version?"""
path = datapath('model-from-gensim-3.8.0.w2v')
model = word2vec.Word2Vec.load(path)
x = model.score(['test'])
assert x is not None

def test_persistence_from_file(self):
"""Test storing/loading the entire model trained with corpus_file argument."""
with temporary_file(get_tmpfile('gensim_word2vec.tst')) as corpus_file:
Expand Down

0 comments on commit db90a6a

Please sign in to comment.