Stories on maker education and innovation 

Home creativity Learn to Build Your Own Conversational Bot using ChatScript
formats

Learn to Build Your Own Conversational Bot using ChatScript

Science fiction (i.e. Star Trek and Star Wars) paint a vision of the future where people can simply use conversational language to interact with their robots and computers.   In the future, conversation will become a first class user interface like the keyboard, the mouse, and touch screens.    Bruce Wilcox has made a powerful contribution to natural language processing and chatbots by creating ChatScript.  His work has won in the Loebner Prize Contest in 2010, 2011, and 2012.   I wanted to provide a high level introduction into this smart and insightful chatbot engine.    This is a true gem of the open source world.

Download ChatScript for SourceForge.NET

  • Open your web browser to http://sourceforge.net/projects/chatscript/ .
  • Click to the ‘download’ button.
  • After the ChatScript ZIP has completed downloading, unzip the file to a location on your hard drive.   (i.e. c:\chatscript or /home/user/chatscript).   We will refer to this location as your ChatScript home directory.

Test drive ChatScript

  • Open your ChatScript home directory.
  • Run ‘ChatScript.EXE’ (or LinuxChatScript32)
  • After ChatScript loads and you have provided your name, you will have the opportunity to chat with the small chatbot installed by default in ChatScript.
  • In the ChatScript home folder, open the ‘documentation’ folder to learn how ChatScript functions.   Bruce Wilcox and his team have provided a nice set of user guides to help you understand the language and process of creating a chatbot.   I highly recommend checking out the “ChatScript Tutorial.pdf” and “Paper- ARBOR-MakingItReal.pdf.”

Let’s add some personality

  • Open your ChatScript home directory.
  • Copy “Files1.txt” to “Files2.txt.”  “Files2.txt” will contain the topic files (i.e. “.top” files) that your personality will load.
  • Using your favorite text editor, we need to add a line to enable a new topic file.   We will also need to disable the “simpletopic” file.   Edit “files2.txt” so it looks exactly like the following.     Save your changes and close your text editor.

ChatScript File2

  • Open your ChatScript home folder.
  • Open the “RAWDATA” folder.
  • In this folder, create a file called “tutorial.top.”

cs helloworld

  • Open your ChatScript home folder.
  • Run ChatScript.EXE.  After the user provides their name, the user is greated with “Hello world.”

cs helloworld results

ChatScript enables you to organize your chatbot brain into conversation topics.     As you probably guessed, the first line of the script is associated with introductions.   Refer to the “ChatScript Tutorial.pdf” documentation for additional details.

Creating a virtual waiter

Let’s say we needed to program ChatScript to manage the process of ordering breakfast for a user.   Yum! What would this look like in ChatScript?   If you skim through the code below, you can probably understand the logical progression of the conversation.  I believe this is a major strength of ChatScript over alternatives.

Modify the “tutorial.top” file with the following code snippet.   To reload the ChatScript brain, type “:build 2” at the ChatScript prompt to reload the system.

topic: ~introductions keep repeat[]

t: keep() repeat() Hello! How are you? Welcome to Big Joe's Breakfast.  Can I start you off with something to drink?
	a: (~yes) What can I get you to drink?
		b: (*) Ok.  I'll get you your drink order. And I'll come back to take your breakfast order. ^reuse(READY_TO_ORDER)

	a: (~no) Ok. ^reuse(READY_TO_ORDER)

t: READY_TO_ORDER() keep() repeat() Are you ready to order?
	a: (~yes) Ok.   Do you like meat?
		b: (~yes) You might enjoy trying the green eggs and ham.
		b: (~no) You might enjoy trying our veggie omlette.  It's very good.

	a: (~no) I will be back shortly to take your order.

The following shows a sample Chat session using this script.

cs_waiter

  • t: keep() repeat() Hello! How are you? Welcome to Big Joe’s Breakfast.  Can I start you off with something to drink?
    • This line is a topic rule or gambit. (denoted by the “t:”)   Topic lines are executed from top to bottom so that chatbot creators can craft stories.  Topics are initiated by the bot when the system starts or the bot needs to shift the direction of conversation.
    • a: (~yes) What can I get you to drink?” – When the user wants something to drink. This rule will be triggered.   The “(~yes)” code will get triggered when the system encounters any form of an affirmative response.   In more technical terms, ChatScript will trigger this rule when the concept of “yes” is encountered.  While other chatbot frameworks pattern match on strings or text, ChatScript pattern matches on concepts.
    • a: (~no) Ok. ^reuse(READY_TO_ORDER) – This rule will reply “Ok” to the user and direct the system to trigger the “READY_TO_ORDER” rule.
  • t: READY_TO_ORDER() keep() repeat() Are you ready to order?
    • This topic rule is named “READY_TO_ORDER.”  The bot simply asks the question “Are you ready to order?”

Reflections on ChatScript

  • I really love the “concepts” feature of the language.   It’s really cool that the system knows that “I do!” and “I think so” means “yes.”
  • To prepare this small ChatScript code sample, I had to craft a focused story before designing my code.  I believe it would be interesting to introduce this technology to high school or college students interested in creative writing or drama.  Why?  The craft of designing the chatbot is like writing a scene from a play.

 “While ChatScript is a marvelous tool, it is not a chatbot. For that you need the script itself. And to write that script you need to define a personality, much as a novelist crafts a character. Who is the chatbot? What do they do? Who are their friends? What is their life story? We want to create a consistent being with a logical set of interests and intentions living in a rational world. The more a user can model the character’s personality, the more engrossed the user can become in the reality of a fictitious world.”
Bruce and Sue Wilcox – “Making it Real: Loebner-winning Chatbot Design”

  •  I would encourage the reader to explore the documentation for ChatScript.  This blog post only scratches the surface of the rich capabilities of the language.  In future work, we hope to create media to make ChatScript accessible to younger audiences and inspire the next generation of AI professionals.
  • Special thanks to Bruce and Sue Wilcox for creating such an amazing contribution to natural language processing.
  •  

    Photo from http://www.flickr.com/photos/edlitmus/4784371536/sizes/m/in/photostream/

     

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
© Inspired To Educate
credit