forked from jessykate/streamLDA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
20 lines (18 loc) · 683 Bytes
/
util.py
File metadata and controls
20 lines (18 loc) · 683 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
def print_topics(lambda_, topn):
''' prints the top n most frequent words from each topic in lambda '''
topics = lambda_.num_topics
for k in xrange(topics):
this_topic = lambda_._topics[k]
if topn < len(this_topic):
printlines = topn
else:
printlines = len(this_topic)
print 'Topic %d' % k
print '---------------------------'
for word in this_topic.keys(): # this_topic.items() is pre-sorted
if printlines > 0:
print '%20s \t---\t %.4f' % (word, this_topic.freq(word))
printlines -= 1
else:
break
print