How To Build Chatbots
- 1. Getting Started
- 2. Bot Settings
- 3. Expanding on Keyphrases
- Wildcards in Keyphrases
- The AI Engine
- 4. Keyphrase Macros
- 5. Writing Good Keyphrases
- 6. Plug-ins for Responses
- 7. Writing Good Responses
- 8. The Seek System
- 9. Keyphrase Rank
- 10. AIScript
- 11. Memories
- 12. AI Emotions
- 13. Conditional Responses
- 14. More Useful AIScript
- 15. Other Keyphrases
- 16. Robotics & The API
- 17. Future Advances
Wildcards are placeholders in Keyphrases that match certain kinds of things. They are essential to writing good Keyphrases as they expand the reach of what is matched.
What if you have the Keyphrase "i like" but you'd also like it to also match "i really like"? You need the * wildcard. It will match anything or nothing. To use it, write your Keyphrase like this: "i * like". This is called a soft wildcard, because it's optional. The soft wildcard is essential in extending the reach of your Keyphrases, and should be used liberally when writing them. Before saving, read through your Keyphrase and imagine anyplace where the word "really" or "big" could fit, and put a * there.
* matches anything or nothingKeyphrase: do you * like
Matches: do you like, do you really like
But wait, "i * like" also matches "i look like a monkey", which should have different Responses. In that case, you can use the (r) wildcard, which matches adverbs or nothing. Adverbs are words that describe actions or adjectives. Examples: "really", "quickly", and "usually".
(r) matches adverbs or nothingKeyphrase: do you (r) like
Matches: do you like, do you really like
But what about words that reverse the meaning like "not", "never", and "rarely"? You wouldn't want the Keyphrase "i * want to eat" to match "I do not want to eat". Not to worry! The AI Engine prevents * and (r) from matching words like these.
Keyphrases can use single and multi-word wildcards for particular types of words or groups of words. For example, the Keyphrase "you are (adjective)" will match "You are silly" and "You are brilliant", but not "You are a horse". These are very powerful wildcards and do wonders in nailing down the particular type of sentences you want your Keyphrases to match. Unless otherwise stated, all wildcards must match something (they are not optional matches).
Remember learning about verbs, nouns, prepositions, and pronouns in school? These word types are how we match the parts of sentences.
Word Phrase Wildcards
These are the most useful word type wildcards, as they cover all sorts of forms of the kind of thing you are probably looking for. (np) and (vp) are the best to use in most situations.
(np) stands for noun phrase, which matches a thing or person. It's any series of adjectives, articles, nouns, pronouns, and prepositions.
Matches: the big wet dog by the door, my filthy hand on the table, a pumpkin of doom
Less common variations:
(adjartnoun) - any series of adjectives, determiners, nouns, and pronouns.
Matches: the big wet dog, my filthy hand, a pumpkin
(adjnoun) - any series of adjectives and nouns.
Matches: big wet dog, filthy head, pumpkin
(prenoun) - an OPTIONAL match for things that may precede a noun: adjectives, determiners, and other nouns.
Matches: big wet, filthy
(vp) stands for verb phrase, which matches an action; any series of verbs, adverbs, and prepositions.
Matches: ran very quickly over, snorted loudly, fall down suddenly
Less common variation:
(verbadv) - any series of verbs and adverbs.
Matches: ran very quickly, snorted loudly, fall
Single Word Type Wildcards
These are less-commonly used wildcards. Most often you'll be trying to match (np) and (vp), but there are times when you might want to use one of the following:
(noun) - a single noun.
Matches: book, pies, monkey
(verb) - a single verb.
Matches: run, thinking, gargle
(adj) - a single adjective.
Matches: silly, yellow, grunting
(adv) - a single adverb.
Matches: swiftly, loudly, really
(prep) - a single preposition.
Matches: under, against, between
(det) - a single determiner.
Matches: a, an, the, my, your
(name) - a single name.
Matches: Benji, Josephine, Gwendolyn, Bruce
(number) - a single number.
Matches: 14, twenty-one, 42
Inflected Word Type Wildcards
You can also specify the inflection of the word you want to match - for example, you could match only plural noun phrases or only past tense verb phrases.
nouns: -s for plural, _ for singular
Examples: (np_), (np-s)
verbs: _ for base, -s for third person, -ing for active, -ed for past
Examples: (vp_), (vp-s), (vp-ing), (vp-ed)
adjectives: _ for base, -er for more, -est for most
Examples: (adj_), (adj-er), (adj-est)
This is quite useful. For example, there's a big difference between "i am (vp-ing)" which means you're doing something, and "i am (vp-ed)", which means something was done to you. Limiting the Keyphrase to the right inflections can lead to better Responses. Consider "i like (np)" - that (np) could be singular like "my dog" or plural like "all dogs". With a Keyphrase of "i like (np-s)" you could reply with "Even (adj-neg) ones?"
You can also list words or phrases in parenthesis separated by the vertical line "|" character. The AI Engine will match any one item in the list. You can also put word-list wildcards inside other word-list wildcards.
Keyphrase: are you a (guy|man|dude|boy|male)
Matches: are you a guy, are you a man, are you a dude
Keyphrase: i (desire|want|yearn for) you
Matches: I desire you, I want you, I yearn for you
Keyphrase: can we * ((talk|chat|speak) * about|discuss) (np)
Matches: can we discuss the moon, can we please talk about bikes
Optional Word Lists
You can also specify optional word lists in your Keyphrases. Essentially, you create a list like above with the last element being blank. It matches a word in the list or nothing. Why use these instead of *? These are good if you want to narrow down the things that could match. They also increase your Keyphrase's Rank when matched.
Keyphrase: i am (adj) (that|) you
Matches: I am glad you like worms, I am happy that you are coming home.
Keyphrase: i am (adj) (when|because|that|) you
Matches: I am glad you like worms, I am happy that you are coming home, I am pleased because you are hilarious.
Hard wildcards (*) match anything, as long as there is something there. They can match one or more words. This is less useful than the word type wildcards above, so use those instead when possible. But on the rare occasion, a hard wildcard is called for.
Keyphrase: i know (*)
Matches: "I know Desti.", but does NOT match "I know."
You can match the beginning and end of phrases (sentences or parts of sentences separated by commas) with these. You should use them rarely - only when leaving them off would change the meaning.
^ matches the beginning of a phrase or sentenceKeyphrase: ^(do|did|are|were) you
Matches: "did you go" but not "where did you go"
$ matches the endKeyphrase: (do|can) you * think$
Matches: "do you think" but not "do you think cats are funny"
Both:Keyphrase: ^(vp) (np)$
Matches: "eat this peach" but not "could you eat this peach tomorrow"
There are a lot of built-in Word Wildcards you can use. These are essentially a list of synonyms of each word. If you find you're using one of the following words in a Keyphrase, replace it with the Word Wildcard below.
(a:about), (a:actual), (a:actually), (a:afraid), (a:again), (a:almost), (a:also), (a:always), (a:angry), (a:annoying), (a:attractive), (a:bad), (a:barely), (a:big), (a:certain), (a:certainly), (a:clear), (a:clearly), (a:crazy), (a:currently), (a:dangerous), (a:difficult), (a:disgusting), (a:drunk), (a:easy), (a:eventually), (a:exactly), (a:excited), (a:fat), (a:fascinated), (a:fun), (a:funny), (a:good), (a:great), (a:happy), (a:important), (a:interesting), (a:just), (a:kind), (a:lame), (a:later), (a:lonely), (a:lots), (a:many), (a:mean), (a:much), (a:okay), (a:often), (a:pretty), (a:profound), (a:quickly), (a:rarely), (a:right), (a:rude), (a:sad), (a:scary), (a:sick), (a:skilled), (a:small), (a:smart), (a:snippy), (a:some), (a:somewhat), (a:sometimes), (a:soon), (a:strange), (a:stupid), (a:surprised), (a:surprising), (a:tasty), (a:tired), (a:thankful), (a:the_hell), (a:the_most), (a:too), (a:total), (a:totally), (a:troubled), (a:typical), (a:ugly), (a:very), (a:what), (a:worried), (a:wrong)
(v:accompany), (v:avoid), (v:avoiding), (v:blame), (v:bother), (v:bothers), (v:bothered), (v:bothering), (v:buy), (v:buying), (v:choose), (v:chosen), (v:choosing), (v:consider), (v:considered), (v:considering), (v:consult), (v:consulted), (v:consulting), (v:create), (v:creates), (v:creating), (v:created), (v:die), (v:died), (v:dying), (v:disrespect), (v:disrespecting), (v:fart), (v:farts), (v:farting), (v:fool), (v:fooled), (v:get), (v:getting), (v:got), (v:guess), (v:guessed), (v:guessing), (v:had), (v:has), (v:has_to), (v:hate), (v:hates), (v:hated), (v:hating), (v:hate_to), (v:hates_to), (v:have), (v:having), (v:have_to), (v:have_fun), (v:having_to), (v:having_fun), (v:had_to), (v:help), (v:helping), (v:joking), (v:kill), (v:killed), (v:leave), (v:leaving), (v:left), (v:like), (v:likes), (v:liked), (v:liking), (v:like_to), (v:likes_to), (v:live), (v:mocked), (v:mocking), (v:pee), (v:peed), (v:poop), (v:pooped), (v:recommend), (v:scare), (v:scares), (v:scaring), (v:seem), (v:seems), (v:seemed), (v:seeming), (v:stop), (v:stops), (v:stopped), (v:suck), (v:sucks), (v:surprise), (v:surprises), (v:talk), (v:talks), (v:talked), (v:talking), (v:teach), (v:teaching), (v:think), (v:thinks), (v:thinking), (v:thought), (v:want), (v:wants), (v:wanted), (v:wanting), (v:want_to), (v:wants_to), (v:wanted_to), (v:wanting_to)
(n:anyone), (n:botmaster), (n:boyfriend), (n:cat), (n:cats), (n:chat), (n:chatbot), (n:chatbots), (n:child), (n:children), (n:coward), (n:dad), (n:darling), (n:dog), (n:dogs), (n:female), (n:females), (n:friend), (n:friends), (n:fun), (n:garbage), (n:girlfriend), (n:group), (n:groups), (n:help), (n:homosexual), (n:house), (n:humans), (n:idiot), (n:jerk), (n:jerks), (n:kindness), (n:lies), (n:lover), (n:lovers), (n:male), (n:males), (n:many), (n:mom), (n:parent), (n:pet), (n:ruler), (n:smell), (n:some), (n:suggestion), (n:the_future), (n:trouble), (n:type), (n:types), (n:we)
What if you want a much longer list of options? It would be too much for you to type into a single Keyphrase. You can use the Personality Forge's Custom Plug-ins for this. Custom Plug-ins in Keyphrases match any one of the items listed. These lists can be created by you or shared by others. You can see the available ones on the Plug-ins page.
Keyphrase: i (vp) (p:park)
Matches: I've been to Yosemite, I enjoy seeing Yellowstone
Keyphrase: (p:badweather) * coming
Matches: There is a thunderstorm coming, I think a typhoon is coming
Here are some that are very useful in Keyphrases:
(p:person-key) any type of person, such as "teacher" or "highlander".(p:adj-pos) a positive adjective, such as "funny" or "dashing".
(p:person-positive) a positive person, such as "hero" or "prodigy".
(p:person-negative) a negative person, such as "jerk" or "degenerate".
(p:person-crazy) a crazy person, such as "loony" or "weirdo".
(p:adj-neg) a negative adjective, such as "smelly" or "vile".
(p:adj-amp) a crazy adjective, such as "bonkers" or "maniacal".
(p:quality-positive) a positive quality, such as "bravery" or "ingenuity".
(p:quality-negative) a negative quality, such as "vileness" or "negativity".
(p:quality-crazy) a crazy quality, such as "bizarreness" or "quirkiness".
(p:verb-action-pos) a positive verb, such as "like" or "miss".
(p:verb-action-neg) a negative verb, such as "dislike" or "blame".
(p:verb-effect-pos) a positive feeling verb, such as "inspire" or "impress".
(p:verb-effect-neg) a negative feeling verb, such as "upset" or "bother".
There are thousands more on the Plug-ins page.
You can use memories as wildcards in Keyphrases, too. For more visit Memories in Keyphrases.
There's a shortcut if you want to match different inflections of single words or lists of words. They're called Wildcard Inflectors. You begin with word bases, then add a marker for what inflections you also want to match. For nouns, you can use +s to match plural tense. For verbs, you can use +s to match third person tense, +ed to match past tense, and +ing to match continuous tense. For adjectives, you can use +er and +est. These can be added to the end of single words, Word List Wildcards, and Plugin-in Wildcards.
Keyphrase: what * rhyme+s with (*)
Matches: What words rhyme with possum, What rhymes with possum
Keyphrase: tell me your * reason+s+ing
Matches: Tell me your reason, Tell me your reasons, Tell me your reasoning
Keyphrase: (is|does) (np) * (like|love|enjoy)+ing (np)
Matches: Is the boar enjoying my song? Does your sister like thunderstorms?
Keyphrase: are you * (hungry|thirsty)+er+est
Matches: Are you feeling thirsty? Are you hungrier than before?
If you want to match laughter: ROFL, LOL, hahaha, etc., then create the Keyphrase "haha".
All of these can be put together to match many ways of saying something.
- (do you (r) (v:want)|would you (r) (v:like)) * (p:food-drink)
- have you (ever|) (gone to|been to|visited) (np)
- what * (do you (r) (v:have)|have you (r) got)
- we (r) are (r) (going|heading|leaving|off) (to|for) ((go|head) (r) to|) (np)
The flexibility and reach of our Keyphrases are expanding. However, they can get a little hard to read. In the next section on macros, you can see how to simplify these while expanding their reach even further.
If you want more than one Keyphrase with different structures to trigger the same set of Responses, you can list them as a single Keyphrase. In the Language Center, this can be done either by putting one Keyphrase per line or separating them by commas. In export files, you must use the comma format. Following is an example of a single Keyphrase entry as a list of Keyphrases.
let us * ((talk|chat|speak) * about|discuss) (np),
(talk|chat|speak) * (to|with) me * about (np),
(do you * want|would you * like) * to * ((talk|chat|speak) * about|discuss) (np)
An incredibly powerful and engaging aspect of Keyphrases is the ability for your chatbot to return phrases and topics said to them in their Responses. This is accomplished through Keys. Each wildcard in a matched Keyphrase automatically produces a Key, which are Plug-ins you can use in your Responses. This only applies to the outer level. Wildcards inside other wildcards do not produce keys.
Keyphrase: (do you * want|would you * like) * to * ((talk|chat|speak) * about|discuss) (np)
Key Contents (key1) (do you * want|would you * like) (key2) * (key3) * (key4) ((talk|chat|speak) * about|discuss) (key5) (np)
But what if I update my Keyphrase? Do I have to change all the Key numbers in my responses? What if I have multiple Keyphrases listed and the keys don't line up? Key Mapping to the rescue!
Key Mapping lets you set your own keys in whatever order you want. And better yet - you only need to set the ones you want to use! Starting with 1, you add :1 to the end of they key, and that produces (key1).
Most likely we're only interested in using the noun phrase (np), so we write:
(do you * want|would you * like) * to * ((talk|chat) * about|discuss) (np:1)
Key Contents (key1) (np)
(name:1) * is * my (np:2),
my (np:2) * is * (name:1),
i * have a (np:2) * named (name:1)
Key Contents (key1) (name) (key2) (np)
There are two more Keys generated with each Keyphrase match.
(prekey): the part of the sentence BEFORE the matched Keyphrase.
(postkey): the part of the sentence AFTER the matched Keyphrase.
The AI Engine does a lot of things to help your Keyphrases match what you intend them to, meaning there's less work for you when writing your Keyphrases.
MetaMacros take complex sentence formations and reduce them to simpler statements.
Message: I think that you are amazing.
Becomes: You are amazing.
Message: I was wondering if you knew what clouds are made of.
Becomes: What are clouds made of?
Message: Do you have any idea why the badger took the blade?
Becomes: Why did the badger take the blade?
Message: What I need is for you to bring me the cheese.
Becomes: Bring me the cheese.
Message: Would you happen to recall what kind of sandwich it was?
Becomes: What kind of sandwich was it?
There are over 800 different sentence structures (and growing) that the AI Engine can reduce like this, meaning you don't need to write Keyphrases for every conceivable way of saying things - just the more essential ones.
Message: Do you have any idea why the badger took the blade?
Keyphrase: why * did (np:1) (vp:2)
Thanks to Meta Macros, this Keyphrase will match (see example above).
Now if you want to match something in the original message, you still can. The original message is looked at as well when deciding which of your Keyphrases fits best.
Message: I think that you are amazing.
Keyphrase 1: you * are (adj:1)
Keyphrase 2: i * think * you * are (adj:1)
Since the original message is also searched, Keyphrase 2 will be selected since it is a longer match.
The opposite of Meta Macros is Answer Restructuring. It takes a short answer to a question, and turns it into a full statement.
Chatbot: What kind of music do you like?
Person: Silly children's music.
Becomes: I like silly children's music
Chatbot: What should I do if the moon explodes?
Person: Close your eyes.
Becomes: You should close your eyes if the moon explodes.
Chatbot: Where is the pants festival?
Person: At my house.
Becomes: The pants festival is at my house.
These full sentences are easier for your Keyphrases to match. You'll see that these can also save you a lot of work when it comes to writing Seeks, as your Keyphrases may be able to pick up the answer when it's formed into a full sentence. Speaking of Seeks, look at one more example:
Chatbot: Do you like kittens?
Person: Of course!
Becomes: Of course! I like kittens.
With yes/no questions, the original response is also kept. So not only will it match any "yes" Seek you may have, but it will also match any Keyphrase that would match "I like kittens."
The AI Engine simplifies matching numbers for you. All numeric words are translated to numbers. Take the number 36. It can be written 36, thirty six, or thirty-six. In your Keyphrase, you only need to match the number 36. If you like, you can also words for numbers from "zero" up to "nineteen" and they will still match numbers.