Commit 1fe9a228 authored by Kathryn Elliott's avatar Kathryn Elliott

Fix error that was causing the topics to be out of sync

I've also added the call to show_topics() so the printed topics can be
double checked against it.
parent 5709bb1b
......@@ -46,4 +46,4 @@ topic_model.export_document_id_map()
......@@ -347,25 +347,25 @@ class TopicModel:
def print_topics(self, topn=20, compact=True):
def print_topics(self, topn=20, extended=False):
""" Print the top terms for each topic.
for topic_id, max_topic in self._topics_generator():
self.print_topic(topic_id, topn=topn, compact=compact)
self.print_topic(topic_id, topn=topn, extended=extended)
def print_topic(self, topic_id, topn=20, compact=True):
def print_topic(self, topic_id, topn=20, extended=False):
""" Print the top terms for all topics.
if compact == True:
for topic in self._models[topic_id].show_topics(topn):
for topic in self._models[topic_id].show_topics(topn):
if extended == True:
for n in range(topic_id):"Terms per topic {0} (of {1})".format(n + 1, topic_id))"Terms per topic {0} (of {1})".format(n, topic_id - 1))"{:20} {}".format(u'term', u'frequency'))
for term, frequency in self._models[topic_id].show_topic(n - 1, topn):
for term, frequency in self._models[topic_id].show_topic(n, topn):"{:20} {:.3f}".format(term, round(frequency, 3)))"")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment