gpt4 book ai didi

python - 在gensim LdaModel中提取主题词概率矩阵

转载 作者:太空宇宙 更新时间:2023-11-03 14:56:17 25 4
gpt4 key购买 nike

我有 LDA 模型和文档主题概率。

# build the model on the corpus
ldam = LdaModel(corpus=corpus, num_topics=20, id2word=dictionary)
# get the document-topic probabilities
theta, _ = ldam.inference(corpus)

我还需要所有主题的单词分布,即主题-单词概率矩阵。有没有办法提取这些信息?

谢谢!

最佳答案

主题术语矩阵 (lambda) 可通过以下方式访问:

topics_terms = ldam.state.get_lambda()

如果你想要一个概率分布,只需对其进行归一化:

topics_terms_proba = np.apply_along_axis(lambda x: x/x.sum(),1,topics_terms)

关于python - 在gensim LdaModel中提取主题词概率矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42289858/

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