简体   繁体   English

如何运行时警告:LDA中的exp中遇到溢出

[英]How to RuntimeWarning: overflow encountered in exp in LDA

ldamodel, fequency_list,vect = create_ldamodel(documents = chatTurn.case_content, num_topics = 6)

I am running the above LDA code and it appears the statement as below. 我正在运行上面的LDA代码,它显示如下语句。

/Users/user/anaconda3/lib/python3.6/site-packages/gensim/models/ldamodel.py:497: RuntimeWarning: overflow encountered in exp expElogthetad = np.exp(Elogthetad) /Users/user/anaconda3/lib/python3.6/site-packages/gensim/models/ldamodel.py:497:RuntimeWarning:exp遇到溢出expElogthetad = np.exp(Elogthetad)

The LDA model function that I used is as follow: 我使用的LDA模型函数如下:

def create_ldamodel(documents, num_topics):
    vect = CountVectorizer(stop_words = 'english')
    X = vect.fit_transform(documents.apply(lambda x:x.lower()))
    corpus = gensim.matutils.Sparse2Corpus(X, documents_columns=False)
    id_map = dict((v,k) for k, v in vect.vocabulary_.items())
    ldamodel = gensim.models.ldamodel.LdaModel(corpus,      num_topics=num_topics,
                                          id2word = id_map)

fequency_list = dict()
for i in list(ldamodel[corpus]):
    for j_k, j_v in i:
        if j_k in fequency_list:
            fequency_list[j_k] += j_v
        else:
            fequency_list[j_k] = 0

return (ldamodel, fequency_list,vect)

May I know is there any solution to it? 我可以知道有什么解决办法吗?

Because your numpy is mismatch the gensim, maybe update numpy in your current environment or specify the numpy version to match your gensim version. 由于您的numpy与gensim不匹配,请在当前环境中更新numpy或指定numpy版本以与您的gensim版本匹配。 Hope this is helpful to you. 希望这对您有帮助。 ^^ ^^

My runtime erros was the following: RuntimeWarning: overflow encountered in exp expElogthetad = np.exp(Elogthetad) After trying so many times and things, I came across with a reading recommending uninstalling numpy and reinstalling it back again: 我的运行时错误如下:RuntimeWarning:exp中遇到溢出expElogthetad = np.exp(Elogthetad)在尝试了很多次之后,我发现建议卸载numpy并再次重新安装它:

python3.6 pip uninstall numpy and to install it back: python3.6 -m pip install -U numpy python3.6 pip卸载numpy并重新安装:python3.6 -m pip install -U numpy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM