Repository: piskvorky/gensim

Issue:
DeprecationWarning: numpy sum :: np.sum(generator) is deprecated - LDA
**Warning:**
score += np.sum(cnt * logsumexp(Elogthetad + Elogbeta[:, int(id)]) for id, cnt in doc)
/usr/local/lib/python2.7/dist-packages/gensim/models/ldamodel.py:1077: DeprecationWarning: Calling np.sum(generator) is deprecated, and in the future will give a different result. Use np.sum(np.from_iter(generator)) or the python sum builtin instead.
  score += np.sum(cnt * logsumexp(Elogthetad + Elogbeta[:, int(id)]) for id, cnt in doc)

#### Versions
import platform; print(platform.platform())
Linux-4.16.0-x86_64-with-Ubuntu-18.04-bionic
import sys; print("Python", sys.version)
('Python', '2.7.15rc1 (default, Nov 12 2018, 14:31:15) \n[GCC 7.3.0]')
import numpy; print("NumPy", numpy.__version__)
('NumPy', '1.15.4')
import scipy; print("SciPy", scipy.__version__)
('SciPy', '1.1.0')
import gensim; print("gensim", gensim.__version__)
('gensim', '3.6.0')
from gensim.models import word2vec;print("FAST_VERSION", word2vec.FAST_VERSION)
('FAST_VERSION', 1)





Discussion:
I am facing the similar problem for LDA using gensim, Hope to receive some help for this. 

**Code:** 
lda_model = gensim.models.ldamodel.LdaModel(corpus=doc_term_matrix,
                                           id2word=id2word,
                                           num_topics=20, 
                                           random_state=100,
                                           update_every=1,
                                           chunksize=100,
                                           passes=10,
                                           alpha='auto',
                                           per_word_topics=True)

**Warning**

C:\Users\shrav\Anaconda3\lib\site-packages\gensim\models\ldamodel.py:826: DeprecationWarning: Calling np.sum(generator) is deprecated, and in the future will give a different result. Use np.sum(np.from_iter(generator)) or the python sum builtin instead.
  score += np.sum(cnt * logsumexp(Elogthetad + Elogbeta[:, int(id)]) for id, cnt in doc)
Traceback (most recent call last):

  File "<ipython-input-186-10881c23a011>", line 9, in <module>
    per_word_topics=True)

  File "C:\Users\shrav\Anaconda3\lib\site-packages\gensim\models\ldamodel.py", line 371, in __init__
    self.update(corpus, chunks_as_numpy=use_numpy)

  File "C:\Users\shrav\Anaconda3\lib\site-packages\gensim\models\ldamodel.py", line 734, in update
    self.do_mstep(rho(), other, pass_ > 0)

  File "C:\Users\shrav\Anaconda3\lib\site-packages\gensim\models\ldamodel.py", line 781, in do_mstep
    self.print_topics(5)

  File "C:\Users\shrav\Anaconda3\lib\site-packages\gensim\models\basemodel.py", line 36, in print_topics
    return self.show_topics(num_topics=num_topics, num_words=num_words, log=True)

  File "C:\Users\shrav\Anaconda3\lib\site-packages\gensim\models\ldamodel.py", line 883, in show_topics
    topic_ = topic_ / topic_.sum()  # normalize to probability distribution

  File "C:\Users\shrav\Anaconda3\lib\site-packages\numpy\core\_methods.py", line 36, in _sum
    return umr_sum(a, axis, dtype, out, keepdims, initial)

TypeError: reduce() takes at most 5 arguments (6 given)
@raviolli thanks for the report!

@shravik looking into your stack trace, something goes wrong with your numpy, try to re-install it together with gensim.
Is there any solution available? I recently installed the all the packages. Also the result varies with every run. The coherence value of topic gets changed with every run.
> Also the result varies with every run. The coherence value of topic gets changed with every run.

This can happen if you don't pin seed, i.e. expected situation.
The warning can be easily fixed in the way that mentioned directly in warning. Feel free to contribute!
I would like to contribute :smiley: .
@rsdel2007 you are welcome :)

Resolving patch:
diff --git a/gensim/models/ldamodel.py b/gensim/models/ldamodel.py
--- a/gensim/models/ldamodel.py
+++ b/gensim/models/ldamodel.py
@@ -1094,7 +1094,7 @@ def bound(self, corpus, gamma=None, subsample_ratio=1.0):
             assert Elogthetad.dtype == self.dtype
 
             # E[log p(doc | theta, beta)]
-            score += np.sum(cnt * logsumexp(Elogthetad + Elogbeta[:, int(id)]) for id, cnt in doc)
+            score += sum(cnt * logsumexp(Elogthetad + Elogbeta[:, int(id)]) for id, cnt in doc)
 
             # E[log p(theta | alpha) - log q(theta | gamma)]; assumes alpha is a vector
             score += np.sum((self.alpha - gammad) * Elogthetad)


Test patch: