From c0a3b3a397d22c6941012c78d24c0fcfefe740fc Mon Sep 17 00:00:00 2001 From: Luis Pedro Coelho Date: Sun, 27 Nov 2016 11:05:39 +0100 Subject: [PATCH 1/4] DOC Make explicit how to get AP data --- ch04/README.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ch04/README.rst b/ch04/README.rst index 7fe0a92f..99a3c186 100644 --- a/ch04/README.rst +++ b/ch04/README.rst @@ -4,6 +4,16 @@ Chapter 4 Support code for *Chapter 4: Topic Modeling* + +AP Data +------- + +To download the AP data, use the ``download_ap.sh`` script inside the ``data`` +directory:: + + cd data + ./download_ap.sh + Word cloud creation ------------------- From c4c71a59644d6f9c80993aed3bae5eb6f453c00c Mon Sep 17 00:00:00 2001 From: Luis Pedro Coelho Date: Tue, 28 Mar 2017 18:47:48 +0200 Subject: [PATCH 2/4] MIN Update link to AP data --- ch04/data/download_ap.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ch04/data/download_ap.sh b/ch04/data/download_ap.sh index 6de8ded8..da27814a 100755 --- a/ch04/data/download_ap.sh +++ b/ch04/data/download_ap.sh @@ -1,3 +1,3 @@ #!/bin/sh -wget http://www.cs.princeton.edu/~blei/lda-c/ap.tgz +wget http://www.cs.columbia.edu/~blei/lda-c/ap.tgz tar xzf ap.tgz From a237d75979fe47d6505ea0c3bc731050503064e8 Mon Sep 17 00:00:00 2001 From: Luis Pedro Coelho Date: Sun, 25 Jun 2017 13:55:34 +0200 Subject: [PATCH 3/4] 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 4/4] 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)