gpt4 book ai didi

Python Gensim : how to calculate document similarity using the LDA model?

转载 作者:IT老高 更新时间:2023-10-28 22:24:27 25 4
gpt4 key购买 nike

我有一个经过训练的 LDA 模型,我想从我训练模型的语料库中计算两个文档之间的相似度得分。在学习了所有 Gensim 教程和功能之后,我仍然无法理解它。有人可以给我一个提示吗?谢谢!

最佳答案

取决于您要使用的相似度指标。

Cosine similarity普遍有用 & built-in :

sim = gensim.matutils.cossim(vec_lda1, vec_lda2)

Hellinger distance对概率分布(例如 LDA 主题)之间的相似性很有用:

import numpy as np
dense1 = gensim.matutils.sparse2full(lda_vec1, lda.num_topics)
dense2 = gensim.matutils.sparse2full(lda_vec2, lda.num_topics)
sim = np.sqrt(0.5 * ((np.sqrt(dense1) - np.sqrt(dense2))**2).sum())

关于Python Gensim : how to calculate document similarity using the LDA model?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22433884/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com