A beginner’s guide to creating a Cognitive Chatbot
Author: Abdul Hasib Sazzad
Senior Software Engineer
Machine Learning / Cognitive Systems/ Deep Learning / Software Engineering
Cognitive chatbots are intelligent personal agents that have the ability to use machine learning to drive natural-language conversations, and hence can be distinguished from the long line of traditional and monotonous ‘bots’ that came before.
One of our major competencies at Infolytx is in Artificial Intelligence and Cognitive Systems. As part of our work with cognitive systems, we have built a number of Artificial Intelligence enhanced cognitive chatbots.
Here I will walk you through developing a simple cognitive chabot powered by IBM Watson.
You will need to begin with an IBM Bluemix account.
Step 1: Sign-up with IBM BlueMix and login to the console
First visit this link and click ‘Sign Up’ from the menu to sign up for an IBM BlueMix account. After the account registration is complete, visit this link to go to the BlueMix console. Log in with your credentials if needed.
Before you start using Bluemix, you need to create your organization and space, which you will be prompted for the first time.
Step 2: Journey to the Conversation Service
- You will be taken to the Dashboard.
- Navigate using the navigation bar on your left, and select ‘Watson’
Step 3: Create the Watson Conversation Service
- Click ‘Create Watson Service’ as shown in the screenshot above
- Select ‘Conversation’
- Click the ‘Create‘ button
Step 4: Launch the tool
You will be taken to a Conversation entry page, where you select Launch Tool. You might be prompted to log in again.
You will then need to login to the conversation service with your Bluemix ID.
Step 5: Create a workspace
A workspace is a container for the artifacts that define the conversation flow for an application.
- In the Conversation tool, click Create .
- Give your workspace name and click Create
Step 6: Create intents
An intent represents the purpose of a user’s input. You can think of intents as the actions your users might want to perform with your application.
In this example, we’re going to keep things simple and define only two intents: one for saying hello, and one for saying goodbye.
You should be in the Intents tab in Build menu as shown in the screenshot above. If not, navigate to the the Build menu’s Intents tab using the navigation bar on the left.
- Click Create new. You can also import your intents if you have any.
- Name the intent hello and press Enter. The ‘#hello’ Intent will be created.
- Type hello as a User example and press Enter.
- Examples tell the Conversation service what kinds of user input you want to match the intent. The more examples you provide, the more accurate the service can be at recognizing user intents.
- Add some more user examples “hi , good morning, greetings” and click Done to finish creating the #hello intent:
- Create another intent named #bye with these examples: “bye, farewell, goodbye, I’m done, see you later”.
You’ve now created two intents, #hello and #goodbye, and provided example user inputs to train Watson to recognize these intents.
Step 7: Build a dialog
A dialog defines the flow of your conversation in the form of a logic tree. Each node of the tree has a condition that triggers it, based on user input.
We’ll create a simple dialog that handles our #hello and #bye intents, each with a single node.
Adding a start node
In the Build menu, click the Dialog tab.
Click Create. You’ll see two nodes.
- Welcome: Contains a greeting that is displayed to your users when they first engage with the bot.
- Anything else: Contains phrases that are used to reply to users when their input is not recognized.
Click the Welcome node to open it in the edit view.
Replace the default response most likely “Hello. How can I help you?“ with the text ” Welcome to the Cognitive Agent!”. Click the cross button to close the edit view.
You have now created a dialog node that is triggered by the welcome condition. This is a special condition that indicates that the user has started a new conversation. Your node specifies that when a new conversation starts, the system should respond with the welcome message.
Testing the start node
You can test your dialog at any time. Let’s test it now.
- Click the icon to open the “Try it out” pane. You should see your welcome message.
Adding nodes to handle intents
Now let’s add nodes to handle our intents between the Welcome node and the Anything_else node.
- Click the More icon on the right side of the Welcome node, and then select Add node below.
- Give a name to the node.
- Type hello in the Enter a condition field of this node. Then select the #hello option.
- Add the response, “Good day to you”.
- Close the edit view.
- Click the More button on this node.
- Then select Add node below to create a peer node. In the peer node follow steps 2 to 5 and specify #bye as the condition, and OK! See you later. as the response.
Step 8: Test intent recognition
You built a simple dialog to recognize and respond to both hello and goodbye inputs. Let’s see how well it works.
Click the icon to open the “Try it out” pane. There’s that reassuring welcome message.
- At the bottom of the pane, type Hello and press Enter. The output indicates that the #hello intent was recognized, and the appropriate response (Good day to you.) appears.
- Try the following input also like goodbye, howdy, see ya, good morning, sayonara.
This Chatbot can recognize your intents even when your input doesn’t exactly match the examples you included. The dialog uses intents to identify the purpose of the user’s input regardless of the precise wording used, and then responds in the way you specify.
That’s it. You created a simple conversation with two intents and a dialog to recognize them.
Step 9: Explore the sample workspace
Open the sample workspace Like Car Dash Board to see intents similar to the ones you just created plus many more, and see how they are used in a complex dialog.
There you go. You’ve now created your first intelligent chat bot. Stay tuned! In the subsequent days I will teach you how to build more complex agents with more features. Till then, you can explore more here.