Clock Slave
Clock Slave

Reputation: 7967

Extract topic word probability matrix in gensim LdaModel

I have the LDA model and the document-topic probabilities.

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

I also need the distribution of words for all the topics i.e. a topic-word probability matrix. Is there a way to extract this information?

Thanks!

Upvotes: 4

Views: 2672

Answers (1)

arthur
arthur

Reputation: 2399

The topics-term matrix (lambda) is accessible via :

topics_terms = ldam.state.get_lambda()

If you want a probability distribution just normalize it :

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

Upvotes: 6

Related Questions