Skip to content

Instantly share code, notes, and snippets.

@ShairozS
Created August 4, 2020 00:50
Show Gist options
  • Select an option

  • Save ShairozS/8a3b8c75966cf9ca5dd7d02c7ea2c229 to your computer and use it in GitHub Desktop.

Select an option

Save ShairozS/8a3b8c75966cf9ca5dd7d02c7ea2c229 to your computer and use it in GitHub Desktop.
Retrieve the label of a topic on a trained Gensim LDA model
def topic_label(ldamodel, topicnum):
alltopics = ldamodel.show_topics(formatted=False)
topic = alltopics[topicnum]
topic = dict(topic[1])
return(max(topic, key=lambda key: topic[key]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment