From 11ad64dcd76e555698b9c636d5596565ac244800 Mon Sep 17 00:00:00 2001 From: Chinmaya Pancholi Date: Sun, 12 Mar 2017 10:05:29 +0530 Subject: [PATCH 1/4] checks if model changed before setting model_trimmed_post_training --- gensim/models/word2vec.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gensim/models/word2vec.py b/gensim/models/word2vec.py index 182e1c4dc1..789a69d316 100644 --- a/gensim/models/word2vec.py +++ b/gensim/models/word2vec.py @@ -1251,7 +1251,8 @@ def _minimize_model(self, save_syn1 = False, save_syn1neg = False, save_syn0_loc del self.syn1neg if hasattr(self, 'syn0_lockf') and not save_syn0_lockf: del self.syn0_lockf - self.model_trimmed_post_training = True + if not save_syn1 or not save_syn1neg or not save_syn0_lockf: + self.model_trimmed_post_training = True def delete_temporary_training_data(self, replace_word_vectors_with_normalized=False): """ From 2a3c1923f0007e447845148764950a7b5f0a4fbe Mon Sep 17 00:00:00 2001 From: Chinmaya Pancholi Date: Sun, 12 Mar 2017 10:06:46 +0530 Subject: [PATCH 2/4] shows deprecation warning for _minimize_model --- gensim/models/word2vec.py | 1 + 1 file changed, 1 insertion(+) diff --git a/gensim/models/word2vec.py b/gensim/models/word2vec.py index 789a69d316..a9826d2632 100644 --- a/gensim/models/word2vec.py +++ b/gensim/models/word2vec.py @@ -1253,6 +1253,7 @@ def _minimize_model(self, save_syn1 = False, save_syn1neg = False, save_syn0_loc del self.syn0_lockf if not save_syn1 or not save_syn1neg or not save_syn0_lockf: self.model_trimmed_post_training = True + logger.warning("This method would be deprecated in the future. Use KeyedVectors to retain the previously trained word vectors instead.") def delete_temporary_training_data(self, replace_word_vectors_with_normalized=False): """ From 4091d3ee878bd80999b4f4d3447b4e45f0623075 Mon Sep 17 00:00:00 2001 From: Chinmaya Pancholi Date: Sun, 12 Mar 2017 10:41:46 +0530 Subject: [PATCH 3/4] using warnings.warn to show deprecation message --- gensim/models/word2vec.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gensim/models/word2vec.py b/gensim/models/word2vec.py index a9826d2632..0e6f7ee193 100644 --- a/gensim/models/word2vec.py +++ b/gensim/models/word2vec.py @@ -1253,7 +1253,8 @@ def _minimize_model(self, save_syn1 = False, save_syn1neg = False, save_syn0_loc del self.syn0_lockf if not save_syn1 or not save_syn1neg or not save_syn0_lockf: self.model_trimmed_post_training = True - logger.warning("This method would be deprecated in the future. Use KeyedVectors to retain the previously trained word vectors instead.") + import warnings + warnings.warn("This method would be deprecated in the future. Use KeyedVectors to retain the previously trained word vectors instead.") def delete_temporary_training_data(self, replace_word_vectors_with_normalized=False): """ From 0be6395955f8558a262a9b190aec9f74d9e7a47b Mon Sep 17 00:00:00 2001 From: Chinmaya Pancholi Date: Sun, 12 Mar 2017 19:27:03 +0530 Subject: [PATCH 4/4] updated warning message and logic to check parameters --- gensim/models/word2vec.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gensim/models/word2vec.py b/gensim/models/word2vec.py index 0e6f7ee193..df90fb3fe2 100644 --- a/gensim/models/word2vec.py +++ b/gensim/models/word2vec.py @@ -106,6 +106,7 @@ from collections import defaultdict import threading import itertools +import warnings from gensim.utils import keep_vocab_item, call_on_class_only from gensim.utils import keep_vocab_item @@ -1245,16 +1246,16 @@ def __str__(self): return "%s(vocab=%s, size=%s, alpha=%s)" % (self.__class__.__name__, len(self.wv.index2word), self.vector_size, self.alpha) def _minimize_model(self, save_syn1 = False, save_syn1neg = False, save_syn0_lockf = False): + warnings.warn("This method would be deprecated in the future. Keep just_word_vectors = model.wv to retain just the KeyedVectors instance for read-only querying of word vectors.") + if save_syn1 and save_syn1neg and save_syn0_lockf: + return if hasattr(self, 'syn1') and not save_syn1: del self.syn1 if hasattr(self, 'syn1neg') and not save_syn1neg: del self.syn1neg if hasattr(self, 'syn0_lockf') and not save_syn0_lockf: del self.syn0_lockf - if not save_syn1 or not save_syn1neg or not save_syn0_lockf: - self.model_trimmed_post_training = True - import warnings - warnings.warn("This method would be deprecated in the future. Use KeyedVectors to retain the previously trained word vectors instead.") + self.model_trimmed_post_training = True def delete_temporary_training_data(self, replace_word_vectors_with_normalized=False): """