5
votes

Situation:

I have a numpy term-document matrix example: [[0,1,0,0....],....[......0,0,0,0]].

I have plugged in the above matrix to the ldamodel method of the gensim. And it is working fine with the lad method lda = LdaModel(corpus, num_topics=10). corpus is my term-document matrix mentioned above. I needed two intermediate matrices( topic-word array & document-topic array) for research purpose.

1) per document-topic probability matrix (p_d_t)

2) per topic-word probability matrix (p_w_t)

Question:

How to get those array from the gensim LdaModel() function.? Kindly help me with getting those matrices.

1
If you use lda.print_topics(k) it will print the per word propability, and with vec_lda = lda[document] it wll show you the per topic probability. - christosh

1 Answers

10
votes

1.Per-document topic probability matrix:

Apply a transformation to your corpus.

docTopicProbMat = lda[corpus]
  1. Per-topic word probability matrix:

K = lda.num_topics topicWordProbMat = lda.print_topics(K)