Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Cobe uses Python setuptools for distribution and installation. It is distributed via the Python Package Index which means that installation can be as simple as:
$ easy_install cobe
If you don’t have
easy_install, you can download the latest version of Cobe and run its install target directly:
$ ./setup.py install
Cobe’s data file is called a “brain”. This is where it stores statistical information about the text it has learned and some basic information about how the brain was first configured. The brain contains two N-order Markov chains, one trained in a forward direction and one in reverse. By default, these are 5th order (the same as MegaHAL). The order is configurable at brain creation time.
You can train the brain with text using the
cobe learn command or using the
Brain.learn() API. You can get it to reply by interacting with
cobe console or the
Cobe comes with a command line tool that can be used to interact with a brain. It’s a script with subcommands, which will be familiar to anyone used to CVS-style usage.
$ cobe console
Running the console command with no arguments opens the brain found in
cobe.brain in the current directory (initializing it if it doesn’t exist). This command loops forever, training the brain with a line of input from the user and then replying to that line.
The brain in this example has been trained using sample data from Wikipedia
$ cobe console > good morning! Anthracite is a good friend of Penelope (Kristin Wiig).
Learning larger amounts of text
Interacting directly with the console is fine, but Cobe’s reply quality really picks up after it has learned a few thousand lines. The command-line tool includes a command that loops over a text file, learning each line:
$ cobe learn <text file>
IRC botBuilt in
If you have the Twisted framework installed, Cobe comes with an IRC bot. It learns all the text said on a specified server and channel. When spoken to directly, the bot will reply.
$ cobe irc-client -s <irc server hostname> -c "#channel"
You can find the main API documentation via pydoc (
pydoc cobe.Brain), but there are three steps for simple usage:
1. Create a Brain object, passing the filename you’d like to use. This will be created if it doesn’t exist.
2. Learn some text using
Brain.learn, which takes the string to learn.
3. Generate replies with
Brain.reply, which takes a string that seeds the reply.
#!/usr/bin/env python from cobe.brain import Brain b = Brain("cobe.brain") b.learn("This is the only thing I know!") print b.reply("Hello cobe")
user@host:~ $ python cobe-example.py
This is the only thing I know!