Skip to content

Commit

Permalink
Merge pull request #413 from robertcv/fix/topic_modeling
Browse files Browse the repository at this point in the history
[Fix] topics: HdpModel showing no topics
  • Loading branch information
ajdapretnar authored Feb 19, 2019
2 parents d8f7afc + 0075b73 commit 9572916
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions orangecontrib/text/tests/test_topic_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ def test_get_topic_table_by_id(self):
# self.assertAlmostEqual(topic1.W.sum(), 1.)
self.assertFalse(any(topic1.W == np.nan))

def test_get_all_topics(self):
self.model.fit(self.corpus)
topics = self.model.get_all_topics_table()
self.assertEqual(len(topics.domain), self.model.num_topics)

def test_top_words_by_topic(self):
self.model.fit(self.corpus)
words, _ = self.model.get_top_words_by_id(1, num_of_words=10)
Expand Down
5 changes: 3 additions & 2 deletions orangecontrib/text/topics/topics.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,15 @@ def get_top_words_by_id(self, topic_id, num_of_words=10):

def _topics_words(self, num_of_words):
""" Returns list of list of topic words. """
x = self.model.show_topics(-1, num_of_words, formatted=False)
x = self.model.show_topics(self.num_topics, num_of_words, formatted=False)
# `show_topics` method return a list of `(topic_number, topic)` tuples,
# where `topic` is a list of `(word, probability)` tuples.
return [[i[0] for i in topic[1]] for topic in x]

def _topics_weights(self, num_of_words):
""" Returns list of list of topic weights. """
topics = self.model.show_topics(-1, num_of_words, formatted=False)
topics = self.model.show_topics(self.num_topics, num_of_words,
formatted=False)
# `show_topics` method return a list of `(topic_number, topic)` tuples,
# where `topic` is a list of `(word, probability)` tuples.
return [[i[1] for i in t[1]] for t in topics]

0 comments on commit 9572916

Please sign in to comment.