0

我正在尝试通过 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_topics=num_topics, 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"

...

wheredescriptions_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

谢谢!

4

0 回答 0