Hello, Watson!

A Bot-Building Tutorial

David Thomason
Aug 27, 2017 · 9 min read
Image for post
Image for post
Photo: WikiMedia Commons

Whether we are part of a large business, a small startup, or a non-profit organization, there’s one objective that tends to arise when we seek to design and improve our organizations: providing our customers and users with an engaging experience. Although there are many ways to approach this objective, one of the recent trends to accomplish this is the rise of chatbots.

Chatbots are becoming a bigger presence in social media, e-commerce, and many other industries. Consider the Google Trends rise over the last couple years:

Image for post
Image for post
© 2015 Google Inc, used with permission. Google and the Google logo are registered trademarks of Google Inc.

For more background on what is driving this trend, check out the article Trends Driving the Chatbot Growth. Needless to say, some businesses are already choosing to enhance their customer engagement with bots. But many businesses and developers are still wondering how to get started.

IBM’s Watson Conversation is a cloud-based service that allows one to:

Quickly build and deploy chatbots and virtual agents across a variety of channels, including mobile devices, messaging platforms, and even robots.

Okay, so maybe you’re like me and want to start getting your hands dirty to see if this is really true…

Let’s Jump In

First, you’ll need a Bluemix account, after which, you can deploy a free instance of the Conversation Service from the catalog. Give it a name, click Create, and click the Launch tool button from the service Manage page:

Image for post
Image for post

Or go directly to https://www.ibmwatsonconversation.com. You’ll see the Workspaces view of Watson Conversation. Think of a workspace as the “brain” of a bot. It defines the intents, entities, and dialog flow that direct its behavior in a conversation.

Let’s create a “blank slate” brain for our bot. Click on the Create button from the Workspaces panel:

Image for post
Image for post

Fill in a name and description for your workspace, something like the following:

Image for post
Image for post

Click Create and you’ll land on a blank Intents panel.

Intents

When users interact with our bot, they will typically speak one phrase at a time. Each phrase that comes in needs to be classified under an intent. Intents, as they imply, allow us identify what the user intended to say.

In this example, phrases will get thrown into one of three buckets: a #greetings bucket, a #small_talk bucket, or a #goodbyes bucket. The bot needs to figure out what bucket, or intent, the phrase belongs in.

Let’s create a new intent and call it #greetings. Click on the Create new button.

Image for post
Image for post

Now fill in the intent name, “#greetings” and a few user examples. When filling in examples, you can hit enter to add the example.

Image for post
Image for post

Once the examples are filled in, click “Done” and we’ll see our new #greetings intent in the Intents panel.

Image for post
Image for post

Let’s repeat the same idea for #goodbyes. Fill in any examples you like.

Image for post
Image for post

Finally, let’s create our third bucket called #small_talk. Fill in the user examples with whatever small talk utterances come to mind. But be sure to include at least one example similar to, “I really like Mexican food” (I’ll explain why later.)

Image for post
Image for post

Let’s test it out. Open the chat sidebar by clicking on the chat bubble in the upper-right hand corner. As soon as Watson is done training, send a greeting to your bot.

Image for post
Image for post

Your message should be correctly classified as #greetings, which you can see in the image above under my input phrase “hey there buddy” in the chat sidebar. Of course, the bot does not respond because we have not built our dialog yet. Before we do that, let’s add an entity to see how those work. Click on the Entities tab at the top.

Entities

Let’s say the user says, “I like Korean food. How about you?” Our bot should correctly classify this utterance as the #small_talk intent. But we actually want to make our bot a bit smarter than that. We’d like to give it the ability to identify types of cuisine. The next step is to look at the sentence for any words that are types of cuisine (Italian, Mexican, Korean, etc.) These words are entities that we want to extract.

From the Entities panel, click the Create new button.

Image for post
Image for post

You’ll see fields for the entity name, values, and optional synonyms.

Image for post
Image for post

Create an entity named @cuisine and fill in the values with your favorite cuisines. Be sure that one of the cuisines is “Korean”.

Image for post
Image for post

When you’re finished, click Done and you should see the new entity in the Entities panel.

Image for post
Image for post

Let’s go back to the chat sidebar and try out the user utterance, “I really like Korean food”.

Image for post
Image for post

As you can see, the phrase is classified as #small_talk and the entity of type @cuisine and value “Korean” is identified. At this point we can classify the utterance and extract a specific word from it.

The final step is to have the bot respond. For example, we could say, “Oh, great to know that. I really love Korean food.” Let’s take a look at how to do that with the Dialog builder.

Dialog

Click on the Dialog tab. You should see the following:

Image for post
Image for post

Now click Create. You should see a simple dialog tree with two nodes named “Welcome” and “Anything else”:

Image for post
Image for post

The first node, Welcome, corresponds to what the bot will say as the introductory message. Let’s open it up and take a look. Click on the Welcome node and you’ll see a side panel with four sections.

Image for post
Image for post

The first section at the top is the name of this node, which in this case is “Welcome”. So far so good.

The next section is the condition of the node. “If the bot recognizes: welcome” indicates that this node is triggered by the special condition “welcome” which, according to the documentation on dialog conditions:

This condition is evaluated as true during the first dialog turn (when the conversation starts)… Typically, a node with this condition is used to greet the user, for example, to display a message such as “Welcome to our Pizza ordering app.”

Okay, so we know that this node will be triggered by the start of the conversation, and will be the first “introductory” message to be sent by the bot. Now let’s add another condition to this node so that it will be triggered by our #greetings intent as well. Click the plus sign “+” button next to the welcome condition:

Image for post
Image for post

Click on the box that says “and” and switch it to “or”. Then fill in the field marked “Enter a condition” with #greetings:

Image for post
Image for post

This node will be triggered both at the very beginning of the conversation or if the user ever utters something that we classify in the #greetings intent.

The third section is the response. “Then respond with:” allows us to define the response at this node. In this case it is, “Hello. How can I help you?” Feel free to change this introductory greeting to whatever you like. (e.g. “Hello, World!”)

The fourth and last section is the “And then” section, by default set to “Wait for user input”. We’ll keep this as-is for now because we’re asking the user a question, so we want to wait for their response.

Okay, so now we understand the Welcome node. Let’s create our own dialog node to make our bot more intelligent. Select the three dots inside the Welcome node in the dialog tree and select Add node below

Image for post
Image for post

You’ll see a new blank node with no condition or response set yet.

Image for post
Image for post

Let’s fill those in. We’ll make that this node can handle small talk. Name the node “Small Talk”, make the condition #small_talk and then fill in the response with something that could make sense in most small talk scenarios. I decided to keep my response very general:

Image for post
Image for post

Great, we can now handle two different user intents. Let’s see if we can get our bot to respond intelligently to the “I like Korean food” user input. With the Small Talk node still selected, click Add child node above the dialog tree.

Image for post
Image for post

You’ll see a child node of Small Talk in the tree. This means that the node will be reachable only after we have arrived at the Small Talk node. Fill in the name with “Cuisine Mentioned”, set the condition to “@cuisine” and response to “I love @cuisine food!

Image for post
Image for post

Excellent. Now let’s test it out. Open the chat sidebar and clear out your old conversation with the “Clear” button at the top. Then type in “I like Korean food

Image for post
Image for post

Hmmm, what happened there? Not quite what we expected. We got the right small talk response, and it seemed to identify “Korean” as a cuisine. However, we did not get the response that we set in our “Cuisine Mentioned” node. Why not? Let’s go back into our “Small Talk” node and take a look at the last section of the node, the “And then” section:

Image for post
Image for post

When we arrive at this node, the logic states that if the bot recognizes #small_talk, then respond with “Hey, I feel you buddy.” and then wait for user input. This is why we do not get to the Cuisine Mentioned node, because we are waiting for the user to say something. To correct this, click the drop-down in the And then section and select Jump to…

Image for post
Image for post

Next our focus goes back to the dialog tree and we see a banner at the top telling us to select the destination node. Click on the Cuisine Mentioned node and select If bot recognizes (condition).

Image for post
Image for post

Now we should have the Small Talk node configured to jump to the condition of the Cuisine Mentioned node.

Image for post
Image for post

Let’s try that input utterance again.

Image for post
Image for post

Bingo! This time, we get the responses we had set for both nodes. First from the Small Talk node, and then from the Cuisine Mentioned node. The response from our bot now makes sense in the context of our input utterance.

Hopefully by now you understand the basics of intents, entities, and dialog building. We used these three elements to create a very basic bot flow. But of course, there is so much more potential here. Try adding another node to handle the #goodbyes intent. Take a look at the Anything else node, which is triggered by another special condition. See if you can understand what it does.

Chatbot building can be a challenge. But as you’ve seen, Watson Conversation’s user interface helps make the process simpler and more intuitive. Challenge yourself and show the world what you can create with Watson Conversation.

Inside Machine learning

Deep-dive articles about machine learning and data.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store