Skip to content

Commit

Permalink
Fix #1230. Fix word2vec reset_from bug in v1.0.1 and added unittest (#…
Browse files Browse the repository at this point in the history
…1234)

* Update CHANGELOG.txt

* Update CHANGELOG.txt

* Release version typo fix

* Typo in version

* Upgraded to match word2vec class structure

* Added unittest for reset_from

* Fixed typo

* Positive reset_from() unittest

* Change unittest to check if attributes are shared

* Formatting fixed
  • Loading branch information
Kreiswolke authored and tmylk committed Mar 27, 2017
1 parent fe49d98 commit d00b6c1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gensim/models/word2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,8 @@ def reset_from(self, other_model):
Borrow shareable pre-built structures (like vocab) from the other_model. Useful
if testing multiple models in parallel on the same corpus.
"""
self.wv.vocab = other_model.vocab
self.wv.index2word = other_model.index2word
self.wv.vocab = other_model.wv.vocab
self.wv.index2word = other_model.wv.index2word
self.cum_table = other_model.cum_table
self.corpus_count = other_model.corpus_count
self.reset_weights()
Expand Down
10 changes: 10 additions & 0 deletions gensim/test/test_word2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,16 @@ def test_sentences_should_not_be_a_generator(self):
def testLoadOnClassError(self):
"""Test if exception is raised when loading word2vec model on instance"""
self.assertRaises(AttributeError, load_on_instance)

def test_reset_from(self):
"""Test if reset_from() uses pre-built structures from other model"""
model = word2vec.Word2Vec(sentences, min_count=1)
other_model = word2vec.Word2Vec(new_sentences, min_count=1)
other_vocab = other_model.wv.vocab
model.reset_from(other_model)
self.assertEqual(model.wv.vocab, other_vocab)


#endclass TestWord2VecModel

class TestWMD(unittest.TestCase):
Expand Down

0 comments on commit d00b6c1

Please sign in to comment.