python - Gensim LDA 连贯性得分 Nan
问题描述
我创建了一个 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。我在这里做错了什么?
解决方案
解决了!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
希望这可以帮助其他人犯同样的错误。谢谢!
推荐阅读
- javascript - 如何将键值对数组转换为以第一个数组的值作为键的对象?
- odoo - 如何在 Odoo 11 Enterprise 中为选定帐户设置“管理数据库”按钮?
- loops - 超出内存限制 - Python
- flatpickr - Flatpickr 时间格式操作
- regex - Bash if 语句检查 1 个字母和 2 个数字
- cryptography - 使用椭圆曲线密码术使用公钥加密并使用私钥解密
- python - ModuleNotFoundError:没有名为“requests_html”的模块
- dependency-management - 如何在 ivy 中调整版本分辨率
- sql - 如何从包含两个文本字符串的一列中检索一个文本字符串?
- string - Bash 字符串重定向到标准输入:删除换行符