Markovator – Python + Google App Engine + Markov chains + Twitter

Can good TV shows have a dog eating cat poop.
@markovator_dev
Markovator Dev

As a child a chat bot program called NIALL made quite an impression on me.  It came on one of those demo floppy disks from some PC magazine I forget the name of now.  NIALL stands for Non Intelligent Acquired Language Learner and what it (he?) would do is remember each word you “said” to it and the frequency that any following word appeared after it.  So for example when given the sentence “the cat sat on the mat” NIALL would remember that “cat” always precedes “sat” but that “the” only precedes “cat” half the time, the other half of the time it precedes “mat”.  Whilst slowly building up this dataset of word frequencies with each message you would type in it would use them to generate its own nonsensical, sometimes amusing replies.  You can find a better description of the process on the how it works page of this GNOME implementation.

I most enjoyed the experience of “talking” to a computer and having it reply.  Whilst NIALL wouldn’t get within a million miles of passing the Turing test it was my first experience of any kind of a “chatbot”.  Additionally the accompanying explanation of how it worked (very similar to the gNiall explanation linked above) was simple concise and illustrated the technique quite clearly.  I’ve since always wanted to hack together a clone of NIALL as an exercise.  I’m sure I initiated a number of failed attempts in QBASIC but the required string manipulation would doubtless have been beyond my 10 year old programming brain.

With the recent realisation that the 2010 analog of a chatbot is a twitterbot and the need for a simple project to get to grips with Python on Google App Engine I needed no further excuse.  markovator is the result.  If you @mention him he will send you a reply generated NIALL-style from some of your recent tweets.  He will also follow you (feel free to block him if you don’t like this!) and occasionally send out a tweet made up of all the tweets of the people he is following.  markovator won’t use @mentions you’ve sent to other people so you won’t be the cause of him spamming your friends.

Here are a few of my favourite markovator tweets that were generated whilst developing him:

@ markovated: Criticker says it really needs to have randomly spammed BBC White City Tesco.
@markovator_dev
Markovator Dev
Lovely pub lunch with my favorite movies of his nose?
@markovator_dev
Markovator Dev
@ markovated: So Ben Affleck is way more grey hairs in my Ubuntu install. Bedtime.
@markovator_dev
Markovator Dev

markovator is so named because (as far as I understand the concept) the process of generating his tweets is a kind of Markov chain in that it “is a random process with the property that the next state depends only on the current state.”  The source can be found on github (sans twitter auth details of course).

This entry was posted in Development, Python and tagged , , , , . Bookmark the permalink.

One Response to Markovator – Python + Google App Engine + Markov chains + Twitter

  1. Pingback: Twitter rate limiting and Google App Engine | HeyChinaski.com

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">