<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>statistically-improbable-phrases on S Anand</title>
    <link>https://www.s-anand.net/blog/tag/statistically-improbable-phrases/</link>
    <description>Recent content in statistically-improbable-phrases on S Anand</description>
    <generator>Hugo -- 0.164.0</generator>
    <language>en-us</language>
    <lastBuildDate>Mon, 23 Mar 2009 15:33:29 +0000</lastBuildDate>
    <atom:link href="https://www.s-anand.net/blog/tag/statistically-improbable-phrases/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Statistically improbable phrases on Google AppEngine update</title>
      <link>https://www.s-anand.net/blog/statistically-improbable-phrases-on-google-appengine-update/</link>
      <pubDate>Sat, 12 Apr 2008 12:00:00 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/statistically-improbable-phrases-on-google-appengine-update/</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve added some interactivity to the &lt;a href=&#34;http://sip.s-anand.net/&#34;&gt;Statistically improbable phrases&lt;/a&gt; application. You can now:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Filter out stopwords&lt;/li&gt;
&lt;li&gt;Dynamically filter infrequent words and commonly used words&lt;/li&gt;
&lt;li&gt;Dynamically play with the contrast and font size&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;comments&#34;&gt;Comments&lt;/h2&gt;
&lt;!-- wp-comments-start --&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Srikanth&lt;/strong&gt; &lt;em&gt;12 Apr 2008 12:00 pm&lt;/em&gt;:
Dear sir, I was searching for Ilayaraja songs and came across your wonderful compilation of 15 wonderful articles. Good one. Please do write more on music.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Collin&lt;/strong&gt; &lt;em&gt;12 Apr 2008 12:00 pm&lt;/em&gt;:
I love this application. Because now, I can create a url to NY Times, and see what is the main subject of the day. :)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;S Anand&lt;/strong&gt; &lt;em&gt;12 Apr 2008 12:00 pm&lt;/em&gt;:
Thanks, Colin!&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Spencer&lt;/strong&gt; &lt;em&gt;12 Apr 2008 12:00 pm&lt;/em&gt;:
I was curious as to whether or not I could use this pointed into a specific personal corpus to separate documents from one another.&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- wp-comments-end --&gt;
</description>
    </item>
    <item>
      <title>Statistically improbable phrases on Google AppEngine</title>
      <link>https://www.s-anand.net/blog/statistically-improbable-phrases-on-google-appengine/</link>
      <pubDate>Tue, 08 Apr 2008 12:00:00 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/statistically-improbable-phrases-on-google-appengine/</guid>
      <description>&lt;p&gt;I &lt;a href=&#34;http://googleappengine.blogspot.com/2008/04/introducing-google-app-engine-our-new.html&#34;&gt;read&lt;/a&gt; about &lt;a href=&#34;http://appengine.google.com/&#34;&gt;Google AppEngine&lt;/a&gt; early this morning, and applied for an invite. Google&amp;rsquo;s issuing beta invites to the first 10,000 users. I was pretty convinced I wasn&amp;rsquo;t among those, but turns out I was lucky.&lt;/p&gt;
&lt;p&gt;AppEngine lets you write web apps that Google hosts. People have been highlighting that it give you access to the &lt;a href=&#34;http://en.wikipedia.org/wiki/Google_file_system&#34;&gt;Google File System&lt;/a&gt; and &lt;a href=&#34;http://en.wikipedia.org/wiki/Bigtable&#34;&gt;BigTable&lt;/a&gt; for the first time. But to me, that isn&amp;rsquo;t a big deal. (I&amp;rsquo;m not too worried about reliability, and MySQL / flat files work perfectly well for me as a data store.)&lt;/p&gt;
&lt;p&gt;What&amp;rsquo;s more interesting unlike Amazon&amp;rsquo;s EC2 and S3, this is free up to a certain quota. And you get a fair bit of processing power and bandwidth for free. One of the reasons I&amp;rsquo;ve held back on creating some apps was simply because it would take away too much bandwidth / CPU cycles from my site. (I&amp;rsquo;ve &lt;a href=&#34;https://www.s-anand.net/blog/reducing-the-server-load/&#34;&gt;had this problem before&lt;/a&gt;.) Google &lt;a href=&#34;http://code.google.com/appengine/articles/quotas.html&#34;&gt;quota&lt;/a&gt; is 10 GB of bandwidth per day (which is about 30 times what my site uses). And this is on Google&amp;rsquo;s &lt;a href=&#34;https://www.s-anand.net/blog/why-google-reader/&#34;&gt;incredibly&lt;/a&gt; &lt;a href=&#34;https://www.s-anand.net/blog/gmail-is-fast/&#34;&gt;fast&lt;/a&gt; servers It also offers 200 million megacycles a day. That&amp;rsquo;s like a dedicated 2.3 GHz processor (200 million megacycles = 200,000 GHz x 1 second ~ 2.3 GHz x 86,400 seconds/day) &amp;ndash; better, because this is the average capacity, not peak capacity. The only restriction that really worries me is that only 3 apps are allowed per developer.&lt;/p&gt;
&lt;p&gt;So I decided to give a shot at publishing some code I&amp;rsquo;d kept in reserve for a long time. You may remember my &lt;a href=&#34;https://www.s-anand.net/blog/statistically-improbable-phrases/&#34;&gt;statistical analysis of Calvin &amp;amp; Hobbes&lt;/a&gt;. For this, I&amp;rsquo;d created a script in Perl that could generate Statistically Improbable Phrases (SIPs) for any text. This is based on (a somewhat limited) 23MB corpus of ebooks that I had. I&amp;rsquo;d wanted to put that up on my website, but &amp;hellip;&lt;/p&gt;
&lt;p&gt;AppEngine only uses Python. So the first task was to &lt;a href=&#34;http://www.activestate.com/Products/activepython/&#34;&gt;get Python&lt;/a&gt;, and then to &lt;a href=&#34;http://www.diveintopython.org&#34;&gt;learn Python&lt;/a&gt;. The only saving grace was that I was just cutting-and-pasting most of the time. Google wasn&amp;rsquo;t helping:&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://www.s-anand.net/blog/assets/flickr-google-appengine-over-quota-error_2398327713_o-png.webp&#34; title=&#34;Google AppEngine Over Quota Error&#34;&gt;&lt;img alt=&#34;Google AppEngine Over Quota Error&#34; loading=&#34;lazy&#34; src=&#34;https://www.s-anand.net/blog/assets/flickr-google-appengine-over-quota-error_2398327713_o-png.webp&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Anyway, the site is up. You can view it at &lt;strong&gt;&lt;a href=&#34;http://sip.s-anand.net/&#34;&gt;sip.s-anand.net&lt;/a&gt;&lt;/strong&gt; for now. Just type a URL, and it&amp;rsquo;ll tell you the improbable words in that site.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;http://sip.s-anand.net/&#34;&gt;Visit sip.s-anand.net&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Technical notes&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I realise that these are statistically improbable &lt;strong&gt;words&lt;/strong&gt;, not &lt;strong&gt;phrases&lt;/strong&gt;. I&amp;rsquo;ll get to the phrases in a while.&lt;/p&gt;
&lt;p&gt;The logic is simple:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Get the frequency of words in a corpus&lt;/strong&gt;. I pre-generated this file. It has over 100,000 words.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Get the URL as text&lt;/strong&gt;. Rather than muck around with Python, I decided to use the &lt;a href=&#34;http://cgi.w3.org/cgi-bin/html2txt&#34;&gt;W3 html2txt&lt;/a&gt; service.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Convert the text to words&lt;/strong&gt;. &lt;a href=&#34;https://www.s-anand.net/blog/splitting-a-sentence-into-words/&#34;&gt;Splitting text into words is tricky&lt;/a&gt;. For now, I&amp;rsquo;m simply assuming that any group of letters is a word, and anything that&amp;rsquo;s not a letter is a word delimiter.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Find the relative frequency (improbability) of words&lt;/strong&gt;. This is the frequency in the URL divided by the frequency in the corpus, normalised (i.e. scale it so that the maximum value is 1.0).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Create a tag cloud&lt;/strong&gt;. I use the word frequency as the size and the improbability as the colour. You need a bit of mathematical jugglery to get the pattern right. Right now, I&amp;rsquo;m taking the 6th root of the improbability and the logarithm of the frequency to get a reasonably smooth tag cloud.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The source code is at &lt;a href=&#34;http://statistically-improbable-phrases.googlecode.com/&#34;&gt;statistically-improbable-phrases.googlecode.com&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: 12-Apr-2008. I&amp;rsquo;ve added some interactivity. You can play with the contrast and font size, the filter out common or infrequent words.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: 22-Apr-2008. Added concordance. You can click on a word and see the context in which it appears.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;comments&#34;&gt;Comments&lt;/h2&gt;
&lt;!-- wp-comments-start --&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Sasidhar&lt;/strong&gt; &lt;em&gt;8 Apr 2008 12:00 pm&lt;/em&gt;:
Interesting. Great to see you&amp;rsquo;ve already developed an App. :) I was trying it out, and looks like something broke. Here&amp;rsquo;s the error. Traceback (most recent call last): File &amp;ldquo;/base/python_lib/versions/1/google/appengine/ext/webapp/__init__.py&amp;rdquo;, line 486, in __call__ handler.post(*groups) File &amp;ldquo;/base/data/home/apps/sip/1.35/sip.py&amp;rdquo;, line 64, in post result = urlfetch.fetch(&amp;ldquo;&lt;a href=&#34;http://cgi.w3.org/cgi-bin/html2txt?noinlinerefs=on&amp;amp;nonums=on&amp;amp;url=%22&#34;&gt;http://cgi.w3.org/cgi-bin/html2txt?noinlinerefs=on&amp;amp;nonums=on&amp;amp;url=&amp;quot;&lt;/a&gt; + urllib.quote(url)) File &amp;ldquo;/base/python_lib/versions/1/google/appengine/api/urlfetch.py&amp;rdquo;, line 95, in fetch raise DownloadError() DownloadError&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Glenn&lt;/strong&gt; &lt;em&gt;8 Apr 2008 12:00 pm&lt;/em&gt;:
This is a great app and uses some techniques I wanted to learn more about. The source code seems out of date with the currently running app. Any chance you can update the source .zip file as well? Thanks in advance.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Brandon&lt;/strong&gt; &lt;em&gt;8 Jun 2011 10:40 pm&lt;/em&gt;:
The app is really, really neat. Is there any chance there will be a version that can do the same for Word files?&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- wp-comments-end --&gt;
</description>
    </item>
    <item>
      <title>Statistically improbable phrases</title>
      <link>https://www.s-anand.net/blog/statistically-improbable-phrases/</link>
      <pubDate>Wed, 23 Aug 2006 12:00:00 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/statistically-improbable-phrases/</guid>
      <description>&lt;p&gt;&lt;strong&gt;Calvin and Hobbes has some recurrent themes&lt;/strong&gt;, like &lt;a href=&#34;http://calvinethobbes.free.fr/english/c_home.html&#34;&gt;Hobbes pouncing&lt;/a&gt;, &lt;a href=&#34;http://www.angelfire.com/wa/zzaran/calvin.html&#34;&gt;snow art&lt;/a&gt;, &lt;a href=&#34;http://calvinethobbes.free.fr/english/c_elections.html&#34;&gt;polls&lt;/a&gt;, &lt;a href=&#34;http://calvinethobbes.free.fr/english/c_santa.html&#34;&gt;letters to Santa&lt;/a&gt;, &amp;hellip;&lt;/p&gt;
&lt;p&gt;Over the last 5 years, I&amp;rsquo;ve transcribed the &lt;a href=&#34;https://www.s-anand.net/blog/calvin/&#34;&gt;Calvin and Hobbes&lt;/a&gt; comics, and tagged them manually by theme. But &lt;strong&gt;can I generate themes automatically?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;One way is to use Amazon&amp;rsquo;s &lt;a href=&#34;http://www.amazon.com/gp/search-inside/sipshelp.html&#34;&gt;statistically improbable phrases&lt;/a&gt;. It&amp;rsquo;s a list of words that occur a lot in a book, but rarely occur in others. It gives you a good feel of what topics the book is about.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s how I did it:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Transcribe Calvin &amp;amp; Hobbes&lt;/strong&gt;. This is 99% of the work.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Make a C&amp;amp;H word list&lt;/strong&gt;. Just join all the words in Calvin and Hobbes. (Be careful about punctuation, and colloquialisms like &amp;ldquo;dunno&amp;rdquo;, &amp;ldquo;leggo&amp;rdquo;, etc.)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Get an English corpus&lt;/strong&gt;. That is, get a big list of words in normally occurring text. I have some e-books, and I picked 23 megabytes worth of these as my corpus.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Compare the word frequency in C&amp;amp;H with the corpus&lt;/strong&gt;. That is, compare the % of occurrences of a word in Calvin and Hobbes versus the corpus.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Display those with significantly higher frequency in C&amp;amp;H&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The list below has common Calvin &amp;amp; Hobbes words occurring 10 times as often as in normal text. It&amp;rsquo;s incredible how closely it relates to most of the themes.&lt;/p&gt;
&lt;p&gt;(Big words occur more often. Dark words are more improbable.)&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;allowance assignment babe balloon bat bath beanie bedtime bee beep bet bike blaster boring bug bus butter calvin calvinball cartoon cent cereal cheat chew chocolate click comic cookie crunch dad dame derkins dictator-for-life dinosaur disgusting doll doomed dumb duplicate earthling explorer fang fearless ferocious flip flush frog frosted fun fuzzy genius goggle goodness goon grade gross grown-up gum hack hamburger hamster hate hero hideous hobbes homework huey insect invent jelly jerk jurassic kid leaf loot martian math mild-mannered mom monster moron motto munch mushy nickel oatmeal ouija pant peanut perspective pit playground poll porridge poster quiz recess rosalyn rotten rub sandwich santa scary sculpture scum shovel
sissy sitter sled slimy slug slushball sniff snow snowball snowman soak spaceman spiff splash spoil sport squirt steer sting stuffed stupendous sugar susie tickle tiger toy transmogrifier transmogrify tub tuna twinky tyrannosaur underwear vacation weird wham whiff worm wormwood&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;: &amp;ldquo;Statistically improbable phrases&amp;rdquo; are a powerful tool for text analysis. You can apply it on any content and figure out what topics it talks about.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: Technically, these are &amp;ldquo;Statistically improbable WORDS&amp;rdquo;, not phrases. So I &lt;a href=&#34;https://www.s-anand.net/blog/statistically-improbable-phrases-2/&#34;&gt;re-did this analysis using phrases instead of words&lt;/a&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;comments&#34;&gt;Comments&lt;/h2&gt;
&lt;!-- wp-comments-start --&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;DMac&lt;/strong&gt; &lt;em&gt;23 Aug 2006 12:00 pm&lt;/em&gt;:
This is great. Can you be more specific on how you did this? You say that the words listed are &amp;ldquo;common&amp;rdquo; words that appear more than 10 times more often - what is your criterion for &amp;ldquo;common&amp;rdquo;? Also, what were the ranges of improbability and oftenness that you mapped into the size and color of the results. How are improbability and oftenness different, anyway? Finally, how did you handle any words in C&amp;amp;H that didn&amp;rsquo;&amp;rsquo;t appear in your corpus? I&amp;rsquo;&amp;rsquo;m very interested in hearing more from you about how you did this - I&amp;rsquo;&amp;rsquo;m looking forward to hearing from you. Best regards&amp;hellip;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Mugen&lt;/strong&gt; &lt;em&gt;15 Sep 2010 4:33 pm&lt;/em&gt;:
Any further directions to how exactly you came up with this/whether you used any software would be most helpful. Please tell us more about this. This is going to be awesome to help decide what to read. Thanks a load.
Also, does amazon have this feature for most books? I browsed a lot of books in amazon but was only able to find this in one so far.&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- wp-comments-end --&gt;
</description>
    </item>
  </channel>
</rss>
