2017-02-17 299 views
1

我有LDA模型和文檔主題概率。在gensim中提取主題詞概率矩陣LdaModel

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

我還需要爲所有主題分配單詞,即主題詞概率矩陣。有沒有辦法提取這些信息?

謝謝!

回答

3

的主題長期矩陣(拉姆達)是通過訪問:

topics_terms = ldam.state.get_lambda() 

如果你想有一個概率分佈,只是它正常化:

topics_terms_proba = np.apply_along_axis(lambda x: x/x.sum(),1,topics_terms) 
當我使用
+0

'ldam.state.get_lambda() '我得到了一個numpy矩陣,但沒有列名。我如何識別單詞? –

+0

要知道哪個單詞對應給定的索引,請使用'ldam.id2word'。例如'ldam.id2word [0]'是對應於矩陣第一列的單詞。 – arthur