Creating a chatbot using API.ai – Layman’s guide

When you start learning ML and become fascinated by it, you will never stop with learning certain models. You will try to understand how it applies to some real world problems or outcomes. One such outcome is chatbot, I have been wondering about the possibility of creating a chatbot using NLP (with actual algorithms) and not using any tools. However, my learning is not progressing briskly to start implementing the algorithm for the real-world problem. Therefore, I contemplated using already existing tools/APIs to make some progress. Did some basic research and with some gut feeling choose API.ai and it turned out that my choice was actually great. API.ai did a great job in creating a chatbot with few easy steps.

This blog outlines the steps that I followed to create my first bot and everyone can follow it to create something fundamental. May be, those attempts can drag you into the worlds of ML, Statistic etc. All I can say is that it is a fascinating world to reside currently.

API.ai allow sign-in only through Google account, they cite security reasons for not providing additional options, but I believe it might be to have Google hegemony. Why would not they, after all, Google acquired API.ai. After signing in, you get a console as show below or if you are redirected to home page of API.ai, click on GO TO CONSOLE to start your journey for creating a chatbot.

Step 1 – Creating Agent.

Create a new agent (option is available on the upper left)

Provide an agent name, your bot will be referred by this name. Add a description that aptly describes your bot. Unless you are importing any existing agents, leave ‘ADD SAMPLE DATA’ blank. Change the time zone to reflect time zone of your location. Unless you already have any Google Cloud Project and wish to use it for chatbot agent, you can allow API.ai to create a new Google Cloud Project for your agent.

Finally, click on SAVE to create an agent.

Now a page, as shown above, should appear and it would provide options to create INTENTS, ENTITIES, and CONTEXTS. Before I delve into those details, there is setup icon next to agent name on the top left side. Click on it to make any changes to the agent.

Step 2 – Agent Settings

Settings page offers 4 tabs i) General, ii) ML Setting, iii) Export and Import and iv) Share

I only explored i) General and ii) ML Settings.

In i) General, clicking on Project_ID will redirect you to Google Cloud Platform. It is required if you are planning to leverage APIs. Otherwise, do nothing on the (i) General tab.

On (ii) ML Settings tab, try experimenting with ML threshold value. I tried modifying it to 0.50 while the default value is 0.30 (the acceptable value is in the range of 0 to 1). 1 indicates the best match if there is no best match INTENT, the response of FALLBACK INTENT will be displayed. For a higher value of threshold value, there is a high possibility of not matching any INTENT unless you provide too many options while defining INTENT for API.ai to train itself.

After any changes, do not forget to click on SAVE button.

Step 3 – Creating Intent

By default, there are 2 Intents already created for chatbot i) Default Welcome Intent and ii) Default Fallback Intent

Default welcome intent will be activated for the WELCOME event or if a user says ‘Hi’, ‘Hello’, or ‘Welcome’ depending on the list of user expressions in ‘User Says’.

Default fallback intent will be activated if user query does not match any Intent. You can add your default response in the default fallback intent. If there are more than text response in any Intent, what I had noticed is that the response will be used in round robin fashion whenever the Intent matches

Click on ‘+’ sign alongside Intent on the left side to create an additional Intent. The basic element for creating Intents is to identify all possible unique responses that you intend to provide to your users and what will be the user expression (or query) for each of those unique responses.

Since I was creating a chatbot for my product. I could think of user expression to know what is the product, why it is used, what is the cost etc. Accordingly, I created an intent for each response and identified the list of user expression for each unique response.

I have a created an Intent to respond to user expressions regarding what does the product do. Therefore, I created an intent outlining user expressions as shown in the picture below:

I did not explore Contexts and Parameters much. I will reserve that for a follow-up. However, I will explain what I did Entities. Now if you look at one on my user expression – ‘what product does AVC support?’ Apart from variations in user expression, users can also multiple words to refer something. In the above user expression, my customers generally refer AVC with NBAR or NBAR2 or NBARv2

If you took a close at the above picture again. On the right side, I have tested the agent with a user expression – ‘What platforms does NBAR2 support?’ Technically it is similar to ‘What products does AVC support’ but I have used platform instead of product and NBAR2 instead of AVC. To seek a better response from BOT what I did is to create Entities for defining synonyms as shown below:

I created similar entities for product keyword as well mapping it with product-line or platform.

Later, I went back to Intent and mapped those 2 words i) product and ii) AVC to corresponding Entities as shown below:

Chatbot now intercepts AVC, NBAR2, NBARv2, and NBAR as AVC. Instead of creating multiple user expression for each combination, creating Entities makes it easier now and I am also able to solicit a better response from chatbot.

The user expression has now matched parameter ‘AVC’ and ‘Product’. Please go ahead and create a chatbot with simple Intent and it is a lot easier now.

For integration with Cisco spark, please head to developer.ciscospark.com. Click on MY APPS on top right side and later click on + sign to create a new app. Now click on ‘Create a BOT’ to get an access token and supply the same while selecting Spark as an option under one-click integration.

My chat transcript my with my BOT

As a next step, I am planning to explore Contexts and integrate with Webhooks as well. If someone has already done it, please do reach me. I might need some help 🙂

Leave a Reply