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

标签 python gensim lda topic-modeling

我有 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/

相关文章:

python - 更新/刷新动态创建的 WxPython 小部件

python - matplotlib:按没有规范化的字典着色

python - 在远程服务器上使用 ein (emacs ipython notebook)

python - 日期时间:从自身中减去日期得到 3288 天

machine-learning - 小模型来自Google新闻Word2Vec模型

python-3.x - LDA算法的python代码不是很清楚

python - 如何将主题转换为 python 中 LDA 中每个主题中前 20 个单词的列表

python - 如何最佳地处理不在 word2vec 词汇表中的单词

python - 如何使用 Pandas 删除项目或字符串少于一定数量的行?