Dealing With Off Topic Input

Steve Worswick
Sep 5, 2019 · 9 min read

Picture the scene: you’ve made an awesome chatbot that can order train tickets for users. It knows all there is to know about departure and arrival times, the various prices of different tickets, the facilities in each station and yes, even what’s being served in the onboard cafe. You put it online and the first thing it gets asked is, “What’s your favorite pizza topping?” ARGH!!!

It’s a big problem for chatbots, especially when the vast majority of users have little idea as to the current state of technology. They see the word “chatbot” and (not unreasonably) expect to be able to chat to it, as though it was something like C3PO from Star Wars. In fact, you’ll find that around 20–30% of the input you receive will be off topic.

How do we deal with off topic messages

Here at Pandorabots, we’ve seen the same thing happen to the sales chatbot on our home page. It’s designed to tell you about our services, what Pandorabots is, and allow users to book appointments with our sales team among other things but it gets asked all kinds of things from relationship advice to weight loss tips!

To deal with the off topic inputs, we networked the sales chatbot with our award-winning Mitsuku chatbot so we can pass any unrelated chitchat messages to Mitsuku to provide a suitable answer instead of a “does not compute!” message. Pandorabots supports bot-to-bot communication (via the <sraix> tag) and preserving context by passing a topic between bots. This means that a user who has wandered off-topic for a given number of turns (which can be customized via a parameter) can be prompted to continue the conversation based on whatever goal your bot was designed to accomplish like, for example, booking an appointment with Sales.

You can do this yourself with your own off topic bots or alternatively you can license the chitchat module version of Mitsuku to handle off topic messages for you. Details of the Mitsuku Module can be found by clicking here.

How to do it

This can be applied to your own Pandorabot but I’ll demonstrate how we connected our sales bot to Mitsuku. Please feel free to use this example as a guide to doing it in your own bots.

First, we need to tell the sales bot how to to access Mitsuku. Go to your Pandorabots dashboard and navigate to your system properties, as in the image below.

We add a new property called mitsukumodule, with the App ID and botname of the off topic handling bot. Your App ID can be found by opening your Account Page from the icon in the top right of the screen and opening the API Settings tab.

Your App ID will be something like un1234abcd. This, along with your off topic bot’s name, should be added as a new property, as in the example above. If you are using our Mitsuku Module, these details will be provided for you. We’ve called the property mitsukumodule but obviously you should rename this to whatever makes more sense to you.

Creating the AIML

How can we tell if something is said to the sales bot that is off topic? Simple, if an AIML bot doesn’t understand the user’s input, the UDC (Ultimate Default Category) is triggered. This consists of a pattern of a single star wildcard like below.

If the user types something the bot can’t handle, it provides a default response. However, we want to pass any of these inputs to Mitsuku, using AIML’s <sraix> tag. We called our property mitsukumodule, so we change our UDC to look like this.

The <denormalize> part of the template lets us pass the user input to Mitsuku without altering it. Simply put, if a user says, “r u a robot”, we may have a normal.substitution file that would convert this to “are you a robot” before allowing our bot to process it. As we are allowing Mitsuku to handle this query, we send it unaltered.

So now instead of the “Sorry. I don’t understand what you are saying.” message, Mitsuku will reply with something more appropriate.

Republish your bot and that’s it! If anyone asks our sales bot what the capital of Norway is, rather than giving a generic huh? type message, it will ask Mitsuku, respond with the answer and create a seamless experience for the user.

Oh ok. That was easy

This worked really well but raised another important issue. People enjoyed the responses Mitsuku gave and were spending more time in off topic conversation, so the poor old sales bot got very little action at all.

To combat this, we set up the sales bot so that it would pass 3 off topic interactions to Mitsuku and then prompt the user to get back on track.

Amending the Code

To do this, we need to set up a new system property, exactly the same as we did with the mitsukumodule property. As it’s the limit of <sraix> tags we want to allow, let’s call it sraixcount. As you can see, we’ve set it to 3 but you can amend this to however many you wish, as long as it’s 1 or above.

We also need to keep a running total of how many off topic queries we’ve received to check if we’ve reached this total. We can do this with a predicate called offtopic. Finally, the bot needs to remember at what point the user went off topic so it can bring them back on track, as it would be frustrating for the user to have to start the bot’s script right from the beginning again. We’ll call this predicate subject, as it was the subject the bot was discussing before the user went off topic.

Assuming, you’ve built your bot in a fairly standard way, you’ll have a few main categories to deal with high level requirements such as ordering, payment, product information and then lots of other categories that <srai> to these. These main categories are often known as intents.

For example, we have a category called DASHBOARDACCESS in our sales bot which allows the user to open their dashboard. We also have other categories that <srai> to this main category with patterns such as:
# OPEN # DASHBOARD #
# LOG IN #
etc

We need to amend the intent categories to include a subject line and to reset the off topic counter back to 1, as the user is now on topic. Here’s our DASHBOARDACCESS category to give you an example.

This template displays a button that the user can click on to access their dashboard. You don’t need to worry about most of this category but you can see that we have reset the offtopic predicate and also included a subject predicate to give a brief description of what this category does. So if you have a category called HowToUseThis, your subject line could be something like, “how to use our service”. You get the idea? Do this for all your intents.

Amending the UDC

We need to amend our UDC, so it checks how many times the user has gone off topic and if it’s reached the limit, to guide the user back on track. If it’s not reached the limit, it should pass the input to Mitsuku and increase the offtopic counter. Here’s how we do this:

Let’s break it down. First we check the value of the offtopic predicate. It can either have reached the sraixcount limit, have an unknown value or have a value that is less than sraixcount.

1 — If offtopic is the same as sraixcount, Mitsuku is allowed to answer one last time and then the sales bot asks if the user wants to get back on topic using two new categories which we’ll discuss in a moment.

2 — If offtopic is unknown, perhaps if the user has just started the script or if something has gone wrong, we set the value to 1 and start the bot script from the start. We have a category called BeginWidgetBot that starts the script but you should change this to your own initial category.

3 — Otherwise if offtopic is neither of these, we pass the input to Mitsuku to handle and increase the offtopic counter by 1 using the inbuilt map called successor, which maps any number to the one above it: 2 to 3, 45 to 46 etc

Categories to get back on topic

To make things easier to manage, we create an extra category called MitsukuSRAIX to activate Mitsuku and a category called BackOnTopic which prompts the user to continue the conversation. These are below:

BackOnTopic offers two options. You can either start the bot from the main menu or carry on from where you left the main bot. Remember, we amended our intent categories to include a subject line? This is where it gets used. Assuming the user went off topic in the DASHBOARDACCESS category, the bot will prompt the user with a message of “Shall we get back on topic? We were talking about accessing the dashboard.”

These next categories are triggered if a positive response is given by the user.

If the user says something other than these, the bot assumes they want to stay off topic and passes the inputs to Mitsuku again. However, if the user wants to get back on topic, a category called ContinueConversation is called, which figures out where in the sales bot we were and continues from there. Here is an extract:

In this category, we reset the offtopic counter to 1, as we are now back on topic. The bot then checks the value of the subject line and triggers the appropriate category. The last <li> is a catchall just in case there is no subject line. In this case, the bot will start from the beginning of its script.

This is now working. The user can chat with the sales bot and if the sales bot doesn’t understand something, it asks Mitsuku to reply instead. Once Mitsuku has replied 3 times, the sales bot decides it wants some of the action and asks the user if he wants to get back on topic. The user can then either continue talking to Mitsuku or go back to the sales bot

Anything else?

The user might want to get back to the sales bot without having to wait to say something off topic 3 times. To do this, we can create a few categories like below to return to the original bot.

If the user says one of the keywords, the sales bot assumes he wants to get back on track and displays the “Shall we get back on topic” message.

You can see all this in action in the chatbot on our home page at www.pandorabots.com

Don’t worry if this seems a little complicated. If you are a Mitsuku Module customer, we can help you integrate it into your own chatbots. Giving your chatbot a personality this way, makes for a great user experience and is a whole lot better than a, “Sorry I don’t understand” message.

To bring the best bots to your business, check out www.pandorabots.com or contact us at info@pandorabots.com for more details.

pandorabots-blog

The leading platform for building and deploying chatbots.

Steve Worswick

Written by

Mitsuku's creator and developer. Mitsuku is the 5 times winner of the Loebner Prize and regarded as the world's most humanlike conversational AI

pandorabots-blog

The leading platform for building and deploying chatbots.

More From Medium

More from pandorabots-blog

More from pandorabots-blog

CogX London 2018

More on Bots from pandorabots-blog

More on Bots from pandorabots-blog

Introducing Live Training for Chatbots

More on Pandorabots from pandorabots-blog

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade