In this tutorial, you will use the Conversation service to create a dialog that helps users interact with a cognitive car dashboard.
Lessons 1-6 of this tutorial should take approximately 1 to 2 hours to complete. Lessons 7 could take many hours to complete, depending on the method you choose to use to deploy the workspace.
To begin the tutorial, you need to create a new instance of the Conversation service and launch the tool.
Log in to IBM® Bluemix® and navigate to the Conversation service on IBM® Bluemix®:
In the Service name field, specify
On the "Service Details" page, click Launch tool.
A workspace is a container for all the artifacts that define the behavior of your service.
Add some intents on the Intents tab. An intent is the purpose or goal expressed in user input.
On the Intents page of the Car tutorial workspace, click Create new.
Add the following intent name, and then press Enter:
# is prepended to the intent name you specify. The
#turn_on intent indicates that the user wants to turn on an appliance such as the radio, windshield wipers, or headlights.
In the User example field, type the following utterance, and then press Enter:
I need lights
Add these 5 more examples to help Watson recognize the
Play some tunes Turn on the radio turn on Air on please Crank up the AC Turn on the headlights
Click Done to add the intent.
Repeat steps 2-5 to create a
#greeting intent with these utterances:
Hello Hi Good morning Good afternoon Good evening Howdy
You defined two intents,
#greeting, with example utterances. These examples help train Watson to recognize the intents in user input.
An entity definition includes a set of entity values that can be used to trigger different responses. Each entity value can have multiple synonyms, which define different ways that the same value might be specified in user input.
Create entities that might occur in user input that has the #turn_on intent to represent what the user wants to turn on.
Click the Entities tab to open the Entities page.
Click Create new.
Add the following entity name, and then press Enter:
@ is prepended to the entity name you specify. The
@appliance entity represents an appliance in the car that a user might want to turn on.
Click the toggle to turn fuzzy matching On. This setting helps the service recognize references to entities in user input even when the entity is specified in a way that does not exactly match the syntax you use here.
Add the following value to the Value field, but do not press Enter:
The value represents a specific appliance that users might want to turn on.
Add other ways to specify the radio appliance entity in the Synonyms field. Press tab to give the the field focus, and then enter the following synonyms. Press Enter after each synonym.
Click the Add a new value icon to add other types of appliances.
air conditioning. Synonyms:
Click Done to add the @appliance entity.
Repeat Steps 2-8 to create the @
genre entity with these values and synonyms:
rhythm and bluesSynonym:
rock & roll,
rock and roll, and
You defined two entities:
@appliance (representing an appliance the bot can turn on) and
@genre (representing a genre of music the user can choose to listen to).
When the user's input is received, the Conversation service identifies both the intents and entities. You can now define a dialog that uses intents and entities to choose the correct response.
A dialog is a set of conversational nodes that are contained in a workspace. Together the set of nodes makes a dialog tree, on which every branch is a conversation that can be had with a user.
Create a dialog and add a node:
On the Car tutorial workspace page, click the Dialog tab.
Click Create. A dialog is created with the following nodes:
Click the Welcome node to open it in edit view.
Replace the existing response (Hello. How can I help you?) with the text,
Welcome to the car tutorial!
Click to close the node edit view.
Click the More icon on the Welcome node, and select Add node below.
In the edit view, specify the condition and response for this node of the conversation.
In the condition field, start typing
#greeting, and then select it from the list.
In the response field, enter the following text:
Hi, there. What can I do for you?
Your bot will show this response when the specified condition is true (in this case, when someone greets the bot).
Click to close the node edit view.
The tree view now shows the node you added.
Select the icon.
In the chat pane, you should see the bot welcome message,
Welcome to the car tutorial!.
Type a greeting, such as "Hi", and then press Enter. The output shows that the #greeting intent is recognized, and the appropriate response is displayed.
Congratulations! You have had a successful first chat with your bot.
Close the chat pane.
In this complex dialog, you will create dialog branches that handle the #turn_on intent you defined earlier.
Create a dialog branch to respond to the #turn_on intent. Start by creating the root-level node:
#turn_onin the condition field, and then select it from the list. This condition is triggered by any input that matches the #turn_on intent.
The dialog needs to determine which appliance the user wants to turn on. To handle this, create multiple responses based on additional conditions.
There are three possible scenarios, based on the intents and entities that you defined:
Scenario 1: The user wants to turn on the music, in which case the bot must ask for the genre.
Scenario 2: The user wants to turn on any other valid appliance, in which case the bot echos the name of the requested appliance in a message that indicates it is being turned on.
Scenario 3: The user does not specify a recognizable appliance name, in which case the bot must ask for clarification.
Add nodes that check these scenario conditions in this order so the dialog evaluates the most specific condition first.
Add nodes that address scenario 1, which is that the user wants to turn on the music. In response, the bot must ask for the music genre.
@appliance:radio. This condition is true if the value of the @appliance entity is
radioor one of its synonyms, as defined on the Entities tab.
What kind of music would you like to hear?
Jump directly from the
#turn on node to the
Music node without asking for any more user input. To do this, you can use a Jump to action.
Note that you had to create the target node (the node to which you want to jump) before you added the Jump to action.
After you create the Jump to relationship, you see a new entry in the tree:
Now add a node to process the type of music that the user requests.
@genreto the condition field. This condition is true whenever a valid value for the @genre entity is detected.
OK! Playing @genre.as the response. This response reiterates the genre value that the user provides.
Add a node to respond when the user does not specify a recognized value for @genre.
truein the condition field, and then select true (add new condition) from the list. This condition specifies that if the dialog flow reaches this node, it should always evaluate as true. (If the user specifies a valid @genre value, this node will never be reached.)
I'm sorry, I don't understand. I can play classical, rhythm and blues, or rock music.as the response.
That takes care of all the cases where the user asks to turn on the music.
Select the icon to open the chat pane.
The bot recognizes the #turn_on intent and the @appliance:music entity, and it responds by asking for a musical genre.
Type a valid @genre value (for example,
The bot recognizes the @genre entity and responds appropriately.
Play music again, but this time specify an invalid response for the genre. The bot responds that it does not understand.
We will add nodes that address scenario 2, which is that the user wants to turn on another valid appliance. In this case, the bot echos the name of the requested appliance in a message that indicates it is being turned on.
Add a node that is triggered when any other valid value for @appliance is provided by the user. For the other values of @appliance, the bot doesn't need to ask for any more input. It just returns a positive response.
@applianceas the node condition. This condition is triggered if the user input includes any recognized value for the @appliance entity besides music.
OK! Turning on the @appliance.as the response. This response reiterates the appliance value that the user provided.
Select the icon to open the chat pane.
The bot recognizes the #turn_on intent and the @appliance:headlights entity, and it responds with
OK, turning on the headlights.
turn on the air.
The bot recognizes the #turn_on intent and the @appliance:(air conditioning) entity, and it responds with
OK, turning on the air conditioning.
Try variations on all of the supported commands based on the example utterances and entity synonyms you defined.
Now add a peer node that is triggered if the user does not specify a valid appliance type.
truein the condition field, and then select true (add new condition) from the list. This condition specifies that if the dialog flow reaches this node, it should always evaluate as true. (If the user specifies a valid @appliance value, this node will never be reached.)
I'm sorry, I'm not sure I understood you. I can turn on music, headlights, or air conditioning.as the response.
Try more utterance variations to test the dialog.
If the bot fails to recognize the correct intent, you can retrain it directly from the chat window. Select the arrow next to the incorrect intent and choose the correct one from the list.
Optionally review the Car Dashboard - Sample workspace to see this same use case fleshed out even more with a longer dialog and additional functionality.
Click the Back to workspaces button from the navigation menu.
On the Car Dashboard - Sample tile, click Edit sample.
Now that you have built and tested your workspace, you can deploy it by connecting it to a user interface. There are several ways you can do this.
You can use the Watson SDK to build your own front-end application that connects to your workspace using the Conversation REST API.
You can use the Botkit framework to build a bot application that you can integrate with social media and messaging channels such as Slack, Facebook, and Twilio.