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 ------------------- 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/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 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) 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)