Python Gensim LDA模型show_topics函数 [英] Python Gensim LDA Model show_topics funciton
问题描述
我正在使用Gensim训练LDA模型:
I am training a LDA Model using Gensim:
dictionary = corpora.Dictionary(section_2_sentence_df['Tokenized_Sentence'].tolist())
dictionary.filter_extremes(no_below=20, no_above=0.7)
corpus = [dictionary.doc2bow(text) for text in (section_2_sentence_df['Tokenized_Sentence'].tolist())]
num_topics = 15
passes = 200
chunksize = 100
lda_sentence_model = gensim.models.ldamulticore.LdaMulticore(corpus, num_topics=num_topics,
id2word=dictionary,
passes=passes,
chunksize=chunksize,
random_state=100,
workers = 3)
培训后,我需要进行进一步分析的主题.不幸的是,show_topics函数仅返回 10个主题.我希望定义的数量为 15个主题.有人知道这是故意的还是可以解决的错误?
After training i need the topics for further analysis. Unfortunately the show_topics function only returns 10 topics. I expected the defined number of 15 topics. Does anyone know if that is on purpose or an error that can be solved?
print(len(lda_sentence_model.show_topics(formatted=False)))
推荐答案
根据gensim文档中的 .show_topics()
方法,其默认 num_topics
参数值(要返回的主题数")为10:
According to the gensim documentation for the .show_topics()
method, its default num_topics
parameter value ("Number of topics to be returned") is 10:
如果希望它返回10以上,请为该方法的 num_topics
参数提供首选的非默认值.例如:
If you want it to return more than 10, supply your preferred non-default value for that method's num_topics
parameter. For example:
len(lda_sentence_model.show_topics(formatted=False, num_topics=15))
这篇关于Python Gensim LDA模型show_topics函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!