Python Gensim LDA 模型 show_topics 函数

Python Gensim LDA Model show_topics funciton

我正在使用 Gensim 训练 LDA 模型:

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 功能仅 returns 10 个主题。我预计 15 个主题 的定义数量。有谁知道这是故意的还是可以解决的错误?

print(len(lda_sentence_model.show_topics(formatted=False)))

根据.show_topics()方法的gensim文档,其默认num_topics参数值("Number of topics to be returned")为10:

https://radimrehurek.com/gensim/models/ldamulticore.html#gensim.models.ldamulticore.LdaMulticore.show_topics

如果您希望它 return 超过 10,请为该方法的 num_topics 参数提供您首选的非默认值。例如:

len(lda_sentence_model.show_topics(formatted=False, num_topics=15))