Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

retrieve topic-word array & document-topic array from lda gensim

Tags:

gensim

lda

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.

like image 211
AnandViswanathan89 Avatar asked Sep 12 '14 07:09

AnandViswanathan89


1 Answers

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)

like image 66
sinwav Avatar answered Sep 20 '22 16:09

sinwav