Skip to content

Instantly share code, notes, and snippets.

@aneesha
Last active July 23, 2017 13:53
Show Gist options
  • Save aneesha/146e3d030ca7cbced9d94c34d87e5714 to your computer and use it in GitHub Desktop.
Save aneesha/146e3d030ca7cbced9d94c34d87e5714 to your computer and use it in GitHub Desktop.
def display_topics(H, W, feature_names, documents, no_top_words, no_top_documents):
for topic_idx, topic in enumerate(H):
print "Topic %d:" % (topic_idx)
print " ".join([feature_names[i]
for i in topic.argsort()[:-no_top_words - 1:-1]])
top_doc_indices = np.argsort( W[:,topic_idx] )[::-1][0:no_top_documents]
for doc_index in top_doc_indices:
print documents[doc_index]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment