Created
December 6, 2018 08:11
-
-
Save foowaa/2d66c2fed073b70a97b2883c31643413 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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