I mentioned that I created a chat bot named Jarvis. Since then I've been asked a few times what goes into creating Jarvis. I thought I'd take the time and explain what is going on behind the scenes.
First off Jarvis sits on top of database with the following tables.
- word - A library of known words he found online
- keywords - collections of words that Jarvis thought went together
- responses - Response that can be given to a user
There are other tables, but that is the core ones.
Now I loaded Jarvis with the library that ELIZA the original chat bot used. That system had a number of keywords and responses to those key words. For example: If the user had typed "Hi", there were 3 possible responses. "How are you?", "Hello", "Welcome".
Jarvis would randomly pick one of those.
I also hand entered in some other "choice" keywords and phrases.
The next step was to have him learn from input. So when ever Jarvis puts out a response that includes a question (question mark), he would wait for the response and tag it as a possible "answer" to that question. That way when another user asked the question of Jarvis this was in his possible responses.
So for example, Jarvis might start off with a memory like the following:
Key: How are you?
Possible Responses: "Good", "I'm sad" or "I'm happy".
Let's say he had the following conversation with user 1.
Jarvis: Hi
User 1: Hello Jarvis
Jarvis: How are you?
User 1: I'm good, I had bacon this morning.
Now Jarvis' memory looks like the following:
Key: How are you?
Possible Responses: "Good", "I'm sad" or "I'm happy" or "I'm good, I had bacon this morning"
So when user 3 comes along the conversation looks like this...
Jarvis: Hello
User 3: Hi Jarvis, How are you?
Jarvis: I'm good, I had bacon this morning
User 3: That sounds good
Jarvis: how are you?
User 3: Hungry
Jarvis used the first users answers and he also learned a new answer to the question "How are you?"
Key: How are you?
Possible Responses: "Good", "I'm sad" or "I'm happy" or "I'm good, I had bacon this morning", "Hungry"
CuriosityAt first I built him so that any response that was a question was given priority. But that lead to Jarvis asking to many questions. So Jarvis now has a curiosity factor. The more curious he is, the more likey that he will give a response that is in the form of a question. This sponsors more responses for him.
You can increase or decrease curiosity by typing "moreCurious" or "lessCurious" into the text box.
Peeking into Jarvis BrainThere is a checkbox "Peek into Brain". Clicking this will let you see into Jarvis process. It shows you the following:
- Words gathered from your input
- Last 5 words learned (popularity is in parens)
- The Keywords or phrases that were triggered based on your words
- Selected/Best Keyword is highlights in bold
- The Responses triggered from the best keyword
- The last 5 learned keyword phrases
- The last 5 learned responses
ScoreingJarvis tracks each chat session and gives it a score. Keep in mind each possible response is scored. Anytime Jarvis uses an response with a score higher than 0, he adds one to the session score.
This should lead to interesting sessions having a higher score, but I have not thoroughly tested that.
Jarvis can be found at
http://www.mobeamer.com/lab/jarvisRandomnessThere are two places where Jarvis uses randomness.
First: Sometimes after finding all the keyphrases from the users input. Multiple keypharases have the same score. In this case, Jarvis will randomly select one of them.
Second: Sometimes after finding all responses from a keyphrase, mulitple responses have the same score. In this case, Jarvis will randomly select one.
The random function uses php's in-built rand() function. Which is not 100% random but close enough for me.