How to get the topic probability for each document for topic modeling using LDA

♀尐吖头ヾ 提交于 2020-12-07 07:33:17

问题


I use scikit-learn LDA to generate LDA model and after that I can get the topic-terms. I am wondering how can I get the probability of each topic for each document?


回答1:


Use the transform method of the LatentDirichletAllocation class after fitting the model. It will return the document topic distribution.

If you work with the example given in the documentation for scikit-learn's Latent Dirichlet Allocation, the document topic distribution can be accessed by appending the following line to the code:

doc_topic_dist = lda.transform(tf)

Here, lda is the trained LDA model and tf is the document word matrix.



来源:https://stackoverflow.com/questions/49740675/how-to-get-the-topic-probability-for-each-document-for-topic-modeling-using-lda

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!