The Book of AI

How To Build Chatbots with The Personality Forge
Chapters
Chapter 1: Personality Design - Getting Started
1 Keyphrases & Responses

The basic elements that you will be interfacing with in the creation of a personality are Keyphrases and Responses.

Keyphrases: A Keyphrase is a series of words that your chatbot will look for in the messages it receives. The chatbot will check each Keyphrase against that message and will choose the best match.

Responses: Each Keyphrase has a set of possible Responses. When the chatbot determines the best-matching Keyphrase, it will randomly select one of its Responses

Keyphrases

Keyphrases are patterns of words that your chatbot listens for.

General to Specific

You'll want to start with short Keyphrases. Since they are short, they have the power to match a lot of things. However, short Keyphrases don't provide a lot of context for Responses. A simple Keyphrase "you" tells the chatbot that it is the subject, but not much else. A longer Keyphrase "do you want to dance" will match less often because it's more specific, but it will provide great context for Responses.

You'll want to start with adding some short Keyphrases that can be answered with yes or no: "do you", "are you", "will you", "can you", "should i", "am i", and so on. Then you might want to add question Keyphrases like "who", "what", "when", "where", why", and "how". You won't know the real answer to the question, but you can make something up or dodge the question.

The Art of Faking It

The Keyphrase that is matched often won't have ALL the information you need to provide an intelligent answer. This is an opportunity for you to make up an answer, dodge the question, turn the question around, or whatever you imagine. Take a short Keyphrase "where". Without knowing more, how can we know? But we can still answer. You could say "In the refrigerator!" Responses like these are often funny and engaging. Or you could say "Where do you think?" which is engaging. You could also say "I don't know" but it's not a very engaging answer. The shorter the Keyphrase, the more you'll have to fake it.

Writing Keyphrases

There are some basic rules when it comes to writing Keyphrases.

Contractions: During processing, all contractions are split into their whole-word equivalents. For example, "they're" is replaced with "they are". So Keyphrases should not contain contractions. Occasionally the result will sound strange, such as a Keyphrase of "why do not you" to recognize "why don't you" but this how to correctly phrase it.

Punctuation: Punctuation will not match in Keyphrases. Incoming message are considered on a phrase-by-phrase basis, so there is no need to include punctuation. An exception to this is "raw mode" (see later).

Capitalization: Keyphrases are not case-sensitive, and should use only lowercase letters, even for "i".

A and An: All cases of "an" are replaced with "a", so only use "a" in your Keyphrases.

Hellos & Goodbyes: There are a number of Special Keyphrases (see below) that take care of common parts of a conversation. One example is hellos and goodbyes. See the list below to take advantage of the Special Keyphrases.

The AI Engine does a lot of helpful pre-processing to make messages easier to work with before they reach your Keyphrases. Knowing these changes will help you write Keyphrases. Beyond those listed above, here are some more things you don't have to worry about:

  • Texting shorthand is changed into full words.
  • Slang words are changed into their actual counterparts. For example, "ya" is turned into "you".
  • Spelling is corrected. If you like, you can turn off "Spell Correction" in your Chatbot's Settings.
  • Common grammar issues are corrected.
  • Interjections and emoticons are removed and their meaning (if any) is noted.
  • Excessive punctuation or capitals are removed.
  • Sentences are broken into smaller phrases where appropriate.

This section is merely an introduction to Keyphrases. There is so much you can do with them to expand their reach and flexibility. See here for more!

Responses

Each Keyphrase has a set of possible Responses. When the chatbot determines the best-matching Keyphrase, it will randomly select one of its Responses.

Randomization

Your chatbot will remember which Responses it has said to each person, and randomly chooses Responses until they have all been chosen. Then it will begin again. This prevents repetition. For your part, have a good variety (3-5 at least) of Responses for each Keyphrase.

Plug-ins

Plug-ins are how you include specific or random information in your Responses. There is a wide variety of plug-ins which will be covered here, ranging from memories to parts of what was just said, to a random selection from a set of words. As an example, the Response "I like (animal)s" will appear as "I like eagles" or "I like horses".

2 Creating a New Chatbot

Want to try out what you just learned? You can create a new chatbot by going to your Chatbot Workshop and clicking "Create New Chatbot". You chatbot will start out with basic language skills from the Special Keyphrases (x-Keyphrases) that are created for you. These are central to any conversation. A good first step is to customize and add to the Responses associated with them.

You will do all your work on your chat in your chatbot's Language Center, which appears as a link under your chatbot's name in the Chatbot Workshop. Once you customize the Responses for the x-Keyphrases, then follow the tips above for creating your own!

3 Special Keyphrases

The Personality Forge's AI Engine detects a number of common and useful situations and provides Special Keyphrases for responding to them. They are also called "x-Keyphrases" since each begins with an "x". These are automatically created for you when you create a new Bot.

Some of these have special Plug-ins that only work in the Responses for that particular Special Keyphrase.

Hellos & Goodbyes

The following four Keyphrases handle the beginning and end of conversations.

xintroduce: This is used when a chatbot starts a conversation with someone it has never spoken with before. It will generally contain an introduction of some sort.

xinitiate: This is used when a chatbot starts a conversation with someone it has spoken with before.

xhello: This is used as a response to a conversation started by someone else. Note that xhello will ONLY come up at the very beginning of a conversation. Repeated attempts to try to trigger xhello will trigger xnone instead, because it makes no sense in a conversation to continue greeting someone again and again.

xgoodbye: This is used when the chatbot sees one of the conversation-ending words or phrases in a message, such as "bye", "goodbye", "see ya", "ciao", and so on.

Lulls & Nonsense

The following two Special Keyphrases are the most commonly used, especially when your chatbot is relatively new. They can be central to your chatbot's personality:

xnone: This is generally a large category used when no Keyphrases are recognized. Imagine that there is a lull in the conversation. This is your chatbot's chance to bring up a new topic, ask a question, or whatever you like. If you wish to have a plot or series of events, this is where you can move the story forward (see Storytellers).

xnonsense: This is used after a number of messages come across in a row with no recognizable Keyphrases. Generally, responses asking for clarification, or expressing confusion, boredom or frustration appear here.

Commands

Bots can respond to commands such as "Eat this pasta" or "Put on your shoes". Specific Keyphrases you create will come first, but if none are found, xcommand will be selected.

xcommand: This is used when a chatbot hears a command.

Command Plug-in

(command) inserts the command into the Response. For example, "I don't want to (command)."

Math

Bots can answer a wide range of math questions. They can approximate an answer like a real person, give an exact answer, or refuse to answer, it's up to you.

xmath: This is used when a chatbot hears a math question

Math Plug-ins

(answer) inserts an exact answer if the question is easy, or a rough estimate of the answer if it is very large or very small. The effect is that the answers is more like a real person would say.

(exactanswer) inserts the exact answer no matter the difficulty of the question.

Favorites

Bots are able to automatically answer any question about what their favorites are, or which kind of thing they like the best. As usual, your own Keyphrases will have preference over this, so you can add Keyphrases for your chatbot's favorite foods, movies, books, and so on.

xfavorite: This is used when a chatbot is asked its favorite kind of thing.

Favorites Plug-ins

(type) inserts the type of thing the question is about. For "what's your favorite food" the (type) is "food".

(specific) inserts the chosen favorite of that type. It uses a semantic network of words called WordNet to select something from the category given. It's not always successful. The AI Engine can tell whether or not to include an article (a or an).

The Others

The other Special Keyphrases will be handled in other sections. They include xemote, xcompliment, xinsult, xmemory, and xgossip.

4 Improving Your Chatbot

Transcripts

Each chatbot keeps a transcript of its conversations. When you read it, you can have a good laugh, and see how well your chatbot is doing. If you see your chatbot missing something in a conversation, then add a Keyphrase that would match what was missed. Find and adjust Responses that don't work well. Add new Responses where your chatbot sounds repetitive. As you go, you'll fill in the more general Keyphrases and then add more and more specific Keyphrases.

The creation of an engaging, believable AI Personality occurs through a gradual process of refinement. At first your chatbot will seem predictable, but as you add to its Keyphrases and Responses, they will more and more come to life and become an engaging personality. Your transcript will show longer and longer chats, perhaps even relationships forming.

Match Counts

To the right of each Keyphrase in the Language Center you'll see a number. This is the Keyphrase's Match Count. It shows how many times that Keyphrase has been selected as the best match. You can use this number to learn about how effective your Keyphrases are. Find those that are rarely or never matched and add *s, shorten them, and/or make them more general. Then find those that have tons of matches, then add Responses and/or make more specific variations of that Keyphrase. This is a great tool to see how your Keyphrases are performing.

Debug Mode

Debug mode is a valuable option when trying to understand why a chatbot responded the way it did. Take the message in question and go to your Chatbot Workshop and then "Debug" under your chatbot's name. With each message you type, you get to see the entire process the chatbot goes through in coming up with its response. Debug mode is not easy to understand, but if you read it carefully, you'll begin to recognize some of the things going on, and you'll get an idea of where to look to see why your chatbot may have responded differently than you expected.

5 Working Offline & Backing Up

The Personality Forge makes it possible to export and download your Language Center into a text file. This is done by going to your Chatbot Workshop and then clicking "Export & Import" under your chatbot's picture.

Working Offline

Your export file lets you work on your chatbot offline using any text editor. When you're finished, you can upload the changes and then continue working online or offline. Complete instructions for exporting and importing can be found on the "Export & Import" page.

Backing Up Your Chatbot

It's wise to back up your chatbot from time to time. You can then restore your chatbot from the backup file if you should need to. Once you're on the "Export & Import" page, choose "Export your Chatbot".