Original article was published by Parker Merritt on Artificial Intelligence on Medium
1. Create an IBM Cloud account.
Watson Assistant is one of the many services available on IBM’s public cloud platform, so the first step in creating our chatbot is to sign up and log in.
2. Check out the Resource List page.
This tab will eventually show us the various cloud services we’ve provisioned (including Watson Assistant). Click Create Resource in the upper-right corner.
IBM Cloud boasts 170+ products & services, with dozens of data management, AI, and analytics applications, so be sure to check out everything the platform has to offer.
3. Provision a Watson Assistant instance.
Search the IBM Cloud Catalog for Watson Assistant, and create an instance free-of-charge with the Lite plan.
4. Create your first assistant.
You have the ability to create several assistants within a single instance. After creating your first assistant, provide it with a name and an optional description. Finally, click Create Assistant.
5. Add a Dialog skill.
Assistants interact with users through a collection of behaviors called Skills. Watson Assistant comes with a library of pre-configured skills for a variety of common enterprise uses cases (customer care, for example). In this tutorial, however, we’ll be creating our own.
To begin designing our bot’s conversational abilities, click Add dialog skill.
Watson Assistant’s dialog skill is comprised of 3 main components:
#Intents: An intent is a collection of similar statements expressed by users, typically representing a desired goal or function. For a retail bot, for example, a customer might be seeking #product-info.
@Entities: An entity represents a more specific piece of information in a user request, providing detail and context to the overarching intent (perhaps a particular @product in the retail bot example).
Dialog: The dialog element provides a graphical outline of how intents and entities interact, mapping each combination to a customized, automated response.
6. Create your first Intent.
Most users will begin interacting with your bot the same way they would interact with a human— by greeting them! Click Create intent and give it the name #Greetings.
7. Provide Watson some example greetings.
To help our bot recognize what a typical greeting might look like, we’ll give Watson some examples to train on. Provide at least 5 to 7 variations of common greetings.
After analyzing these examples, our bot will not only be able to recognize those specific phrases as #Greetings — thanks to Watson’s core Natural Language Processing capabilities, it will also be able to more readily identify other variations we haven’t trained on.
8. Construct your first Dialog node.
Now that we’ve created our first Intent, let’s integrate it into our bot’s conversational flow by creating a dialog node. Click Dialog on the menu, then click Add Node. Name the node “Greetings,” and under the subheading “If assistant recognizes,” select your #Greetings Intent.
Under the “Assistant responds” subheading, script some replies to be triggered whenever your bot detects a greeting. It could seem a little too robotic if your workout assistant responded the same way every time, so give your bot a few different greetings to cycle through!
9. Try out your bot.
Your customized dialogue updates in real-time, and we can continuously test out our assistant’s conversational capabilities by clicking the Try it button in the upper-right corner. Open up the chat window and say hello!
You’ll notice that, below your chat entries, Watson displays the #Greetings classification. If Watson does not recognize your greeting’s Intent, however, the entry will be marked as “Irrelevant.”
Luckily, we can train Watson to recognize these unfamiliar greetings right here in the chat window. Try entering a greeting that you did not include in your initial list of examples. If Watson fails to correctly classify it, simply click to open up the classification’s drop-down menu in the chat, and select the #Greetings Intent. Watson will now recognize this phrase in future instances!
Note that after some changes, Watson will need time to train. Watson is still training if the following purple message appears at the top of the chat window. Once this message disappears, the dialog results will reflect your latest edits.
10. Add some workout-related Intents.
Now that we’re familiar with how Intents and Dialog nodes work, let’s teach our assistant about fitness! Navigate back to the Intents window, then click Create intent.
Choose a common exercise topic that users might want to ask your bot about (for example, “How long should I rest between sets?”). As was the case with our #Greetings Intent, you’ll also need to provide Watson with 3–5 examples of how this type of question might vary. Our example question, with a few variations, might look something like this:
How long should I rest between sets?
Should I rest before doing another execise?
Do I need to rest between each set?
Once you’re finished building out your first Intent, go ahead and add a few more (check out the WISE Fitness FAQ Page for a full list of ideas). The more Intents and topics your Workout Advisor is able to recognize, the more useful it will be for your users!
11. Create a Dialog node for each new Intent.
After you’ve created a collection of new workout-related Intents for your bot to advise users on, return to the Dialog page to integrate them into your conversational flow. Follow the same process from when you creating your Greetings dialog— selecting Add node, identifying the desired Intent, and providing a scripted response.
Feel free to pull answers from the WISE Fitness FAQ, or do a bit of research and customize your own answers. The more details your assistant can provide, the better! As you build out each node, continue to test and experiment with your bot in the Try it window, double-checking to ensure that your Q&A’s are working as expected.
12. Organize your new Intents in a folder.
By now, your Exercise Advisor is capable of fielding quite a few questions, but your Dialog map is probably looking pretty crowded. As the number of Intents grows, it can become difficult to visualize how a conversation with your bot might flow. Let’s clean things up a bit!
Click the Add folder button at the top of the Dialog page.
After creating the folder and giving it a name (i.e. “General Workout Questions”), move each of your new exercise-related Dialog nodes by clicking the Actions icon (⋮) and selecting Move. Then, click on your folder and select the To Folder option to place your Dialog node inside.
Now you can easily reveal/hide this group of Intents by clicking on the folder icon. Much better!
13. Create a workout recommendations Intent.
So far, we’ve learned how to create basic Q&A dialog flows using some pretty straightforward Intents. But what if our conversation gets a little more complex?
Let’s say our user is looking for some personalized workout recommendations. Inherently, this kind of request can’t be answered with a simple Q&A structure. There’s more context that you need to understand— what kind of equipment do they have available? What muscle group are they targeting? Without getting a little more background, your bot won’t be able to offer a high-quality response.
This is where context variables come in. Watson uses context variables to store this kind of situational input (provided by either the user or an external plugin) in order to create a more specific, customized response.
Before we create our context variables, however, we’ll need to build out the corresponding Intent and Entities. Begin by creating a “workout recommendations” Intent (i.e. #WorkoutRecs). Follow the same process as before, and include a few variations with alternative phrasings.
Sample utterances of this Intent might include:
Can you recommend some exercises?
What workouts can I do?
Any exercise recommendations for a home workout?
I need recommendations for my workouts!
14. Create an Entity for muscle groups.
Next, we’ll add an Entity to help further specify the context of our workout recommendations. In this case, we’ll categorize each exercise by the targeted muscle group. For the sake of simplicity, in this tutorial, we’ll only define 2 broad muscle groups (upper and lower body). Feel free to return to this step later on to create additional muscle groups (and other contextual categories like equipment) to help fine-tune your bot’s recommendation engine.
To begin, click Create entity and provide it with the name @musclegroup.
Then, name your first @musclegroup value “upper body.” Under the synonyms field, list a series of muscles that would fall into the upper body category (arms, chest, shoulders, etc.). Also include alternative ways that users might phrase the “upper body” category (upper, torso, top half).
Once you’re finished listing possible ways a user might request workout recommendations for the “upper body” category, click Add value. Then, repeat this process for the “lower body” value. Provide both muscle names (quads, glutes, calves) and alternative category names (lower, legs, bottom half).
15. Add your workout recommendations dialog node.
Navigate back to the Dialog page and click Add node. Under “If assistant recognizes,” select your #WorkoutRecs Intent.
Because we want to differentiate our recommendations based on the desired muscle group, we’ll need to customize this node a little further. Click Customize in the upper right corner of the node, then turn on the Slots and Multiple conditioned responses options.
Slots give your bot the ability to collect and store user input. In this case, our slot will store our target muscle group.
Multiple conditioned responses will allow you to use the input you’ve captured in your slots to offer different responses, depending on the context.
16. Store the user’s muscle group as a context variable.
Remember context variables? We’re now going to use our slot to capture the user’s muscle group input (in the form of an Entity) and store it in one of these variables. Context variables are denoted with the $ prefix.
Under the Then check for section, fill out the text fields as follows:
Check for: @musclegroup
Save it as: $musclegroup
If not present, ask: What muscle group would you like to work out?
Now, the bot should be able to prompt the user for a target muscle group (if not initially provided), then store this information as a context variable for later use in the conversation.
You can see your context variable in action by clicking the Try it window and chatting with your bot. After requesting a workout recommendation for “arms,” click Manage Context in the upper right corner. Your bot has stored this input as $musclegroup = upper body!
17. Provide conditioned responses for each muscle group.
It’s finally time to script exercise recommendations! Scroll down to the Assistant Responds section of your node and click Add response to bring the total number of potential responses to 2. Then, fill out each field as follows:
If assistant recognizes: $musclegroup:(upper body)
Respond with: For upper body exercises at home, here are a few options you can try: <br/>- Push-Ups (Chest) <br/>- Dips (Triceps) <br/>- Planks (Shoulders)
If assistant recognizes: $musclegroup:(lower body)
Respond with: For lower body exercises at home, here are a few options you can try: <br/> – Body Weight Squat (Hamstrings/Quads) <br/> – Lunges (Hamstrings/Quads) <br/> – Toe Raises (Calves)
The <br/> symbol included in the two examples above is what is known as a “break” element in HTML. This particular element allows you to separate your text into sequential lines. There are many other ways you can format your bot’s responses using HTML tags, for example:
- <b>Text Here</b> to make your text bold.
- <i>Text Here</i> to make your text italic.
- <a href=“Link Here”>Text Here</a> to insert a hyperlink.
Feel free to get creative with the look and feel of your bot’s responses— unique formatting can be a great way of injecting a little more personality into the conversation!
18. Create a node to clear our context.
While testing your bot, one thing you may notice is that context variables are stored for the entire conversation, by default. This can present some issues. For example, if your user asks for upper body workout recommendations, then follows up to ask about recommendations for a different muscle group, your bot will assume they’re still requesting information from the upper body category.
Bot: Hello. How can I help you?
User: Can you provide me with some workout recommendations?
Bot: What muscle group would you like to work out?
User: Upper body.
Bot: For upper body exercises at home, here are a few options you can try…
User: Any recommended exercises for other muscle groups?
Bot: For upper body exercises at home, here are a few options you can try…
What the bot should do is make another request for a target muscle group. Because the “upper body” context variable is still being stored, however, the bot is unable to recognize the new scope of this question.
To address this concern, we’ll construct a Child node to clear our conversation’s context after exercise recommendations are provided.
Click the Actions icon (⋮) on your “Workout Recommendations” node, then click Add child node. Name this new node “Clear Context.” Under “If assistant recognizes,” select your $musclegroup context variable. Then, click the Actions icon (⋮) next to the “Assistant responds” section, and open up the Context Editor.
After the Context Editor is opened, enter the following values into the fields:
This will clear the $musclegroup variable of any stored values once the node is activated.
Finally, under “Assistant responds,” add a friendly follow-up message (“Let me know if you have any other questions!”), inviting the user to make additional queries.
19. Connect our Workout Recommendations node to the child node.
In order to trigger our “Clear Context” actions, we’ll have to connect it to our “Workout Recommendations” node.
Click back over to the “Workout Recommendations” node, and scroll down to the bottom. Underneath the “Then assistant should” section, select Jump to from the dropdown menu. Finally, click the “Clear Context” node, and select Respond.
Your bot’s workout recommendation capabilities should be ready to do some heavy lifting! But one last thing…
20. Customize your bot’s Welcome message.
The most important rule in building a chatbot? Make sure people know they’re interacting with one. From the very beginning of the conversation, users should know there’s not a human on the other end of the line. This sets reasonable expectations for what sort of questions your bot can answer, and helps users feel you’re being transparent about your use of an automated system.
Click the Welcome node to begin editing your intro message. Here’s a sample greeting to get you started:
Hi there! My name is Flex. I’m a chatbot, and your very own personal workout assistant! I can help answer basic questions about fitness and provide exercise recommendations. What can I do for you today?
Ready to Rumble!
Congrats— your virtual workout advisor should now be ready for the big leagues! Navigate back to the Assistants page to access your bot’s preview link, and give it a spin. The preview URL is publicly accessible, so be sure to share with your most fitness-savvy friends!
Going the Extra Mile
We’ve added a lot of cool features today, but don’t stop now! There’s plenty of ways you can continue strengthening your bot’s training capabilities. Now that you’ve got a grip on the basics, here are a few ideas for improvements:
- Add an Intent that allows your bot to give motivational tips, and get users pumped to workout!
- Create more muscle group Entities and provide your users with more targeted workouts.
- Enable your bot to suggest common household objects that can be used for equipment while working out at home.
- Expand the scope of your workout suggestions to include cardio exercises, yoga poses, and more!
- Build out an Intent to help advise users on their nutritional habits, depending on their fitness goals.
Get creative with personalizing your virtual workout advisor, and stay tuned for Part 2 of the tutorial, where we’ll integrate our chatbot with Watson Discovery to extract exercise instructions from the WISE Fitness training manual!