bab2min / tomotopy

Python package of Tomoto, the Topic Modeling Tool
https://bab2min.github.io/tomotopy
MIT License
553 stars 62 forks source link

Question about topic assignments with LDA models #86

Open alonjacovi opened 3 years ago

alonjacovi commented 3 years ago

I'd like to infer topic assignments from a trained LDA model on a document, rather than the probability distribution over all topics. How can I accomplish this?

Thanks

bab2min commented 3 years ago

@alonjacovi Sorry for the late reply. Oh, I accidentally forgot to answer it. You can get topic assignment of each word in a trained or an inferred document. (https://bab2min.github.io/tomotopy/v0.11.0/en/#tomotopy.Document.topics)

Get the document first, and access topics property to get topic assignment.

mdl = LDAModel(...) # create the model
# add_docs ...
mdl.train(...) # train the model
doc = mdl.docs[0] # get the document
print(doc.topics) # topic assignment for each word in doc