From a1b29f0042f3e827010b5b8dbe7759b503483a7a Mon Sep 17 00:00:00 2001 From: HemaVakade Date: Fri, 10 Mar 2017 18:46:49 -0800 Subject: [PATCH 1/3] added err msg --- gensim/models/word2vec.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gensim/models/word2vec.py b/gensim/models/word2vec.py index 8c371ea8bd..8a37c68b84 100644 --- a/gensim/models/word2vec.py +++ b/gensim/models/word2vec.py @@ -1090,6 +1090,13 @@ def update_weights(self): for i in xrange(len(self.wv.syn0), len(self.wv.vocab)): # construct deterministic seed from word AND seed argument newsyn0[i-len(self.wv.syn0)] = self.seeded_vector(self.wv.index2word[i] + str(self.seed)) + + # Raise an error in an online update is run before initial training on a corpus + if not len(self.wv.syn0): + raise RuntimeError("You can do an online update of vocabulary on a pre-trained model. " \ + "Or first build the vocabulary of your model with a corpus and train it " \ + "before doing an online update.") + self.wv.syn0 = vstack([self.wv.syn0, newsyn0]) if self.hs: From 956dbbd1dc4ca0e9b798dafc48579f289f69808f Mon Sep 17 00:00:00 2001 From: HemaVakade Date: Fri, 10 Mar 2017 18:48:35 -0800 Subject: [PATCH 2/3] added err msg --- gensim/models/word2vec.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gensim/models/word2vec.py b/gensim/models/word2vec.py index 8a37c68b84..c2854cd58d 100644 --- a/gensim/models/word2vec.py +++ b/gensim/models/word2vec.py @@ -1091,7 +1091,7 @@ def update_weights(self): # construct deterministic seed from word AND seed argument newsyn0[i-len(self.wv.syn0)] = self.seeded_vector(self.wv.index2word[i] + str(self.seed)) - # Raise an error in an online update is run before initial training on a corpus + # Raise an error if an online update is run before initial training on a corpus if not len(self.wv.syn0): raise RuntimeError("You can do an online update of vocabulary on a pre-trained model. " \ "Or first build the vocabulary of your model with a corpus and train it " \ From e710159ce39866ce64620c742d3c95834e2beea1 Mon Sep 17 00:00:00 2001 From: HemaVakade Date: Sun, 12 Mar 2017 17:59:26 -0700 Subject: [PATCH 3/3] Changed the error message --- gensim/models/word2vec.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gensim/models/word2vec.py b/gensim/models/word2vec.py index c2854cd58d..6cf29f7bc3 100644 --- a/gensim/models/word2vec.py +++ b/gensim/models/word2vec.py @@ -1093,8 +1093,8 @@ def update_weights(self): # Raise an error if an online update is run before initial training on a corpus if not len(self.wv.syn0): - raise RuntimeError("You can do an online update of vocabulary on a pre-trained model. " \ - "Or first build the vocabulary of your model with a corpus and train it " \ + raise RuntimeError("You cannot do an online vocabulary-update of a model which has no prior vocabulary. " \ + "First build the vocabulary of your model with a corpus " \ "before doing an online update.") self.wv.syn0 = vstack([self.wv.syn0, newsyn0])