pyLDAvis: 可视化错误 (IndexError: index 3537 is out of bounds for axis 1 with size 3537)

问题描述

我正在尝试通过 pyLDAvis 可视化一些数据。 我的代码看起来像这样

dictionary_LDA = corpora.Dictionary(descriptions_lem_stop_sense_grams)
dictionary_LDA.filter_extremes(no_below=3)
corpus = [dictionary_LDA.doc2bow(list_of_tokens) for list_of_tokens in descriptions_lem_stop_sense_grams]

num_topics = 20
lda_model = models.Ldamodel(corpus,num_topics=num_topics,\
                                  id2word=dictionary_LDA,\
                                  passes=4,alpha=[0.01]*num_topics,\
                                  eta=[0.01]*len(dictionary_LDA.keys()))

for i,topic in lda_model.show_topics(formatted=True,num_words=10):
    print(str(i)+": "+ topic)
    print()
0: 0.012*"monster" + 0.009*"set" + 0.009*"world" + 0.009*"point" + 0.008*"end" + 0.008*"investigator" + 0.008*"add" + 0.007*"board" + 0.007*"kNow" + 0.007*"score"

1: 0.022*"game" + 0.013*"card" + 0.010*"take" + 0.010*"include" + 0.009*"two" + 0.009*"try" + 0.008*"point" + 0.007*"end" + 0.007*"play" + 0.007*"army"

2: 0.016*"game" + 0.015*"take" + 0.013*"word" + 0.010*"action" + 0.008*"give" + 0.008*"create" + 0.008*"play" + 0.007*"start" + 0.007*"well" + 0.007*"must"

...

其中 descriptions_lem_stop_sense_grams 是单词列表的列表。

dic=corpora.Dictionary(descriptions_lem_stop_sense_grams)

vis = pyLDAvis.gensim.prepare(lda_model,corpus,dic)

pyLDAvis.enable_notebook()
pyLDAvis.display(vis)

最后的代码结果是错误

IndexError: index 3537 is out of bounds for axis 1 with size 3537

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)