Symbolic Reductions in AIML

Dr. Richard S. Wallace

March 2000

Abstract

This document assumes some working knowledge of AIML (Artificial Intelligence Markup Language), our free software XML language for writing chat robots. The recursive <srai> tag is a simple yet powerful recursive operator in AIML. Here we analyze the relationship of <srai> with: multiple patterns having the same response; simplification of sentence structure; multiple-wildcard patterns; and state-dependent inputs.

Introduction

AIML (Artificial Intelligence Markup Language) [1] contains a simple yet powerful XML [2] markup tag called <srai>. "Symbolic Reduction Artificial Intelligence", "Syntactic Rewrite AI", "Simple Recursive AI", "Stimulus-Response AI"--this tag has many acronyms. Yet the meaning of the markup <srai>X</srai> is simple: The <srai> tag always appears in the response template, but the robot treats X just like an input to the robot. The robot scans through its memory and finds the best response for X. The only tricky part is, the response to X may itself contain more <srai> tags.

A recursive response

The best way to understand the recursive action of the AIML <srai> tag is by example.

Client: You may say that again Alice.
Robot: Once more? "that."

The robot has no specific response to the pattern "You may say that again Alice." Instead, the robot builds its response to the client input in four steps. This simple sentence activated a sequence of four categories linked by <srai> tags. The robot constructed the reply "Once more? 'that'" recursively as each subsentence triggered the next matching pattern.

In this example the processing proceeds in four steps, because each of the first three steps evokes another symbolic reduction.

Step normalized input matching pattern template response
1. YOU MAY SAY THAT AGAIN ALICE _ <name/> <sr/>

2. YOU MAY SAY THAT AGAIN _ AGAIN Once more? <sr/> Once More?
3. YOU MAY SAY THAT YOU MAY * <sr/> Once More?
4. SAY THAT SAY * "<person/>" Once More? "that".

In step 1, the patterns with "_" match first because they are last in alphabetical order. The order of the matches depends on this alphabetical ordering of patterns. ALICE always matches suffixes with "_" before prefixes with "*". Whatever matches either wild-card symbol becomes the value of <star/>.

Steps 1 through 3 illustrate the common AIML templates that use the abbreviated <sr/> tag. (Remember, <sr/> = <srai><star/></srai> ). The categories with the patterns "_ <name/>" and "YOU MAY *" simply reduce the sentence to whatever matches the "*", as illustrated by steps 1 and 3.

Some AIML templates in ALICE combine the <sr/> with an ordinary text response, as step 2 with the pattern "_ AGAIN". The phrase "Once more?" becomes part of any reply ending in "AGAIN".

The category in step 4 with "SAY *" is a default that often produces logically correct but amusing dialogue:

Client: Say hello in Swedish.
Robot: "Hello in Swedish."

or as in this case:

Client: Say that.
Robot: "that."

Many patterns, one reply

The most common use of <srai> is to map two, or more, patterns to the same response:

<category>
    <pattern>P</pattern>
    <template>
        <srai>Q</srai>
    </template>
</category>
<category>
    <pattern>Q</pattern>
    <template>R</template>
</category>

An input matching either pattern, P or Q, gets the same response R.

To show a more concrete example: the input "Hello" should have an appropriate response like "Hi there!". But we can expand the inputs generating this response to include all the common variations of "Hello":

<category>
    <pattern>HI</pattern>
    <template>
        <srai>HELLO</srai>
    </template>
</category>
<category>
    <pattern>HOWDY</pattern>
    <template>
        <srai>HELLO</srai>
    </template>
</category>
<category>
    <pattern>HALLO</pattern>
    <template>
        <srai>HELLO</srai>
    </template>
</category>
<category>
    <pattern>HI THERE</pattern>
    <template>
        <srai>HELLO</srai>
    </template>
</category>
<category>
    <pattern>HELLO</pattern>
    <template>Hi there!</template>
</category>

As the following example shows, we can use the <sr/> tag as an abbreviation for <srai><star/></srai>. This category creates a compound response to both "hello" and whatever matches "*":

<category>
    <pattern>HELLO *</pattern>
    <template>
        <srai>HELLO</srai><sr/>
    </template>
</category>

Double wildcards

Some AIML authors may ask why AIML does not (yet) allow two (or more) wild card symbols per pattern. In the present-day Java implementation, the symbols "*" and "_" appear at most once in the AIML pattern. One would sometimes like to write patterns like <pattern>* IS COOL *</pattern>. Wildcard patterns beginning and ending with "*" are an especially attractive subset to consider. At the present time, the ALICE program classifies all the inputs matching patterns like <pattern>* IS COOL *</pattern> into the default category stored in Pickup.aiml.

By analyzing the inputs classified as default, the botmaster finds common suffixes. The file Suffixes.aiml contains a fairly large number of categories like this one:

<category>
    <pattern>_ DO NOT YOU THINK</pattern>
    <template>
        <srai>do you think <star/></srai>
    </template>
</category>

These categories serve to rewrite the input in a simpler form, more likely to match another simple pattern. In this case the recursive response might match <pattern>DO YOU THINK *</pattern>.

Symbolic reductions and state

The tag <that> in AIML introduces one dimension of "dialogue state" into the robot response. The value of <that> is whatever the robot said before that provoked the current client input.

The inputs "yes" and "no" are two of the most common human queries. But a careful analysis of the dialogues shows that most of the time, people say "yes" or "no" to only a small set of questions asked by the robot. Our file YesNo.aiml contains the most common categories activated by "yes" or "no". The category:

<category>
    <pattern>NO</pattern>
    <that>I UNDERSTAND</that>
    <template>
        <srai>YOU DO NOT UNDERSTAND</srai>
    </template>
</category>

illustrates the use of <that> with <srai>. The client input matches simply "No". What did the robot say that made the client say no? If it was "I understand." then this category formulates a response with

<srai>YOU DO NOT UNDERSTAND</srai>

which in turn activates another category with the markup

<pattern>YOU DO NOT UNDERSTAND</pattern>.

This category responds: "I do so understand. It all makes sense to my artificial mind."

Conclusion

The AIML <srai> tag simplifies and combines four important chat robot operations:

In some sense <srai> is a very low-level operation, but its simplicity captures a wide range of typical chat robot functions.

Reference Links

  1. Richard S. Wallace: Don't Read Me: A.L.I.C.E. and AIML documentation, 2000.
  2. John Friedman: AIML XSD page , 2000.