views:

5968

answers:

10

I want to build a bot that asks someone a few simple questions and branches based on the answer. I realize parsing meaning from the human responses will be challenging, but how do you setup the program to deal with the "state" of the conversation?

EDIT: It will be a one-to-one conversation between a human and the bot.

A: 

I would suggest looking at Bayesian probabilities. Then just monitor the chat room for a period of time to create your probability tree.

EBGreen
+12  A: 

You probably want to look into Markov Chains as the basics for the bot AI. I wrote something a long time ago (the code to which I'm not proud of at all, and needs some mods to run on Python > 1.5) that may be a useful starting place for you: http://sourceforge.net/projects/benzo/

EDIT: Here's a minimal example in Python of a Markov Chain that accepts input from stdin and outputs text based on the probabilities of words succeeding one another in the input. It's optimized for IRC-style chat logs, but running any decent-sized text through it should demonstrate the concepts:

import random, sys

NONWORD = "\n"
STARTKEY = NONWORD, NONWORD
MAXGEN=1000

class MarkovChainer(object):
    def __init__(self):
        self.state = dict()

    def input(self, input):
        word1, word2 = STARTKEY
        for word3 in input.split():
            self.state.setdefault((word1, word2), list()).append(word3)
            word1, word2 = word2, word3 
        self.state.setdefault((word1, word2), list()).append(NONWORD)

    def output(self):
        output = list()
        word1, word2 = STARTKEY
        for i in range(MAXGEN):
            word3 = random.choice(self.state[(word1,word2)])
            if word3 == NONWORD: break
            output.append(word3)
            word1, word2 = word2, word3
        return " ".join(output)

if __name__ == "__main__":
    c = MarkovChainer()
    c.input(sys.stdin.read())
    print c.output()

It's pretty easy from here to plug in persistence and an IRC library and have the basis of the type of bot you're talking about.

argv0
+2  A: 

I think you can look at the code for Kooky, and IIRC it also uses Markov Chains.

Also check out the kooky quotes, they were featured on Coding Horror not long ago and some are hilarious.

Joel Coehoorn
+1  A: 

I think to start this project, it would be good to have a database with questions (organized as a tree. In every node one or more questions). These questions sould be answered with "yes " or "no".

If the bot starts to question, it can start with any question from yuor database of questions marked as a start-question. The answer is the way to the next node in the tree.

Edit: Here is a somple one written in ruby you can start with: rubyBOT

nutario
A: 

I'm not sure this is what you're looking for, but there's an old program called ELIZA which could hold a conversation by taking what you said and spitting it back at you after performing some simple textual transformations.

If I remember correctly, many people were convinced that they were "talking" to a real person and had long elaborate conversations with it.

Ferruccio
+5  A: 
Josh Millard
+1  A: 

Imagine a neural network with parsing capabilities in each node or neuron. Depending on rules and parsing results, neurons fire. If certain neurons fire, you get a good idea about topic and semantic of the question and therefore can give a good answer.

Memory is done by keeping topics talked about in a session, adding to the firing for the next question, and therefore guiding the selection process of possible answers at the end.

Keep your rules and patterns in a knowledge base, but compile them into memory at start time, with a neuron per rule. You can engineer synapses using something like listeners or event functions.

Ralph Rickenbach
A: 

If you're just dabbling, I believe Pidgin allows you to script chat style behavior. Part of the framework probably tacks the state of who sent the message when, and you'd want to keep a log of your bot's internal state for each of the last N messages. Future state decisions could be hardcoded based on inspection of previous states and the content of the most recent few messages. Or you could do something like the Markov chains discussed and use it both for parsing and generating.

dlamblin
+2  A: 

You might want to look at http://www.ai-programming.com/

He has some tutorials in a variety of languages that walk you through the simplest possible robot to some with some fairly complex logic.

(Yeah, I know I'm a year and a half behind the thread, but was recently looking for something similar.)

Rahn
A: 

check out daden chatbots www.daden.co.uk also look at this youtube video http://www.youtube.com/watch?v=9hte2MJ54CA

Abi Carver