gpt4 book ai didi

python - 如何在gensim中打印出LDA主题中单词的完整分布?

转载 作者:太空狗 更新时间:2023-10-29 21:29:19 24 4
gpt4 key购买 nike

以下代码中的 lda.show_topics 模块只打印每个主题前 10 个词的分布,我如何打印出语料库中所有词的完整分布?

from gensim import corpora, models

documents = ["Human machine interface for lab abc computer applications",
"A survey of user opinion of computer system response time",
"The EPS user interface management system",
"System and human system engineering testing of EPS",
"Relation of user perceived response time to error measurement",
"The generation of random binary unordered trees",
"The intersection graph of paths in trees",
"Graph minors IV Widths of trees and well quasi ordering",
"Graph minors A survey"]

stoplist = set('for a of the and to in'.split())
texts = [[word for word in document.lower().split() if word not in stoplist]
for document in documents]

dictionary = corpora.Dictionary(texts)
corpus = [dictionary.doc2bow(text) for text in texts]

lda = models.ldamodel.LdaModel(corpus_tfidf, id2word=dictionary, num_topics=2)

for i in lda.show_topics():
print i

最佳答案

show_topics() 中有一个变量调用 topn,您可以在其中指定每个主题的单词分布中所需的前 N ​​个单词的数量。见http://radimrehurek.com/gensim/models/ldamodel.html

所以不是默认的 lda.show_topics()。您可以使用 len(dictionary) 获取每个主题的完整单词分布:

for i in lda.show_topics(topn=len(dictionary)):
print i

关于python - 如何在gensim中打印出LDA主题中单词的完整分布?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17662916/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com