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()
topic_model.export_all_topics_per_documents()
topic_model.export_all_topic_visualisation_data()
topic_model.print_topics(compact=False)
topic_model.print_topics(extended=True)
......@@ -347,25 +347,25 @@ class TopicModel:
print(model.get_document_topics(self._bow[n]))
print()
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):
self._logging.info(topic)
else:
for topic in self._models[topic_id].show_topics(topn):
self._logging.info(topic)
if extended == True:
for n in range(topic_id):
self._logging.info("Terms per topic {0} (of {1})".format(n + 1, topic_id))
self._logging.info("Terms per topic {0} (of {1})".format(n, topic_id - 1))
self._logging.info("{: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):
self._logging.info("{:20} {:.3f}".format(term, round(frequency, 3)))
logging.info("")
......
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