Skip to content

Commit 8f02c6b

Browse files
committed
Fix Bug: check parameter topic for top_terms_of_topic and ADD: print Doc-Topic Matrix and Topic-Term Matrix in example.py
1 parent c249790 commit 8f02c6b

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ llda_model_new.load_model_from_dir(save_model_dir, load_derivative_properties=Fa
115115
print "llda_model_new", llda_model_new
116116
print "llda_model", llda_model
117117
print "Top-5 terms of topic 'negative': ", llda_model.top_terms_of_topic("negative", 5, False)
118+
print "Doc-Topic Matrix: \n", llda_model.theta
119+
print "Topic-Term Matrix: \n", llda_model.beta
118120
```
119121

120122

example/example.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,5 @@
7272
print "llda_model_new", llda_model_new
7373
print "llda_model", llda_model
7474
print "Top-5 terms of topic 'negative': ", llda_model.top_terms_of_topic("negative", 5, False)
75+
print "Doc-Topic Matrix: \n", llda_model.theta
76+
print "Topic-Term Matrix: \n", llda_model.beta

model/labeled_lda.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,8 @@ def top_terms_of_topic(self, topic, k, with_probabilities=True):
938938
:param k: int, the number of terms
939939
:return: the top-k terms of topic
940940
"""
941+
if topic not in self.topic_vocabulary:
942+
raise Exception("Cannot find topic \"%s\"" % topic)
941943
beta = self.beta_k(self.topic_vocabulary[topic])
942944
terms = sorted(list(zip(self.terms, beta)), key=lambda x: x[1], reverse=True)
943945
if with_probabilities:

0 commit comments

Comments
 (0)