Skip to content

Instantly share code, notes, and snippets.

@foowaa
Created December 6, 2018 08:11
Show Gist options
  • Save foowaa/2d66c2fed073b70a97b2883c31643413 to your computer and use it in GitHub Desktop.
Save foowaa/2d66c2fed073b70a97b2883c31643413 to your computer and use it in GitHub Desktop.
'''
corpus is a list of list of string
like:
[['human', 'interface', 'computer'],
['survey', 'user', 'computer', 'system', 'response', 'time'],
['eps', 'user', 'interface', 'system'],
['system', 'human', 'system', 'eps'],
['user', 'response', 'time'],
['trees'],
['graph', 'trees'],
['graph', 'minors', 'trees'],
['graph', 'minors', 'survey']]
'''
dic = Dictionary(corpus)
data = [dic.doc2bow(words) for words in corpus]
lda = LdaModel(data, id2word=dic, num_topics=2)
# 1st topic, 10 words
for _, topic in lda.show_topics(num_topics=1, num_words=10, formatted=False):
result.append([w[0] for w in topic])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment