0

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 specific models. You will try to understand how it applies to some real-world problems or outcomes (e.g., 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 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. Maybe, 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 shown below or if you are redirected to the 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 that references to the chatbot. 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 the 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 a 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 four 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. If no intention to leverage APIs, 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

The tool creates two intents by default i) Default Welcome Intent and ii) Default Fallback Intent

‘WELCOME’ event activates default welcome intent. Additionally, when a user says ‘Hi’, ‘Hello’, or ‘Welcome’ depending on the list of user expressions in ‘User Says’, default welcome intent is activated.

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 is more than one text response in any Intent, what I had noticed is that the responses will be used in round-robin fashion whenever the corresponding Intent matches

Click on ‘+’ sign alongside Intent on the left side to create a new Intent. The fundamental premise 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 anticipate possble user queries around what is the product, why customers use the product, 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 with Entities. Now if you look at one on my user expression – ‘what product does AVC support?’ Apart from variations in user expression, multiple words might have the same meaning. 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 do 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 two 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 the 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 🙂

Appreciate your thoughts or opinions