Elizabeth
Elizabeth

Reputation: 1

I get Runtime Warning: invalid value encountered in double_scalars and divide by zero encountered in double_scalars when using ldaseq

When using the ldaseqmodel in gensim, I got the running time warning:

D:\Anaconda3\lib\site-packages\gensim\models\ldaseqmodel.py:1474: RuntimeWarning: invalid value encountered in double_scalars
converged = np.fabs((lhood_old - lhood) / (lhood_old * total)) D:\Anaconda3\lib\site-packages\gensim\models\ldaseqmodel.py:293: RuntimeWarning: divide by zero encountered in double_scalars
convergence = np.fabs((bound - old_bound) / old_bound)

This is the code:

ldaseq = LdaSeqModel(corpus=corpus_comments, id2word=dictionary_comments,time_slice=time_docs, num_topics=5, chunksize=10,lda_model=model)

The dataset is about 50,000 article in blog.

Please help me ! Thank you so much!

Upvotes: 0

Views: 962

Answers (1)

AdhyaSuman
AdhyaSuman

Reputation: 300

The first warning, that you are getting; i.e.

D:\Anaconda3\lib\site-packages\gensim\models\ldaseqmodel.py:1474: RuntimeWarning: invalid value encountered in double_scalars
converged = np.fabs((lhood_old - lhood) / (lhood_old * total))

is because of empty documents in your corpus. To resolve this first find out the empty documents in your corpus and then remove them from the corpus.

Now, for the second warning please see this answer, I already explain it in detail there, hope it will help you. In short, you are getting the second warning, i.e.

D:\Anaconda3\lib\site-packages\gensim\models\ldaseqmodel.py:293: RuntimeWarning: divide by zero encountered in double_scalars
convergence = np.fabs((bound - old_bound) / old_bound)

because old_bound is initialized as zero in the source code of ldaseqmodel in gensim because of that in this expression (bound - old_bound) / old_bound you are actually dividing the upper part by zero, which leads to the warning. So you simply ignore that warning because after the first iteration the value of old_bound gets updated, so you will not see the warning again.

Upvotes: 1

Related Questions