Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new ValueError in place of assertion error for no model data provided in lsi model #3271

Merged
merged 12 commits into from
Mar 22, 2022
8 changes: 5 additions & 3 deletions gensim/models/lsimodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

from gensim import interfaces, matutils, utils
from gensim.models import basemodel
piskvorky marked this conversation as resolved.
Show resolved Hide resolved

piskvorky marked this conversation as resolved.
Show resolved Hide resolved
import warnings
logger = logging.getLogger(__name__)

# accuracy defaults for the multi-pass stochastic algo
Expand Down Expand Up @@ -489,7 +489,8 @@ def add_documents(self, corpus, chunksize=None, decay=None):
chunksize = self.chunksize
if decay is None:
decay = self.decay

if corpus == []:
mark-todd marked this conversation as resolved.
Show resolved Hide resolved
warnings.warn('LsiModel.add_documents() called but no documents provided, is this intended?')
mark-todd marked this conversation as resolved.
Show resolved Hide resolved
if not scipy.sparse.issparse(corpus):
if not self.onepass:
# we are allowed multiple passes over the input => use a faster, randomized two-pass algo
Expand Down Expand Up @@ -590,7 +591,8 @@ def __getitem__(self, bow, scaled=False, chunksize=512):
Latent representation of corpus in BoW format if `bow` is corpus.

"""
assert self.projection.u is not None, "decomposition not initialized yet"
if self.projection.u is None:
raise ValueError('No training data provided - LSI model not initialized yet')

# if the input vector is in fact a corpus, return a transformed corpus as a result
is_corpus, bow = utils.is_corpus(bow)
Expand Down