Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Random fun with statistical language models.
Python Shell
Latest commit 2faae64 @darius harmonize license, add note
Failed to load latest commit information.
LICENSE harmonize license, add note
README harmonize license, add note rename some functions add simpleverse, a base for experimenting without all the cruft of th… add all_successors() update readme add text scanners add anagram reorderer/ranker minor cleanup extract the name data from the crunchbase downloads extract the name data from the crunchbase downloads
contractionmodel.bigram add model data
contractionmodel.unigram add model data fix emvoweling by bigrams style add mnemonic-finder and surprisingness-highlighter harmonize license, add note more aggressive strip() to deal with Windows crlf line endings do n-grams for any n; output sentence endings; keep only pronounceabl… refactor is_iambic
sonnet123 wrote the README and imported the code add stupid text 'summarizer' simpler code, also works for n=1 add mnemonic-finder and surprisingness-highlighter update readme


Currently here: a Markov random sonnet generator. There's sample
output at
(The program does somewhat better now than what's shown off there.)
To generate it:
$ python sonnet  # or limerick or other verse form it knows about

Currently missing: the data it works from. You need two files:

* 2gm-common6: from
  (lines like "word1 word2\tcount" for common bigrams)
  (word1 can be "<S>" for start of sentence)
* cmudict.0.7a: from

I'd like to add I don't normally publish code in such a crap state.


Three files checked in to this repo (,
contractionmodel.bigram, and contractionmodel.unigram) are NOT
copyright by me, Darius Bacon. They're derived from files at (but not identical to any of them). by Peter Norvig is distributed under the MIT license.
The two data files weren't originally included here, and should
probably be removed, but I'm including them for the moment to
make it easier to actually try out the code.

The remaining files are by me, and distributed under the MIT license.

Some other hacks thrown in here:

* generates multiword anagrams

* helps to sort anagrams by quality (using n-gram
statistics and brute force)

* breaks down the Gutenberg Project's KJ Bible into raw material for other hacks here

* generate random Web2.0 company names, along with a plausibility rating for each.

* reverses disemvoweling

* tries to invent mnemonics like pi's "How I wish I could enumerate pi easily..."

* finds pairs of words that blend nicely, like book + hookup --> bookup

* generates chapter 'summaries' for a book, like

* is a super-crude sentence segmenter

* writes HTML that highlights words with increasing intensity the more unlikely they are according to a language model

* described above

See also for verse-making
rewritten in Javascript.

Finally, there's -- I'm sorry I
don't remember if it has worthwhile differences from the verse code in
this repo.
Something went wrong with that request. Please try again.