NIPyLL

Foolish fun with a Non-Intelligent Python Language Learner.

The concept is very simple. The user enters a phrase. The system breaks the phrase into tokens at word boundaries and, in some way, records which words follow which, like so:

From the phrase "We are closing for lunch." the system deduces:

  • "are" follows "We"
  • "closing" follows "are"
  • "for" follows "closing"
  • "lunch" follows "for"

No attempt is made to parse the phrase, no meaning is assigned to any token. Hence Non-Intelligent Language Learner.

The system then generates its own response phrase, by following the list of word-follows-word rules that it has learned so far. Words are picked at random, but the system must previously have "seen" each pair of words (word[n], word[n+1]) together.

Most often, the phrases it produces are nonsense. Sometimes they're amusing. Sometimes strings of phrases seem to form a real thread of conversation, but this is all in the user's imagination. It's very Monty Python.

Documentation

If you're at all interested in playing with NIPyLL, feel free to use the online CGI version, which is primed with part of Monty Python's Dead Parrot Sketch. Just start typing. Follow the "New Script" link to start again.

You'll find the Dead Parrot NIPyLL here.

Alternatively, you can download the Python source below, along with a couple of lexicons. There's a simple script called nipyll.py which can be used like so:

usage: nipyll.py [ file ]

The single argument provides the name of a lexicon file to be loaded at startup, and to which lexicon changes will be saved at exit.

You'll notice that NIPyLL only ever talks lower-case. He's built that way; he hears lower-case, too. He's also punctuation-blind. Don't worry about it.

Example

A short and typically confusing conversation with NIPyLL, primed with the parrot lexicon by default, and saving the resulting lexicon to my_lexicon.niplex:

./nipyll.py my_lexicon.niplex
you stunned him just as he s resting
> What a very strange thing to say!
norwegian blue
> Is that like "robin's egg blue"?  Does it mean something I don't want to know?
what a very strange thing to say
> Well, you started it.
no he moved
> who moved? 
does it
> does what?
oh yes the fjords
> Oh, the fjords, don't get me started.  I never wanted to work in a pet shop, you know.
i don t want to work in a very strange thing to say
> Do you want to be a lumberjack too?
you mean miss
> ^D

Downloads

Why download it when you can play with it for free?

If you insist, NIPyLL and associated modules and data files are available under the terms of the GNU General Public License and can be downloaded directly from the subversion repository.

At the very least, you'll need to download:

Alternatively, you can check out your own copy with subversion, like so:

svn co http://nipyll.jessies.org/svn/trunk nipyll

Disclaimer

This script and associated modules and data are provided in good faith. The author accepts no responsibility for any mishaps, snafus, fubars or whatnots. Seriously.

Bugs

This is my first Python script. I skipped "Hello, World!" and cut straight to the chase. Consequently, I've no doubt that there are a few gotchas and bugs lurking. If you find one, please contact me. When reporting a bug, please include as much detail as possible, including:

  • output from python -c 'import sys; print sys.version, sys.platform, sys.modules'
  • output from uname -a
  • lexicon files and output, including the error messages received, if any

See Also

I've written a blog article which provides a little background, and goes some way to explaining why.