LDA主题挖掘时,通常采用主题困惑度进行最佳主题数的选择。在利用sklearn.decomposition.LatentDirichletAllocation进行主题困惑度计算时,其提供了一个perplexity函数,但是实际计算结果是随着主题数的增加,函数值也在无规律的增加。通过查阅相关文章,发现在GitHub网站上,对LatentDirichletAllocation源码的issues中,提出这是该代码的一个bug,因此,如果想计算主题困惑度,可以参考https://blog.youkuaiyun.com/xxidaojia/article/details/102702492?utm_source=distribute.pc_relevant.none-task这篇博文,里面是采用gensim进行的lda分析。当然,两种分析工具出来的效果上还有差异,个人感觉利用LatentDirichletAllocation进行LDA分析主题效果要稍微好一些。因此,参考上述博文,将其引入到LatentDirichletAllocation。
def docperplexity(ldamodel, testset, dictionary, size_dictionary, num_topics):
print('the info of this ldamodel: \n')
print('num of topics: %s'%(num_topics))
prep = 0.0
prob_doc_sum = 0.0
topic_word_list = []
for topic_id in range(num_topics):
topic_word = ldamodel.show_topic(topic_id, size_dictionary)
d

本文探讨了使用LDA进行主题挖掘时的主题困惑度计算问题,指出sklearn库中perplexity函数存在的bug,并提供了gensim库的替代方案。通过对比,发现LatentDirichletAllocation在主题挖掘方面效果更佳,文中详细介绍了如何结合gensim的困惑度计算方法改进LDA模型评估。
最低0.47元/天 解锁文章
4930

被折叠的 条评论
为什么被折叠?



