Skip to content

Commit

Permalink
Update the warning text when building vocab on a trained w2v model (#…
Browse files Browse the repository at this point in the history
…1190)

Updated the error message for the case when build_vocab() is triggered more than once without update parameter.

model = gensim.models.Word2Vec(sentences,min_count=3,trim_rule=my_rule)
model.build_vocab(sentences) #throws error
model.build_vocab(sentences, update = True) #works as expected
  • Loading branch information
prakhar2b authored and tmylk committed Mar 7, 2017
1 parent 000c02a commit c2f3716
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion gensim/models/word2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ def finalize_vocab(self, update=False):
def sort_vocab(self):
"""Sort the vocabulary so the most frequent words have the lowest indexes."""
if len(self.wv.syn0):
raise RuntimeError("must sort before initializing vectors/weights")
raise RuntimeError("cannot sort vocabulary after model weights already initialized.")
self.wv.index2word.sort(key=lambda word: self.wv.vocab[word].count, reverse=True)
for i, word in enumerate(self.wv.index2word):
self.wv.vocab[word].index = i
Expand Down

0 comments on commit c2f3716

Please sign in to comment.