{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Alice chatbot\n", "\n", "[ALICE](http://alice.pandorabots.com/) 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:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
Learning database: 'alice'
" ], "text/plain": [ "Learning database: 'alice'\n" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Loading startup.xml... done (0.01 seconds)\n" ] }, { "data": { "text/html": [ "
Loading patterns
" ], "text/plain": [ "Loading patterns\n" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Loading ai.aiml... done (0.10 seconds)\n", "Loading drugs.aiml... done (0.01 seconds)\n", "Loading money.aiml... done (0.02 seconds)\n", "Loading politics.aiml... done (0.01 seconds)\n", "Loading science.aiml... done (0.01 seconds)\n", "Loading emotion.aiml... done (0.07 seconds)\n", "Loading movies.aiml... done (0.08 seconds)\n", "Loading primeminister.aiml... done (0.01 seconds)\n", "Loading sex.aiml... done (0.07 seconds)\n", "Loading astrology.aiml... done (0.00 seconds)\n", "Loading food.aiml... done (0.03 seconds)\n", "Loading mp0.aiml... done (1.95 seconds)\n", "Loading primitive-math.aiml... done (0.01 seconds)\n", "Loading sports.aiml... done (0.01 seconds)\n", "Loading atomic.aiml... done (0.90 seconds)\n", "Loading geography.aiml... done (0.29 seconds)\n", "Loading mp1.aiml... done (1.29 seconds)\n", "Loading psychology.aiml... done (0.35 seconds)\n", "Loading stack.aiml... done (0.01 seconds)\n", "Loading badanswer.aiml... done (0.05 seconds)\n", "Loading gossip.aiml... done (0.04 seconds)\n", "Loading mp2.aiml... done (2.14 seconds)\n", "Loading pyschology.aiml... done (0.17 seconds)\n", "Loading stories.aiml... done (0.17 seconds)\n", "Loading biography.aiml... done (0.26 seconds)\n", "Loading history.aiml... done (0.00 seconds)\n", "Loading mp3.aiml... done (2.30 seconds)\n", "Loading reduction0.safe.aiml... done (2.06 seconds)\n", "Loading that.aiml... done (0.39 seconds)\n", "Loading bot.aiml... done (1.13 seconds)\n", "Loading humor.aiml... done (0.02 seconds)\n", "Loading mp4.aiml... done (1.53 seconds)\n", "Loading reduction1.safe.aiml... done (2.16 seconds)\n", "Loading update1.aiml... done (0.42 seconds)\n", "Loading bot_profile.aiml... done (0.05 seconds)\n", "Loading imponderables.aiml... done (0.02 seconds)\n", "Loading mp5.aiml... done (1.19 seconds)\n", "Loading reduction2.safe.aiml... done (1.70 seconds)\n", "Loading update_mccormick.aiml... done (0.04 seconds)\n", "Loading client.aiml... done (1.10 seconds)\n", "Loading inquiry.aiml... done (0.03 seconds)\n", "Loading mp6.aiml... done (0.97 seconds)\n", "Loading reduction3.safe.aiml... done (1.31 seconds)\n", "Loading wallace.aiml... done (0.31 seconds)\n", "Loading client_profile.aiml... done (0.10 seconds)\n", "Loading interjection.aiml... done (0.01 seconds)\n", "Loading music.aiml... done (0.01 seconds)\n", "Loading reduction4.safe.aiml... done (1.27 seconds)\n", "Loading xfind.aiml... done (0.01 seconds)\n", "Loading computers.aiml... done (0.05 seconds)\n", "Loading iu.aiml... done (0.01 seconds)\n", "Loading numbers.aiml... done (0.09 seconds)\n", "Loading reduction.names.aiml... done (1.63 seconds)\n", "Loading continuation.aiml... done (0.01 seconds)\n", "Loading knowledge.aiml... done (0.68 seconds)\n", "Loading personality.aiml... done (0.05 seconds)\n", "Loading reductions-update.aiml... done (0.01 seconds)\n", "Loading date.aiml... done (0.02 seconds)\n", "Loading literature.aiml... done (0.02 seconds)\n", "Loading phone.aiml... done (0.01 seconds)\n", "Loading religion.aiml... done (0.08 seconds)\n", "Loading default.aiml... done (1.19 seconds)\n", "Loading loebner10.aiml... done (0.01 seconds)\n", "Loading pickup.aiml... done (0.02 seconds)\n", "Loading salutations.aiml... done (0.04 seconds)\n" ] }, { "data": { "text/html": [ "
Loaded 98087 new patterns
" ], "text/plain": [ "Loaded 98087 new patterns\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%learn alice" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Once learned, we can start to talk with the bot" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
Hi there!
" ], "text/plain": [ "Hi there!\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "Hi" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
I am doing very well. How are you ?
" ], "text/plain": [ "I am doing very well. How are you ?\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "How are you?" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
I'm sure you are.
" ], "text/plain": [ "I'm sure you are.\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "I'm ok" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
What is not to like about reading ?
" ], "text/plain": [ "What is not to like about reading ?\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "Do you like reading?" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
Me either.
" ], "text/plain": [ "Me either.\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "I don't know" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that we can write more than one sentence. Alice will process both sentences and produce each output in sequence" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
Actually, it's twenty-three, not forty-two. Yes I like music , especially Opera.
" ], "text/plain": [ "Actually, it's twenty-three, not forty-two. Yes I like music , especially Opera.\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "What's the meaning of life? Do you like music?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Defining bot predicates\n", "\n", "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" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
I am called Nameless.
" ], "text/plain": [ "I am called Nameless.\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "What's your name?" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
Setting bot predicate: name = Alice
" ], "text/plain": [ "Setting bot predicate: name = Alice\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%setp bot name Alice" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
My name is Alice.
" ], "text/plain": [ "My name is Alice.\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "What's your name?" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
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
" ], "text/plain": [ "Setting bot predicate: master = Richard Wallace\n", "Setting bot predicate: master = Botmaster\n", "Setting bot predicate: favoritebook = Tale of Two Cities\n", "Setting bot predicate: favoritemovie = Blade Runner\n", "Setting bot predicate: location = Moonbase Alpha\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Let's define a few more bot predicates, from among the ones used in Alice categories\n", "%setp bot master Richard Wallace\n", "%setp bot master Botmaster\n", "%setp bot favoritebook Tale of Two Cities\n", "%setp bot favoritemovie Blade Runner\n", "%setp bot location Moonbase Alpha\n", "# Other bot predicates used in ALICE DB:\n", "# emotions celebrity friend friends size gender age \n", "# kingdom order family genus species" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can inspect the currently defined bot predicates and we will see that they have been defined" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
Bot predicates:
favoritemovie = Blade Runner
location = Moonbase Alpha
master = Botmaster
name = Alice
favoritebook = Tale of Two Cities
" ], "text/plain": [ "Bot predicates:\n", " favoritemovie = Blade Runner\n", " location = Moonbase Alpha\n", " master = Botmaster\n", " name = Alice\n", " favoritebook = Tale of Two Cities\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%show bot" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
The best book I read recently was Tale of Two Cities. Have you read Tale of Two Cities ?
" ], "text/plain": [ "The best book I read recently was Tale of Two Cities. Have you read Tale of Two Cities ?\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "What's your favorite book?" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
And?
" ], "text/plain": [ "And?\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "Not yet" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
My favorite movie is Blade Runner. Have you seen Blade Runner ?
" ], "text/plain": [ "My favorite movie is Blade Runner. Have you seen Blade Runner ?\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "What's your favorite movie?" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
Excuse me!
" ], "text/plain": [ "Excuse me!\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "No" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
The set design.
" ], "text/plain": [ "The set design.\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "What did you like most?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
Session fields:
it = Blade Runner
topic = Blade Runner
" ], "text/plain": [ "Session fields:\n", " it = Blade Runner \n", " topic = Blade Runner \n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%show session" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And the `%bot size` magic shows the number of defined categories" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
Number of loaded categories: 98087
" ], "text/plain": [ "Number of loaded categories: 98087\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%show size" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Saving state\n", "\n", "The predicates that we have defined can be saved to a file by using the `%save` magic" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Saving session predicates... 2 predicates\n", "Saving bot predicates... 5 predicates\n", "Skipping subs\n", "Skipping brain patterns\n", "Writing main bot file: alice-predicates.ini\n" ] } ], "source": [ "%save alice-predicates nobrain nosub rawfiles" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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](03-chatbot-inline.ipynb) for additional examples." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
Version: 1.0 (2016-07-19)
\n", "Author: Paulo Villegas
" ] } ], "metadata": { "kernelspec": { "display_name": "AIML Chatbot", "language": "", "name": "aimlbot" }, "language_info": { "mimetype": "text/xml", "name": "Chatbot" } }, "nbformat": 4, "nbformat_minor": 0 }