How To Build Chatbots

on The Personality Forge
Chapters
Chapter 5: Writing Good Keyphrases
1 Evolving Keyphrases

NOTE: This requires a working knowledge of Keyphrases in How To Build Chatbots. If you haven't read through that yet, start there. This is a section inside it.

Let's walk through the evolution of a Keyphrase. A common question someone might ask your chatbot is if they like something. So to respond to that, you write the following keyphrase:

do you like

This is a good start but is very limited - it wouldn't match "do you really like" or "do you actually like". So let's add a soft wildcard in there. A soft wildcard can match anything or nothing.

do you * like

That's a little better, but a soft wildcard can match anything. So while it works with the above options, this would also match "do you have a dog like mine" as well, and your responses wouldn't make sense for that. So let's limit what can appear there to word types that appear before verbs with (r).

do you (r) like

Great - now we've expanded the reach of our Keyphrase without expanding it too far. As you look through your chatbot's transcripts, you see that it's catching too many things. It matches "what do you like" and "do you really like to surf". Since we want this Keyphrase to be about things your chatbot likes, let's add a (np) to the end - making sure that what follows is a noun phrase.

do you (r) like (np)

Better! Your Keyphrase is working a lot better now. So it's working fine, but you notice the Keyphrase isn't matched when someone writes "do you enjoy ice cream". That's right, "enjoy" is another word for "like". So let's add that as an option.

do you (r) (like|enjoy) (np)

Now your Keyphrase will match "like" or "enjoy" in that position. But wait - you notice another one it misses: "do you love ice cream". There's probably a lot of words that can fit there. Luckily, there's a Word-Type Plugin for "like" that you can use to match them all. Let's replace (like|enjoy) with that.

do you (r) (v:like) (np)

It's working even better now. But then you see another way to ask if your chatbot likes something: "Are you a fan of ice cream". How to you also catch a whole lot of different phrasings of the same question? You could write a Keyphrase list with all the options you could think of, or better yet, you could use a macro, which will cover them all at once.

(m:do_you_like) (np)

That's it! Your Keyphrase has maximum reach without matching anything it shouldn't. And best of all, it's short and easy to read.

Macros & Modern Keyphrases

If you want to get a good idea of what Macros and Modern Keyphrases look like, take a look at the Master Bot Template.

2 Common Mistakes

There is an art to writing good Kephrases. By this I mean flexible, useful, successful Keyphrases that will match all the versions of what you're looking for without matching too much. Here are some examples of Keyphrases with problems and how to improve them:

Too Long

Keyphrase: i once knew a (np:1) that (vp:2) (np:3) on (his|her|its) (adj:4) (np:5)

This will likely never match, because it's too long. How often will someone say something that matches this? Probably never. So let's shorten it. We'll remove the end, which could be accessed by (postkey) if there's something there. Let's remove the "a" so that the (np) could also match words like "three" or "several":

Improved: i (r) once (r) knew (np:1) that (r) could (vp:2) (np:3)

Too Specific

Keyphrase: the wild dogs took my pajamas then ate them

This is too specific. Nobody is likely to say that exact phrase. So let's make it more general. Unless "wild dogs" or "pajamas" are something brough up by the chatbot, let's make them into (np) so they can match all kinds of things.

Improved: (np:1) (r) took my (np:2)

Lacking Context

Keyphrase: pants

Sure, your Bot could respond with something general about pants, but a person would feel like your chatbot didn't understand what was said to it. This word could be part of many different kinds of questions or statements. If "pants" is a topic raised by your Bot, it'd be better to write Keyphrases with some context:

Improved: where are (prenoun) pants
Improved: i (r) (v:like) (prenoun) pants
Improved: pants are (r) (a:great|a:attractive|stylish)
Improved: i (r) (v:hate) (prenoun) pants

Contains Punctuation

Keyphrase: i'm ready!

Every contraction in incoming messages is separated into individual words for the Keyphrase to match. "I'm" becomes "I am". "you're" becomes "you are". So ensure your Keyphrase is written without contractions or other punctuation.

Improved: i am ready

Spelling or Grammar Errors

Keyphrase: ur soo kewl
Keyphrase: your funny

Common misspellings and slang is corrected in incoming messages. Putting them in the Keyphrase will not match except in raw mode. One of the most common mistakes is confusing "your" which means "you possess something" and "you're" which means "you are".

Improved: you * are * cool
Improved: you * are * funny

Unnecessary Rank

Typically you should almost never have to adjust a Keyphrase's rank. The AI Engine takes care of finding the best, most appropriate match. Learn more about rank