Alice chatbot

ALICE is the original chatbot created with AIML. The distribution of pyAIML, in which this kernel is based, contains the free version of Alice. It can be learned by using the appropriate magic:


In [1]:
%learn alice


Learning database: 'alice'
Loading startup.xml... done (0.01 seconds)
Loading patterns
Loading ai.aiml... done (0.10 seconds)
Loading drugs.aiml... done (0.01 seconds)
Loading money.aiml... done (0.02 seconds)
Loading politics.aiml... done (0.01 seconds)
Loading science.aiml... done (0.01 seconds)
Loading emotion.aiml... done (0.07 seconds)
Loading movies.aiml... done (0.08 seconds)
Loading primeminister.aiml... done (0.01 seconds)
Loading sex.aiml... done (0.07 seconds)
Loading astrology.aiml... done (0.00 seconds)
Loading food.aiml... done (0.03 seconds)
Loading mp0.aiml... done (1.95 seconds)
Loading primitive-math.aiml... done (0.01 seconds)
Loading sports.aiml... done (0.01 seconds)
Loading atomic.aiml... done (0.90 seconds)
Loading geography.aiml... done (0.29 seconds)
Loading mp1.aiml... done (1.29 seconds)
Loading psychology.aiml... done (0.35 seconds)
Loading stack.aiml... done (0.01 seconds)
Loading badanswer.aiml... done (0.05 seconds)
Loading gossip.aiml... done (0.04 seconds)
Loading mp2.aiml... done (2.14 seconds)
Loading pyschology.aiml... done (0.17 seconds)
Loading stories.aiml... done (0.17 seconds)
Loading biography.aiml... done (0.26 seconds)
Loading history.aiml... done (0.00 seconds)
Loading mp3.aiml... done (2.30 seconds)
Loading reduction0.safe.aiml... done (2.06 seconds)
Loading that.aiml... done (0.39 seconds)
Loading bot.aiml... done (1.13 seconds)
Loading humor.aiml... done (0.02 seconds)
Loading mp4.aiml... done (1.53 seconds)
Loading reduction1.safe.aiml... done (2.16 seconds)
Loading update1.aiml... done (0.42 seconds)
Loading bot_profile.aiml... done (0.05 seconds)
Loading imponderables.aiml... done (0.02 seconds)
Loading mp5.aiml... done (1.19 seconds)
Loading reduction2.safe.aiml... done (1.70 seconds)
Loading update_mccormick.aiml... done (0.04 seconds)
Loading client.aiml... done (1.10 seconds)
Loading inquiry.aiml... done (0.03 seconds)
Loading mp6.aiml... done (0.97 seconds)
Loading reduction3.safe.aiml... done (1.31 seconds)
Loading wallace.aiml... done (0.31 seconds)
Loading client_profile.aiml... done (0.10 seconds)
Loading interjection.aiml... done (0.01 seconds)
Loading music.aiml... done (0.01 seconds)
Loading reduction4.safe.aiml... done (1.27 seconds)
Loading xfind.aiml... done (0.01 seconds)
Loading computers.aiml... done (0.05 seconds)
Loading iu.aiml... done (0.01 seconds)
Loading numbers.aiml... done (0.09 seconds)
Loading reduction.names.aiml... done (1.63 seconds)
Loading continuation.aiml... done (0.01 seconds)
Loading knowledge.aiml... done (0.68 seconds)
Loading personality.aiml... done (0.05 seconds)
Loading reductions-update.aiml... done (0.01 seconds)
Loading date.aiml... done (0.02 seconds)
Loading literature.aiml... done (0.02 seconds)
Loading phone.aiml... done (0.01 seconds)
Loading religion.aiml... done (0.08 seconds)
Loading default.aiml... done (1.19 seconds)
Loading loebner10.aiml... done (0.01 seconds)
Loading pickup.aiml... done (0.02 seconds)
Loading salutations.aiml... done (0.04 seconds)
Loaded 98087 new patterns

Once learned, we can start to talk with the bot


In [2]:
Hi


Hi there!

In [3]:
How are you?


I am doing very well. How are you ?

In [4]:
I'm ok


I'm sure you are.

In [5]:
Do you like reading?


What is not to like about reading ?

In [6]:
I don't know


Me either.

Note that we can write more than one sentence. Alice will process both sentences and produce each output in sequence


In [7]:
What's the meaning of life? Do you like music?


Actually, it's twenty-three, not forty-two. Yes I like music , especially Opera.

Defining bot predicates

We can use the %setp magic to define bot predicates. The patterns in Alice rules already make use of some bot predicates, so if we define them they will make the conversation more interesting


In [8]:
What's your name?


I am called Nameless.

In [9]:
%setp bot name Alice


Setting bot predicate: name = Alice

In [10]:
What's your name?


My name is Alice.

In [11]:
# Let's define a few more bot predicates, from among the ones used in Alice categories
%setp bot master Richard Wallace
%setp bot master Botmaster
%setp bot favoritebook Tale of Two Cities
%setp bot favoritemovie Blade Runner
%setp bot location Moonbase Alpha
# Other bot predicates used in ALICE DB:
#    emotions celebrity friend friends size gender age 
#    kingdom order family genus species


Setting bot predicate: master = Richard Wallace
Setting bot predicate: master = Botmaster
Setting bot predicate: favoritebook = Tale of Two Cities
Setting bot predicate: favoritemovie = Blade Runner
Setting bot predicate: location = Moonbase Alpha

We can inspect the currently defined bot predicates and we will see that they have been defined


In [12]:
%show bot


Bot predicates:
favoritemovie = Blade Runner
location = Moonbase Alpha
master = Botmaster
name = Alice
favoritebook = Tale of Two Cities

In [13]:
What's your favorite book?


The best book I read recently was Tale of Two Cities. Have you read Tale of Two Cities ?

In [14]:
Not yet


And?

In [15]:
What's your favorite movie?


My favorite movie is Blade Runner. Have you seen Blade Runner ?

In [16]:
No


Excuse me!

In [17]:
What did you like most?


The set design.

To inspect the bot state there are a few magics available. We have already seen %show bot, which shows the defined bot predicates. Another one is %show session, which shows the session predicates.


In [18]:
%show session


Session fields:
it = Blade Runner
topic = Blade Runner

And the %bot size magic shows the number of defined categories


In [19]:
%show size


Number of loaded categories: 98087

Saving state

The predicates that we have defined can be saved to a file by using the %save magic


In [20]:
%save alice-predicates nobrain nosub rawfiles


Saving session predicates... 2 predicates
Saving bot predicates... 5 predicates
Skipping subs
Skipping brain patterns
Writing main bot file: alice-predicates.ini

This file can be loaded later on with %load. There are additional options to make it save the full brain state (all defined categories, in compiled form) and substitution strings. See 03-chatbot-inline for additional examples.

Version: 1.0 (2016-07-19)
Author: Paulo Villegas