Skip to content

Commit a237d75

Browse files
committed
BUG Fixes API usage
For newer versions of gensim at least, topics are represented as `(word, frequency)`. closesluispedro#21
1 parent c4c71a5 commit a237d75

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

‎ch04/blei_lda.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
# Iterate over all the topics in the model
3737
fortiinrange(model.num_topics):
3838
words=model.show_topic(ti, 64)
39-
tf=sum(fforf, winwords)
39+
tf=sum(ffor_, finwords)
4040
withopen('topics.txt', 'w') asoutput:
41-
output.write('\n'.join('{}:{}'.format(w, int(1000.*f/tf)) forf, winwords))
41+
output.write('\n'.join('{}:{}'.format(w, int(1000.*f/tf)) forw, finwords))
4242
output.write("\n\n\n")
4343

4444
# We first identify the most discussed topic, i.e., the one with the

‎ch04/wordcloud.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ def create_cloud(oname, words,maxsize=120, fontname='Lobster'):
2424
# gensim returns a weight between 0 and 1 for each word, while pytagcloud
2525
# expects an integer word count. So, we multiply by a large number and
2626
# round. For a visualization this is an adequate approximation.
27-
# We also need to flip the order as gensim returns (value, word), whilst
28-
# pytagcloud expects (word, value):
29-
words= [(w,int(v*10000)) forv,winwords]
27+
words= [(w,int(v*10000)) forw,vinwords]
3028
tags=make_tags(words, maxsize=maxsize)
3129
create_tag_image(tags, oname, size=(1800, 1200), fontname=fontname)

0 commit comments

Comments
(0)