From 39f93506df5b96ae51aa3df87df4cdbec29ef04c Mon Sep 17 00:00:00 2001 From: alok nayak Date: Wed, 14 Apr 2021 23:25:25 +0530 Subject: [PATCH] fixed bug of connector_words not loading, while loading saved phrases model of version >= 4 --- gensim/models/phrases.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/gensim/models/phrases.py b/gensim/models/phrases.py index 8e20333b8f..e695f6b6bc 100644 --- a/gensim/models/phrases.py +++ b/gensim/models/phrases.py @@ -391,15 +391,16 @@ def load(cls, *args, **kwargs): raise ValueError(f'failed to load {cls.__name__} model, unknown scoring "{model.scoring}"') # common_terms didn't exist pre-3.?, and was renamed to connector in 4.0.0. - if hasattr(model, "common_terms"): - model.connector_words = model.common_terms - del model.common_terms - else: - logger.warning( - 'older version of %s loaded without common_terms attribute, setting connector_words to an empty set', - cls.__name__, - ) - model.connector_words = frozenset() + if not hasattr(model, "connector_words"): + if hasattr(model, "common_terms"): + model.connector_words = model.common_terms + del model.common_terms + else: + logger.warning( + 'older version of %s loaded without common_terms attribute, setting connector_words to an empty set', + cls.__name__, + ) + model.connector_words = frozenset() if not hasattr(model, 'corpus_word_count'): logger.warning('older version of %s loaded without corpus_word_count', cls.__name__)