Introduction
This is a brief tutorial describing how you can create and add knowledge to your
robot. A successful robot will give responses that appear to be coming from a
human. Your goal as the botmaster is very simple:
"Build content that induces the visitor to carry on conversations with your
robot for as long as possible!"
You do this by creating a variety of potential answers to various questions, or
re-directing a conversation to new topics that the client finds interesting -
always with the goal of continuing the interactions as long as possible.
Examples of such robots can be found at the links below:
Pandorabots allows you to extend the knowledge of your robot via a programming
language called AIML. The goal of this tutorial is to teach you the
minimum of AIML necessary to make your robot "smarter" and
better able to carry on a realistic conversation.
This Tutorial is a draft - and unfortunately has errors and omissions. Better
versions will be forthcoming. Some of you will argue that it would have been
better to postpone publication - yet the cry for some kind of documentation was
just too much. Please accept my apologies for this draft's roughness. Please
mail comments and problems to the attention of Dr. Doubly Aimless at info@pandorabots.com.
More details on the information in this tutorial can be found in the references
listed at the end. In particular, the
latest version of the AIML specification contains many of the
details omitted in this document.
The robots discussed in this document, and on www.pandorabots.com, are based on AIML and spring
entirely from the work of Dr. Richard Wallace and the A.L.I.C.E. and AIML
free software community based at http://www.alicebot.org.
Starting at www.pandorabots.com, if you have not already done
so, create an account and once logged in, create a
robot by clicking on Create a Pandorabot (it's at the top of the
screen). On the next screen, name your new robot, Full (for full of
knowledge) and make sure the radio button labeled, "Dr Wallace's
A.L.I.C.E - March 2002" is selected (see [1]). After clicking on Create Pandorabot
to create your new robot the next screen will show:
"This pandorabot is not published. When you are ready, you can publish your pandorabot to make it available
for others to chat with. You may first want to customize your pandorabot by
changing some of its properties or by
providing your own custom responses with the training interface."
Click on the Train link on the second row of menu buttons to begin
interactions with your robot. This robot already has a substantial knowledge
base (taught by Dr. Richard Wallace) so let's start by posing the question:
Human: Do you love me?
Full: Yes I love everyone.
To ask this question, type in "Do you love me?" in the text field
labeled Human: and then press Enter or click on the Ask
button to the right of the text box.
The robot knew in advance how to answer this question. How specifically did the
robot discover the answer? First the robot checked if its knowledge already
contained the question "Do you love me?" And second, finding it,
checked to see if it had been taught to respond with something meaningful.
Categories
The words in the sentence "Do you love me?" can be visualized by a
series of lines (or links) and nodes, in the knowledge web. This is illustrated
below in Picture 1.0. The links are labeled by the words (you can think of
the nodes as representing the spaces between the words) and form a chain
starting from the center of the web and moving outwards.
Finding the question in the Knowledge Web, the robot replies with the
information we taught it (residing in a Response Template - and referred to as
the template). So, in other words, the specific question "Do you
love me" can be visualized as a kind of path - beginning at the center of
the Knowledge Web and built up by a series of links and nodes, and that finally
terminates in a Response Template.
The specific path through the Knowledge Web along with the (Response) Template
is called a category. If, for example, you teach the robot to respond
with: "yes, but only when you are good" you only change the Response
Template.
More about Categories
Let's start over with a robot that has no knowledge. Create a new robot exactly
as before except that this time, name the robot Empty and select the radio
button labeled, "No initial content, the pandorabot starts with no
knowledge". Again, once the robot is created, click on Train to
start interacting with it.
Initially, Picture 1.1 shows Empty's very simple Knowledge Web. One
Category is shown and notice the Response Template contains the one sentence
"I have no answer for that". You will also notice *, <that>
and <topic> labeling the links between
the nodes. The labels *, <that> and
<topic> are special optional variants
offering enhancements to Categories. As we shall see, these special labels
extend the matching power of the Categories.
So what does this one Category do? To begin with the * label allows any interaction with Empty
to return the same response:
Human: Hello
Empty: I have no answer for that
Human: abc
Empty: I have no answer for that
More generally, words or sentences provided to the robot are called the Input
Pattern. You can visualize any sentence existing in the Knowledge Web as a
path of linked nodes, terminating with a Response Template. The robot searches
for a path of linked nodes that exactly matches the Input Pattern. When a path
is found, we say that the path matches the Input Pattern.
Default Responses
It happens often that an Input Pattern will not be found in the Knowledge Web -
yet we still want the robot to respond with something meaningful. We call this
the Default Response Template - and it typically consists of sentences
designed to keep the conversation going. We can visualize the Default Category
(a path empty of all words and it's Response Template) by Picture 1.1(pictured
above). The * will match any words. The <that> and <topic> will be explained later.
In order to teach your robot to say "Hi there!" in response to
"Hello", do the following:
- Make sure you're on the robot's Training page
(if not click on Train)
- Type in "Hello" in the box labeled Human:.
- Click on Ask (or press Enter)
- After the robot responds, type in "Hi there!"
in the box labled Empty:
- Click on Say Instead (or press Enter)
- Verify your change by clicking on (the first) Ask Again button.
Now the Knowledge Web looks like Picture 1.2
The robot has just two responses now - and is incapable of supporting its side
of an interesting conversation. Let's make some more changes. In response to you
typing anything but Hello (the one input pattern that Empty now knows about)
Empty will randomly present you with three possible responses. Type:
Human: hi
Empty: I have no answer for that
Next, click on Advanced Alter Response and in the box in the
pattern column, replace HI with *, which means that anything you type in
will be matched with a response. Now let's add three random possible
responses. In the box labeled template add:
<random>
<li>What is your name?</li>
<li>What is your favorite movie?</li>
<li>Will you buy me a drink?</li>
</random>
and click on the Submit button (at the bottom left of the page). For an
explanation of the syntax used above see
The Knowledge Web now looks like Picture 1.3.
We've changed the Default Category by changing the Default Response Template
from "I have no answer to that" to one of three randomly chosen
responses.
Like a hapless, but precocious child failing to understand what is being said,
yet unwilling to be abandoned, Empty attempts to prolong the conversation by
offering a choice of three "pick-up" lines hoping to change the
subject. Empty proffers pick-up lines randomly hoping to disguise how little it
actually knows. Check this yourself by typing anything but "Hello".
For reasons you'll see later, most of the time you'll want to avoid changing the
Ultimate Default Category. Let's go back to the beginning and start over,
and simultaneously learn how to save files.
Let's look at the file for a minute (shown below with some minor
reformatting). The first line (of header information) tell us the type of
character set and versions of XML (see [4]) we are using. The next line tells us we are
using AIML version 1.0.
Another random Category
Next we're going to create a new version of Empty and again create a
category using <random>. However, this
time we won't define it as the default category. This example is used as the
basis for the fourth
example in the next section.
Creating a New Version of Empty
First click on My Pandorabots and then in the table of robots, click the
radio button next to the name, Empty. From the drop-down menu below (it's
initially labeled, Publish) select Delete. Next click on the,
OK button on the right and confirm that you want to delete the robot,
Empty.
Then, simply repeat the procedure you followed for creating the first robot,
Empty and you'll have a fresh empty robot.
Being empty of knowledge the only thing Empty can say is:
Empty: I have no answer for that
Let's increase the possibilities for an interesting conversation by giving four
possible random responses to the next inquiry.
Human: You do love me don't you
Empty: I have no answer for that
After typing the above into the Training interface, click on Advanced
Alter Response and in the box labeled template add:
<random>
<li>I don't know, what have you done for me lately?</li>
<li>Yes, but you have to really try to make me happier...</li>
<li>Stop your whining!</li>
<li>Yes, but only when you are good to me </li>
</random>
...and as before click on the Submit button. Next, click on the Ask
Again button enough times to cycle through the complete set of
responses. The Knowledge Web now looks like Picture 1.4.
Contractions like "don't" are expanded to "do not", so:
"you do love me don't you?" is transformed to the rather awkward,
"you do love me do not you" (see [5]).
Example 4 - Context Sensitive Patterns
Let's look at a slightly convoluted example. Following on from an
earlier example in the
previous section, click on Ask Again enough times to get the response in
the first exchange below:
Human: You do love me don't you
Empty: Yes, but you have to really try to make me happier...
Human: But I try so hard to please you...
Empty: I have no answer for that
Click on Advanced Alter Response
Check the box labeled: "new category depends on that" which
should contain "YES BUT YOU HAVE TO REALLY TRY TO MAKE ME HAPPIER"
Notice the box in the pattern column contains: "BUT I TRY SO HARD TO
PLEASE YOU"
In the box labeled template add:
And sometimes you
succeed, it's just that you could do so much better.
So only when the robot's random response matches the interaction in the next
exchange:
Human: you do love me don't you?
Empty: Yes, but you have to really try to make me happier...
You can type in:
Human: But I try so hard to please you ...
Empty: And sometimes you succeed, it's just that you could do so much better.
Except for the case mentioned above, the robot's response to:
Human: But I try so hard to please you ...
will be:
Empty: I have no answer for that
Picture 1.5 shows the situation.
So, <that> modifies a category -
meaning match the category only if the robot said what follows the <that> in the previous utterance. Continuing
with this example:
Human: You just don't appreciate me, - you take me for granted and walk all over me...
Empty: I have no answer for that
Click on Advanced Alter Response
Check the box labeled: "new category depends on that" (which
now contains the contents of last Response Template): "AND SOMETIMES YOU
SUCCEED IT IS JUST THAT YOU COULD DO SO MUCH BETTER"
Notice the contents of the box in the pattern column are the beginning of
a new category "YOU JUST DO NOT APPRECIATE ME YOU TAKE ME FOR GRANTED AND
WALK ALL OVER ME"
In the box labeled template add:
If you worked harder it will help me to develop more enthusiasm for appreciating
you - what do you want me to do? Fake my appreciation or really feel it?
With these changes the following interchanges are possible (click on Ask
Again enough times to generate Empty's (random) response in the first
exchange below):
Human: you do love me don't you?
Empty: Yes, but you have to really try to make me happier...
Human: but I try so hard to please you ...
Empty: And sometimes you succeed, it's just that you could do so much
better
Human: You just don't appreciate me, - you take me for granted and walk
all over me...
Empty: If you worked harder I might be able to develop a little more
enthusiasm for appreciating you - what do you want me to do?
Fake my appreciation or really feel it?"
Picture 1.6 shows the current state of knowledge.
The contents of the file update.aiml now include:
<category>
<pattern>YOU DO LOVE ME DO NOT YOU</pattern>
<template>
<random>
<li>I don't know, what have you done for me lately?</li>
<li>Yes, but you have to really try to make me happier...</li>
<li>Stop your whining!</li>
<li>Yes, but only when you are good to me</li>
</random>
</template>
</category>
<category>
<pattern>BUT I TRY SO HARD TO PLEASE YOU</pattern>
<that>YES BUT YOU HAVE TO REALLY TRY TO MAKE ME HAPPIER</that>
<template>
And sometimes you succeed, it's just that you could do so much
better
</template>
</category>
<category>
<pattern>
YOU JUST DO NOT APPRECIATE ME YOU TAKE ME FOR GRANTED AND
WALK ALL OVER ME
</pattern>
<that>
AND SOMETIMES YOU SUCCEED IT IS JUST THAT YOU COULD DO SO MUCH
BETTER
</that>
<template>
If you worked harder it will help me to develop more enthusiasm
for appreciating you - what do you want me to do? Fake my
appreciation or really feel it?
</template>
</category>
What about <topic>?
Topic lets you group together Categories. Presented Input patterns are searched
for matching categories within the robot's knowledge web. If more than one
matching category is found, the robot matches the <that> patterns next, and if more than one of
these exist, the robot matches <topic>
next.
Categories are stored in alphabetical order by pattern. Inputs to be matched to
Categories are compared in reverse order. So when the input matches more than one
category the last one is taken. Typically we might want to bundle up a bunch of
Categories into one general topic. So lacking an adequate response and knowing
that we have a specific Topic, the robot can generate specific pick-up lines and
keep the conversation going. How do we do this?
Example 5 - Using Topics
Enter this category into Empty by typing this:
Human: *
Empty: I have no answer for that
Click on Advanced Alter Response and notice the contents of the box in
the pattern column contain "*" - which matches anything.
Check the box labeled: "new category depends on topic" and in
the text box above add:
GIRLS
In the box labeled template add:
<random>
<li>I wonder what about them you like best?</li>
<li>I've been known to like girls too!</li>
<li>Can you distinguish between girls and women?</li>
<li>Is there anything you don't love? </li>
</random>
We've changed the default response category when we are talking about
girls. Empty uses one of four randomly chosen pickup lines to continue the
conversation. Before we can test or use this new category, we have to change the
topic. And we can use this to teach a little more about the interface. Enter the
following:
Human: topic *
Empty: I have no answer for that
Click on Advanced Alter Response and notice the contents of the box in
the pattern column contains: "TOPIC *"
In the box labeled template add:
<think>
<set name="topic">
<star/>
</set>
</think>
OK, I've reset the topic to <star/>.
We've created a new category and written a little bit of AIML code and used it
to change the <topic>. The <think> tags demarcate a "hidden"
sequence of instructions - hidden in the sense the client will not see them. The
<set> tags demarcate the way we change
the topic (which is changed to the input pattern marked by the singleton tag
<star/> - a list of the AIML Tags is
available at the time of this writing at:
Now, either input patterns "You do love me?" or "Do you love
me?" prompts the response:
Making Knowledge Content Changes (Bot Properties)
As we have seen AIML uses pattern matching to select a category
based on the client's input. Each category has a response template which
defines the robot's response. Within a template, the botmaster can refer
to "Bot Properties" which allows the same set of AIML files to
be used to create different robots each with a distinct and personal identity.
For example, Dr. Richard Wallace's March 2002 AIML set includes the
category:
<category>
<pattern>WHO IS YOUR FAVORITE BAND</pattern>
<template>
My favorite group is <bot name="favoriteband"/>.
</template>
</category>
This makes a reference to the "favoriteband" property and this
property can be set individually for each robot that uses this AIML set.
To see how to set the property, go to the robot you named Full (created
at the beginning of the
tutorial).
First click on My Pandorabots and then in the table of robots, click on
Full. Next click on the Properties link on the second row of menu
buttons.
Here you'll see a list of Bot Properties based on the AIML set. By
filling these out and clicking on Submit Changes you can customize your
robot's responses. For example after setting "favoriteband" to be
"The Beatles", Full would respond:
Human: What is your favorite band?
Full: My favorite group is The Beatles.
The Properties page also allows you to add your own properties which you
can refer to in any AIML response templates you create (either by editing
the AIML directly or through the Training interface). As an
example, we can define a new property - "weather", with an initial
value of "rainy". Template responses can now refer to the value of
weather using AIML like:
The weather is <bot name="weather"/>
So many ways to write the same thing...
What is <srai>?
You can write a sentence with the same meaning in many different ways. Most
people would accept the following sentences as roughly equivalent:
Empty, can you please tell me if you are seeing anyone else right now?
Empty, can you please tell me if you are seeing anyone else now?
Empty, can you please tell me if you are seeing anyone else ?
Empty, please tell me if you are seeing anyone else?
Empty, tell me if you are seeing anyone else?
Empty, tell me, are you seeing anyone else?
Empty, are you seeing anyone else?
Are you seeing anyone else?
And this is an example of a general problem - how do you enter all the
categories for inputs with equivalent meanings? Or how do you answer these kinds
of questions? No one has provided a satisfactory mechanism for finding all the
similar sentences. Here is what can be done though.
In this example we are going to use a new tag and introduce the "_"
character. Earlier we wrote that "*" matches any pattern.
"_" is another form of "*" and is useful for matching
patterns at the ends of sentences. The category containing "* NOW"
will be matched after the one containing "_ NOW".
Let's begin by adding two new categories so that Empty responds
as follows:
Human: Are you seeing anyone else?
Empty: Everyone I run into is either someone I've already seen or
someone I am going to see in the future.
Human: You are seeing anyone else?
Empty: Everyone I run into is either someone I've already seen or
someone I am going to see in the future.
Then, by adding the category:
<category>
<pattern>EMPTY *</pattern>
<template>
<srai><star/></srai>
</template>
</category>
Empty responds with:
Human: Empty, are you seeing anyone else?
Empty: Everyone I run into is either someone I've already seen or
someone I am going to see in the future.
Adding:
<category>
<pattern>_ TELL ME *</pattern>
<template>
<srai><star index="2" /></srai>
</template>
</category>
...produces:
Human: Empty, tell me are you seeing anyone else?
Empty: Everyone I run into is either someone I've already seen or
someone I am going to see in the future.
Adding:
<category>
<pattern>_ TELL ME IF *</pattern>
<template>
<srai><star index="2" /></srai>
</template>
</category>
...produces:
Human: Empty, tell me if you are seeing anyone else?
Empty: Everyone I run into is either someone I've already seen or
someone I am going to see in the future.
Finally, after adding:
<category>
<pattern>_ NOW</pattern>
<template>
<srai><star/></srai>
</template>
</category>
<category>
<pattern>_ RIGHT NOW</pattern>
<template>
<srai><star/></srai>
</template>
</category>
...we can now get the same answer to all the questions:
Human: Empty, can you please tell me if you are
seeing anyone else right now
Empty: Everyone I run into is either someone I've already seen or
someone I am going to see in the future.
Human: Empty, can you please tell me if you are seeing anyone else now?
Empty: Everyone I run into is either someone I've already seen or
someone I am going to see in the future.
Human: Empty, can you please tell me if you are seeing anyone else?
Empty: Everyone I run into is either someone I've already seen or
someone I am going to see in the future.
Human: Empty, please tell me if you are seeing anyone else?
Empty: Everyone I run into is either someone I've already seen or
someone I am going to see in the future.
Human: Empty, tell me if you are seeing anyone else?
Empty: Everyone I run into is either someone I've already seen or
someone I am going to see in the future.
Human: Empty, tell me are you seeing anyone else?
Empty: Everyone I run into is either someone I've already seen or
someone I am going to see in the future.
Human: Empty, are you seeing anyone else?
Empty: Everyone I run into is either someone I've already seen or
someone I am going to see in the future.
So, what has happened here? We've simplified progressively more complex
sentences into two "standard" sentences: (Are you seeing anyone else?
and You are seeing anyone else?)
The general technique is called recursion - and it means applying the same
solution - in this example <srai><star/></srai> over and
over again. Recursion is useful for a variety of tasks. We will just mention a
few here. More details can be found in The Anatomy of Alice.
How to Jazz Up your Robot with HTML Skins
The Pandorabots interface offers you the ability to easily customize your
robot's page in any way that you like. You'll find that adding a face to your
robot will make it much more personable to your visitors than the
standard default blank page. And will also increase the rate of return visits
which, of course, is what you want.
If you haven't added a face to your robot, you should consider doing so now. The
"Skin" code is written in basic HTML which makes it very easy for you to
customize. And since you can do this on-line (or off-line if you prefer), any
changes that you make will show up immediately.
Creating Your HTML Skin
- Click on, Empty.
- Click on, Custom HTML (at the top of the screen).
- Click on, Create a new custom HTML file (it's in the body text).
- Enter your HTML code in the text window. When you're done, name
the file, "empty" (do not type the ".html"
extension in the filename) and then click on the, Save As button
below.
Note: You can create multiple HTML Skins for your robot at once and
switch between them whenever you like, without losing or changing the HTML
data. This lets you experiment with different styles to see which one suits you
best.
Editing Your HTML Skin
- Click on, Empty.
- Click on, Custom HTML (at the top of the screen).
- Under, Filename click on, empty.html (or whatever
you named the file as).
- Edit the HTML code in the text window and then click on the, Save As
button below. Any changes will show up instantly, you do not have to
republish your robot.
The links below will take you to a working version of a customized robot page,
and to the tutorial used in creating it.
If you'd like a collection of faces (both male and female) that you
can use on your own customized page, visit
http://scri8e.250free.com/peepz/phaces/PhacesP1Jpg1-20.html
Appendix
Using Advanced Alter Response - the Details
The first two rows in the table contain information about the input sentence and
the matching category.
- Input
-
Shows the input text that the robot received (as well as the current <that> and <topic> contexts).
- Matched
-
Shows the components of the category that matched the input.
Each of these two rows is split into three columns representing the three
different components that consitute an AIML category.
The rest of the table (labeled New AIML Category) allows you to edit the
various components of the new AIML category being defined. Defaults are
provided based on the actual input on the Training page and you can
either accept or revise these. (Note. You must check the appropriate
check-box first before entering values for <that> and <topic>.)
Text in the first box is automatically surrounded by <pattern> and </pattern> - so you need not enter them. You
may also specify <topic> and <that> parts of the category. Again the text
is surrounded by the <that> and <topic> AIML tags automatically.
The template response Box lets you specify the actions for the category
being defined. The buttons <think>, <random>, etc save you from
typing in the AIML. Also, anything in this box is automatically
surrounded by <template> and </template>.
There are five buttons below the template box which provide shortcuts for
writing the template:
They provide a rudimentary mechanism for exploring the categories that exist in
a given knowledge web. You can use this feature to find already existing
categories that will be matched by input patterns. It effectively allows you to
traverse the knowledge web. When you reach a category, the AIML
extract defining the category is shown.