【问题标题】:Extract topic word probability matrix in gensim LdaModel在gensim LdaModel中提取主题词概率矩阵
【发布时间】:2017-07-06 12:04:44
【问题描述】:

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

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

谢谢!

【问题讨论】:

    标签: python gensim lda topic-modeling


    【解决方案1】:

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

    topics_terms = ldam.state.get_lambda()
    

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

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

    【讨论】:

    • 当我使用 ldam.state.get_lambda() 时,我得到一个 numpy 矩阵,但没有列名。如何识别单词?
    • 要知道哪个单词对应于给定索引,请使用ldam.id2word。比如ldam.id2word[0]就是矩阵第一列对应的单词。
    猜你喜欢
    • 2017-08-08
    • 2018-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多