我正在尝试使用PyLDAVis在Python中可视化LDA主题,但我似乎无法做到正确。我的模型的词汇大小为150K字,大约有1600万个代币用来训练它。
我是在iPython笔记本之外做的,这是我写的代码。
model_filename = "150k_LdaModel_topics_"+ topics +"_passes_"+passes +".model"
dictionary = gensim.corpora.Dictionary.load('LDADictSpecialRemoved150k.dict')
corpus = gensim.corpora.MmCorpus('LDACorpusSpecialRemoved150k.mm')
ldamodel = gensim.models.ldamodel.LdaModel.load(model_filename)
import pyLDAvis.gensim
vis = pyLDAvis.gensim.prepare(ldamodel, corpus, dictionary)
pyLDAvis.save_html(vis, "topic_viz_"+topics+"_passes_"+passes+".html")
在具有> 30GB RAM的高速服务器上运行代码2-3小时后,我收到以下错误。有人能在我出错的地方帮忙吗?
Traceback (most recent call last):
File "create_vis.py", line 36, in <module>
vis = pyLDAvis.gensim.prepare(ldamodel, corpus, dictionary)
File "/local/lib/python2.7/site-packages/pyLDAvis/gensim.py", line 110, in prepare
return vis_prepare(**opts)
File "/local/lib/python2.7/site-packages/pyLDAvis/_prepare.py", line 398, in prepare
token_table = _token_table(topic_info, term_topic_freq, vocab, term_frequency)
File "/local/lib/python2.7/site-packages/pyLDAvis/_prepare.py", line 267, in _token_table
term_ix.sort()
File "/local/lib/python2.7/site-packages/pandas/indexes/base.py", line 1703, in sort
raise TypeError("cannot sort an Index object in-place, use "
TypeError: cannot sort an Index object in-place, use sort_values instead
答案 0 :(得分:0)
LDAVis代码存在问题,在报告问题后,问题已得到解决。