如何更改LDA中的默认number_words

问题描述 投票:0回答:1

我能够使用gensim从LDA模型中提取主题。当我打印主题时,它默认显示10个单词的主题。我想在一个topic.i中显示15个单词。我试图改变它但我仍然每个主题得到10个单词。我可以更改此默认行为吗?

这是代码:

for n, topic in model.show_topics(num_topics=-1, num_words=15,formatted=False):
                topic = [word for word, _ in topic]
                cm = CoherenceModel(topics=[topic], texts=documents, dictionary=dictionary, window_size=10)
                coherence_values[n] = cm.get_coherence()
            top_topics = sorted(coherence_values.items(), key=operator.itemgetter(1), reverse=True)
            result.append((model, top_topics))

并用于打印主题:

pprint([lm.show_topic(topicid) for topicid, c_v in top_topics[:8]])
python python-3.x nlp lda topic-modeling
1个回答
0
投票

我认为问题出在show_topic函数中。您正在为主题找到更多单词但不显示它们,因为show_topic有一个可选变量,topn用于检索最重要的单词。默认值为10,因此请将print语句中的代码更改为

pprint([lm.show_topic(topicid, topn=15) for topicid, c_v in top_topics[:8]])

它应该全部显示出来。

© www.soinside.com 2019 - 2024. All rights reserved.