Chatbots are becoming an integral part of any business starting from marketing, sales, customer service to HR. They are playing a vital role in improving user experience as well. For example, Lufthansa has launched a Facebook-integrated chatbot – Mildred – to assist passengers in searching for the cheapest flights within the next nine months. Pretty useful, huh?

But if we go back a little bit, chatbots hadn’t always been this smart always. If we turn through the pages of history, we would come across Joseph Weizenbaum's program ELIZA, published in 1966. It seemed to be able to fool the humans into believing that it is actually a human. But Eliza was not really intelligent. It’s process involved the recognition of some cue phrases in the input, and the output response would already be pre-programmed so as to create a meaningful conversation. Thus, it was more of an illusion of understanding rather than a real understanding. ELIZA was followed by Parry in 1972 and Racter in 1983.

The next breakthrough was AIML chatbots, about which we are going to discuss in this article today. AIML or Artificial Intelligence Makeup Language enables people to input knowledge into chatbots based on the A.L.I.C.E free software technology, originally created by Richard Wallace. AIML was created in 1995 as an XML dialect which comes with all the good and bad that comes with XML. Let’s have a look at how AIML works.

Categories

The basic unit of knowledge in AIML is called category. A category consists of an input question or stimulus, and an output option called the template. The input question is also called the pattern. This is how a simple category looks

<category> <pattern>WHERE ARE YOU FROM</pattern> <template>I AM FROM LONG ISLAND.</template> </category>

Here are the meaning of each tags used here:

<category> − defines the unit of knowledge in Alice bot's knowledge base. <pattern> − defines the pattern to match what a user may input to an Alicebot. <template> − defines the response of an Alicebot to user's input.

So, basically, your pattern is matched to a pre-programmed template and accordingly a response is delivered. The bot is not quite thinking on its own but simply matching to a large collection of data.

The AIML language is pretty simple, it consists of words and wildcard characters, “*” and “_” and is not case-sensitive. Now, let’s learn a few more things about Pattern and Template.

Pattern(Input)

Patterns is a series of letters/characters which are used to match the input to the output. For example, if the pattern is, “WHAT IS YOUR NAME?”, AIML will ignore the upper-case letter and will match to only one output.

Now if you give the input as “WHAT IS YOUR *”, AIML will match it to a series of answers which can be anything, name, favorite color etc.

Template

A template is a response to a matched pattern. In other words, it is the output which we get. An example of a simple text template - My name is John.

A template may use variables, such as the example

My address is <bot name="address"/> which will substitute the bot's address into the sentence

(Here the <bot /> ( bot element ) is used to recall custom bot properties defined in the .properties file. These variables are accessible to all users of the bot.)

Template elements include basic text formatting, conditional response (if-then/else), and random responses.

Now, how do you add a random response?

Let’s understand with the help of an example,

<category> <pattern>WHAT IS MY *</pattern> <template> <random> <li>continue.</li> <li>need more details</li> <li>No idea.</li> <li>I don't know what that means.</li> <lirephrase it in another way.</li> </random> </template> </category>

The "*" is a wildcard that matches anything.
It might seem that AIML is simply a collection or database of questions and answers, but it is quite not so. If you want to look for other categories to provide the output and not only the matched category, you need to implement recursion. Let’s see how is it implemented in AIML.

Recursion

AIML implements recursion with the <srai> operator. If you look at the name closely, ai, quite obviously stands for Artificial Intelligence while sr can stand for “stimulus-response," or "syntactic rewrite," or "symbolic reduction” etc. This tag enables AIML to define the different targets for the same template.

Syntax : <srai> pattern </srai>

Different implementation of <srai>

Symbolic Reduction

Let’s look at two sentences, “Who called you?” and “By whom were you called?” The first question format is way simpler than the second one. Now, to explain symbolic reduction, it refers to the process of simplifying complex grammatical forms into simpler ones.

Using AIML categories, many of the complex forms reduce to simpler forms using AIML categories designed for symbolic reduction.

Let’s understand with the help of more detailed examples:

HUMAN - Who was Shakespeare?
BOT - Shakespeare was a famous English Playwright
HUMAN - Who was Hitler?
BOT - He was a German Dictator

Now if questions are spiced up a little,

HUMAN - Do you know who Shakespeare was?

This is achieved by the <srai> tag.

1. Create a category

<category> <pattern>WHO IS SHAKESPEARE</pattern> <template>Shakespeare was a famous English Playwright.</template> </category>

<category> <pattern> WHO IS HITLER </pattern> <template>HITLER is a German Dictator.</template> </category>
2. Create a Generic category

<category> <pattern>DO YOU KNOW WHO * IS</pattern>
<template><srai>WHO IS <star/></srai></template>
</category>

Whatever input matched this pattern, the portion bound to the wildcard * may be inserted into the reply with the markup <star/>.

Divide and Conquer

Divide and Conquer is used to reuse sub sentences in making a complete reply. For example, a sentence begins with Hello! Regardless of the later part, a bot should reply a specific word in response to “Hello”, let’s say, it’s “Hey!”.

<category> <pattern>Hello, Good Morning</pattern> <template>Hey!</template> </category>

Now, let’s define a generic category:

<category> <pattern>Hello *</pattern>
<template><srai>Hey</srai> <sr/></template>
</category>

Synonyms

Synonyms are words with similar meanings. A bot should reply in the same manner for similar words. It s probably the most widespread use of the tag. Let’s look at the example below:

<category> <pattern>School</pattern>
<template>Learning centre</template>
</category>

Now implement <srai> tag to create a generic category

<category> <pattern>School</pattern>
<template><srai>College</srai></template>
</category>

So, looks like we have discussed pretty much on how AIML bots answer to your queries. Next, let’s look at their advantages and disadvantages.

Advantages/Disadvantages

The advantages would be, learning AIML is very easy and also the language in itself is very simple. It’s easy to download and you can get pre-authored AIML sets and libraries. AIML is very easy to use but not powerful enough if you want to make a chatbot that “looks” intelligent these days. Reasons?

AIML has a relatively weak pattern matching, can be time-consuming and difficult to maintain. As you have seen in the previous examples, we need to create a lot of categories, that’s heavy!
Also, with the commence of Chatscript and AISL, it’s kind of becoming obsolete, but quite useful if you are a beginner and just want to experiment with building a chatbot, given its easy learning curve.

Hope you enjoyed reading the article; well this is the first part of the “Chatbot Evolution” series. Don’t forget to subscribe to our blog to get the future articles emailed right to your mailbox.

Select the category you want to explore