Skip to content

Commit

Permalink
Reuse precalculated updated prior in ldamodel.update_dir_prior (#2274)
Browse files Browse the repository at this point in the history
  • Loading branch information
horpto authored and menshikh-iv committed Dec 12, 2018
1 parent 5fbea23 commit 15c02c6
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions gensim/models/ldamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ def update_dir_prior(prior, N, logphat, rho):

dprior = -(gradf - b) / q

if all(rho * dprior + prior > 0):
prior += rho * dprior
updated_prior = rho * dprior + prior
if all(updated_prior > 0):
prior = updated_prior
else:
logger.warning("updated prior not positive")

logger.warning("updated prior is not positive")
return prior


Expand Down Expand Up @@ -665,8 +665,9 @@ def inference(self, chunk, collect_sstats=False):
# Inference code copied from Hoffman's `onlineldavb.py` (esp. the
# Lee&Seung trick which speeds things up by an order of magnitude, compared
# to Blei's original LDA-C code, cool!).
integer_types = six.integer_types + (np.integer,)
for d, doc in enumerate(chunk):
if len(doc) > 0 and not isinstance(doc[0][0], six.integer_types + (np.integer,)):
if len(doc) > 0 and not isinstance(doc[0][0], integer_types):
# make sure the term IDs are ints, otherwise np will get upset
ids = [int(idx) for idx, _ in doc]
else:
Expand Down

0 comments on commit 15c02c6

Please sign in to comment.