From a237d75979fe47d6505ea0c3bc731050503064e8 Mon Sep 17 00:00:00 2001 From: Luis Pedro Coelho Date: Sun, 25 Jun 2017 13:55:34 +0200 Subject: [PATCH 1/2] BUG Fixes API usage For newer versions of gensim at least, topics are represented as `(word, frequency)`. closes #21 --- ch04/blei_lda.py | 4 ++-- ch04/wordcloud.py | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ch04/blei_lda.py b/ch04/blei_lda.py index bbad9d1f..7f6ac2b3 100644 --- a/ch04/blei_lda.py +++ b/ch04/blei_lda.py @@ -36,9 +36,9 @@ # Iterate over all the topics in the model for ti in range(model.num_topics): words = model.show_topic(ti, 64) - tf = sum(f for f, w in words) + tf = sum(f for _, f in words) with open('topics.txt', 'w') as output: - output.write('\n'.join('{}:{}'.format(w, int(1000. * f / tf)) for f, w in words)) + output.write('\n'.join('{}:{}'.format(w, int(1000. * f / tf)) for w, f in words)) output.write("\n\n\n") # We first identify the most discussed topic, i.e., the one with the diff --git a/ch04/wordcloud.py b/ch04/wordcloud.py index 6c5302ea..accca2d6 100644 --- a/ch04/wordcloud.py +++ b/ch04/wordcloud.py @@ -24,8 +24,6 @@ def create_cloud(oname, words,maxsize=120, fontname='Lobster'): # gensim returns a weight between 0 and 1 for each word, while pytagcloud # expects an integer word count. So, we multiply by a large number and # round. For a visualization this is an adequate approximation. - # We also need to flip the order as gensim returns (value, word), whilst - # pytagcloud expects (word, value): - words = [(w,int(v*10000)) for v,w in words] + words = [(w,int(v*10000)) for w,v in words] tags = make_tags(words, maxsize=maxsize) create_tag_image(tags, oname, size=(1800, 1200), fontname=fontname) From 52891e6bac00213bf94ab1a3b1f2d8d5ed04a774 Mon Sep 17 00:00:00 2001 From: Luis Pedro Coelho Date: Mon, 21 May 2018 15:45:33 +0200 Subject: [PATCH 2/2] BUG Fix function import --- ch12/image-classification.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ch12/image-classification.py b/ch12/image-classification.py index 09dbd5b4..6f76d26d 100644 --- a/ch12/image-classification.py +++ b/ch12/image-classification.py @@ -39,7 +39,7 @@ def compute_texture(im): @TaskGenerator def chist(fname): - from features import color_histogram + from features import chist as color_histogram im = mh.imread(fname) return color_histogram(im)