How To Build Chatbots

on 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 shorter 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 are" tells the chatbot that it is something, but not much else. A longer Keyphrase like "you are my hero" will match less often because it's more specific, but it will provide great context and you can write more specific Responses.

You'll want to start with adding some short Keyphrases that can be answered with yes or no. 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

When a Keyphrase is matched, you may not 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. For more, see Writing Good Responses.

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" (an advanced topic).

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.

When creating a chatbot, you can choose to link it to a Chatbot Template, which links thousands of well-constructed and useful Keyphrases to your chatbot, providing a powerful starting point for writing your chatbot. It's recommended that if you choose to do this, read through Chapter 4: Macros so you understand more about how Keyphrases and Macros work.

You will do all your work on your chatbot in your its Language Center, which appears as a link under your chatbot's name in the Chatbot Workshop. Once you customize the Responses for the Special 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. Special Keyphrases all start with a #. These are automatically created for you when you create a new Chatbot.

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.

#introduce: 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.

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

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

#goodbye: 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:

#engage: 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).

#nonsense: 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, #command will be selected.

#command: 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.

#math: 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. They will choose a random answer that fits the question. 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.

#favorite: 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 a random thing of the above type. It uses a semantic network of words to randomly select something from the category given. The AI Engine can tell whether or not to include an article (a or an).

Repetition

Chatbots can respond to someone repeating the same thing to them.

#repeat: This is used when the same thing is repeated to a chatbot.

Repetition Plug-ins

(mylastmessage) inserts the last thing your chatbot said.

The Others

The other Special Keyphrases will be handled in other sections. They include #emote, #compliment, #insult, #memory, #repeat, and #gossip.

4 Improving Your Chatbot

The Guide

At the top of the Language Center is a Guide to developing your chatbot. It will provide guidance on what to work on next. If your bot is linked to the Master Bot Template, it will walk you through Keyphrases to write Responses for, and award Bot Levels as you progress.

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

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".