【问题标题】:Python Gensim LDA Model show_topics funcitonPython Gensim LDAModel show_topics 函数
【发布时间】:2020-02-27 06:21:20
【问题描述】:

我正在使用 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 函数只返回 10 个主题。我预计 15 个主题的定义数量。有谁知道这是故意的还是可以解决的错误?

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

【问题讨论】:

    标签: python gensim lda


    【解决方案1】:

    根据.show_topics() 方法的gensim 文档,它的默认num_topics 参数值(“要返回的主题数”)为10:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-17
      • 1970-01-01
      • 1970-01-01
      • 2018-12-11
      • 2017-07-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多