繁体   English   中英

从LDA模型识别相干值时出错

[英]error while Identify the coherence value from LDA model

我尝试运行LDA模型n将LDA对象传递给get_coherence(),它显示错误

x.get_coherence()

*** TypeError:diags()至少接受2个参数(给定2个)

我的代码:-

iModel = models.ldamodel.LdaModel(corpus=corpus, id2word=dictionary, 
num_topics=i, passes=10)

ldalist.append(iModel)

x = CoherenceModel(model=iModel, texts=tokenizedTexts, dictionary=dictionary, 
coherence=coherence)

cohValue = x.get_coherence()

无需原始文本即可计算u_mass相干性。

这些文本只是“非向量化”语料库。

在将语料库用于连贯之前,需要将其转换成这样的单词列表:

texts = [[dictionary[word_id] for word_id, freq in doc] for doc in corpus]

然后建立一致性模型并获得结果:

u_mass = models.CoherenceModel(model=topic_model, corpus=corpus, dictionary=dictionary, coherence='u_mass')
u_mass_coh = u_mass.get_coherence()

c_v = models.CoherenceModel(model=topic_model, texts=texts, corpus=corpus, dictionary=dictionary, coherence='c_v')
c_v_coh = c_v.get_coherence()

c_uci = models.CoherenceModel(model=topic_model, texts=texts, corpus=corpus, dictionary=dictionary, coherence='c_uci')
c_uci_coh = c_uci.get_coherence()

c_npmi = models.CoherenceModel(model=topic_model, texts=texts, corpus=corpus, dictionary=dictionary, coherence='c_npmi')
c_npmi_coh = c_npmi.get_coherence() 

您可以将代码放入main()函数,然后使用:

if __name__ == '__main__':
 main()

这对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM