Build a chatbot in ten minutes with Watson

Standard

Getting started on Bluemix

To get started with Conversation, you’ll need a Bluemix account. If you don’t have one already, you can sign up here (and get a free 30-day trial!). Once you have signed in, navigate to the catalog, scroll down to the Watson services, and select the Conversation tile. For this example, the Free plan will provide everything you need.

After you create an instance of the service, select it from the services section of your dashboard:

zach1

This will bring up a window with some links and information. Click on the Launch tool button to get started:

zach2

At this point, it’s time to create a workspace. One workspace corresponds to one bot—it contains all the configuration information that gives your bot its unique personality. In this step you can give it a name, write a description, and choose from one of five languages currently supported:

zach3

Configuring intents

The first thing you’ll see when you open your new workspace is the intents tab. Intents are things that the chat users are looking to do: change passwords, get status updates, make complaints, etc. What’s really neat about managing intents is that you are actually training the system to understand what is needed without depending on the exact words. You give multiple training examples that correspond to specific actions or requests.

Creating new intents is easy. First, click on the Add intents button. Pick a simple name for the intent (we’ll use this later). All you have to do to finish is add examples of user requests that fit the category.

For this bot, start with the basics: hello and goodbye. You’re going to train some intents to recognize opening and closing statements in a conversation. Here’s what I trained on for #greetings:

And here is what I used for #goodbyes:

zach5

Once you have those pieces, start training for more specific requests. As this is a customer service bot, you can expect some form of customer complaint. Train for that with the intent #complaint:

zach6

This covers the generic requests for help. But you’ll need something to handle the next step—the specific task that the user is requesting help for. You’re only going to include one example in this bot (remember, it’s super simple). Here are the training examples for #return:

zach7

Almost finished with this step! The final piece is training an intent to catch everything else that someone might say. These examples should be varied both in length and content. Here is my #anything_else intent:

zach8

Preparing entities

Once you’ve finished training your intents, move to the Entities tab. Entities are the specific pieces of information we want to extract from the user response. You’ll want to group entities that might trigger a similar response in your dialog. In this customer service example, we want to put together a list of potential items that the customer may wish to return. Here are my @returnItems:

returnitems

Dialog flow

When your intents and entities are specified, you can move on to constructing the dialog flow. This is the most complicated piece of your bot, because conversations can go anywhere! You want to focus on providing answers for the tasks you can help with, and providing feedback when the conversation gets out of scope. The super simple customer service chat bot will be able to respond to greetings and goodbyes, as well as give direction when a customer has a complaint, including specific feedback when the customer is looking to return an item.

Once you are in the Dialog tab, click Start and you will see the first node. Type “#greetings” into the Enter a condition field, and “Hello!” into the Watson says field.

zach10

This bot is set up to respond only after the user has said something to kick it off. If you would prefer to have it initiate the conversation, you could replace the “#greetings” with “conversation_start”.

At this point, you can begin to test your bot. In the upper right corner of your workspace, there is a speech bubble with three dots. When you click on this, a chat window slides in from the right. This is a test interface for your currently constructed dialog. You can test the classification ability of your intents by trying out some greetings that weren’t included in your training examples:

zach11

You can see that this test tool not only gives the response you set in the dialog node earlier, it also lets you see which intent best matches the input text. This is very useful for debugging!

Now it’s time to build the rest of your dialog. Your initial node has two plus signs, one to the right and one at the bottom. These represent two different ways to expand on the conversation. Clicking the plus sign at the bottom will create a parallel track of the conversation, clicking the one on the right will create a dependent track of the conversation.

Start by clicking the plus sign on the bottom of the #greetings node. In your new node, put “#complaint” in the condition field, and “Sorry to hear that, what can I help you with?” in the response.

zach12

Next, you’ll want to create a node for the specific complaint of wanting to return something. When I did this initially, I clicked the plus sign on the right side of the #complaint node, assuming the specific request to return something would happen after making a basic complaint statement. In my testing, I realized that it is likely a user would request to return something without ever making a generic complaint statement. A return request shouldn’t be dependent on a complaint statement, so I revised the dialog to make returns a parallel track:

zach13

There’s a lot going on here, so I’ll explain one node at a time. The first node (#return) does not have a response. This is because you want the response to be specific to the item being returned. Unlike the situation mentioned previously, this time you do have a true dependency and should use the plus sign on the right side of the #return node. I created the @returnItems:parrot node to handle the situation where the user is requesting to return a parrot, the @returnItems:(video cassette) node to handle the user returning a movie, and the true node to handle all other returns.

If I had only done this, the conversation would stop once the #return condition was satisfied. To keep it going to the next level, I clicked on the three dots at the top right corner of the #return node, selected Continue from…, and then clicked on the @returnItems:parrot condition. Because it is at the top, it will be evaluated first, followed by the other two conditions in the order. For more about the Continue from… functionality, please check out the documentation.

After the #return node, create two more parallel tracks (at the first level) for #goodbyes and #anything_else. This will cover all the use cases your bot can handle!

zach13

Testing and revising

When you’ve finished configuring your bot, you’ll want to test to make sure it does the job it’s supposed to. Using the testing tool discussed earlier, act as if you are a user who needs support help. Make sure you try out some statements that aren’t exactly the same as your training data. Here’s an example of a conversation that went as expected:

zach15

Here’s an example where the return request wasn’t properly recognized:

zach16

To improve your bot, add this statement to the list of examples in the #return intent. As soon as you make this change, you’ll see this banner in your test tool to let you know the system is updating:

zach17

When the updates are complete, you’ll see this:

zach18

If you test again, the system will now recognize requests for switching as returns:

zach19

Next steps

You now have a trained chat bot. The next step is to embed this into an application and connect with other services. To do this, you’ll want to use the Conversation API. I won’t go into all the details here, but we’ve got some great sample applications and documentation to help you get started. If you run into any troubles, make sure you connect with us on our support forums or Slack.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s