【问题标题】:Gensim LDA Coherence Score NanGensim LDA 连贯性得分 Nan
【发布时间】:2020-02-16 08:03:17
【问题描述】:

我创建了一个 Gensim LDA 模型,如本教程所示:https://www.machinelearningplus.com/nlp/topic-modeling-gensim-python/

lda_model = gensim.models.LdaMulticore(data_df['bow_corpus'], num_topics=10, id2word=dictionary, random_state=100, chunksize=100, passes=10, per_word_topics=True)

它会生成 10 个主题,其 log_perplexity 为:

lda_model.log_perplexity(data_df['bow_corpus']) = -5.325966117835991

但是当我在其上运行一致性模型来计算一致性分数时,如下所示:

coherence_model_lda = CoherenceModel(model=lda_model, texts=data_df['bow_corpus'].tolist(), dictionary=dictionary, coherence='c_v')
with np.errstate(invalid='ignore'):
    lda_score = coherence_model_lda.get_coherence()

我的 LDA 分数是 nan。我在这里做错了什么?

【问题讨论】:

    标签: python machine-learning gensim lda topic-modeling


    【解决方案1】:

    解决了! Coherence 模型需要原始文本,而不是提供给 LDA_Model 的训练语料库 - 所以当我运行这个时:

    coherence_model_lda = CoherenceModel(model=lda_model, texts=data_df['corpus'].tolist(), dictionary=dictionary, coherence='c_v')
    with np.errstate(invalid='ignore'):
        lda_score = coherence_model_lda.get_coherence()
    

    我的连贯性得分为:0.462

    希望这可以帮助其他人犯同样的错误。谢谢!

    【讨论】:

    • 遇到了同样的问题!感谢分享!
    【解决方案2】:

    文档 (https://radimrehurek.com/gensim/models/coherencemodel.html) 说要提供“标记化文本”(str 列表列表) - 这些应该是您的文本拆分为您提供给 CoherenceModel 的字典中的单个单词。如果您提供未标记化的全文,则查找字典中没有词条的条目。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-19
      • 2019-03-31
      • 2021-10-05
      • 2023-03-13
      • 2016-06-17
      • 1970-01-01
      • 2013-06-23
      相关资源
      最近更新 更多