Creating Minimal, Easy & Effective Chatbots with Microsoft LUIS





“If you ask me what’s your certainty that chat is going to be the next once-in-a-decade platform, I would say 99%. I am completely convinced that chat is going to be the next big platform.”

Ted Livingston, CEO Kik

The Chatbot diegesis

By now we all have probably tried one of those sites – the ones with a pop-up down below on the right, that goes off with greetings, assistance with bookings, subscriptions, new service offerings etc. etc. These chatbots have been around for awhile now, giving both, the business holder and the visiting user the ability to bridge the gap of communicating services. While chatbots are extensively used in the customer services domain, today it has also found its way to various other domains like artificial intelligence, conversational systems like Siri, wearables, robotics, etc. The applications are high in number, and the implementation challenges are many. Some of these challenges are Security, Speech Recognition, Language Authentication, Language Understanding, Scale, Business Logic, etc. Keeping in mind these challenges, many IaaS providers and companies have now built cloud platforms and APIs to simplify this problem and give a user-friendly interface to build efficient bots without the need of a data scientist or a machine learning expert.

Chatbots   Fig: Chatbot Service Providers

Great. So what am I here for?

There are a lot of resources out there on the Internet to get started with your own chatbot. In fact, there is a full-fledged online magazine that features very interesting articles from implementation to updates on latest chatbots.

This post here, though, describes a minimal, easy and effective way you can build a chatbot for your very own web/mobile application using above cloud services and API, and that too for free. We will attempt to cover Microsoft’s cognitive LUIS services in this post with a live example, and while we do this, you will realize how easy and convenient it is for even a beginner to learn and implement a trained chatbot. In a subsequent post, I will attempt to cover the AWS Lex+Polly service which works sweet with AWS Lambda and external APIs, giving us a really useful conversational chatbot.

Let’s get started!

Language Understanding Intelligent Service (LUIS) leverages machine learning capabilities to develop virtual assistants, chatbots, IOT experiences or any intelligent service on any device. To start with LUIS you can go to the site, create an account, add the additional information on login and start by creating a new application. If you have reached the below page you are good to go.

pasted image 0 (2)
Fig: LUIS Application List Page

Please note that LUIS is in its beta stage and the portal interface might change with time, but the basic workflow will be retained. For the purpose of our example, we attempt to create a hotel booking chatbot which assists users to view and select a hotel for booking. To create a new LUIS application (i.e. a new chatbot service in pur) click on New App >> New Application or simply click on the blue link below “Let’s get started”.

A modal will prompt you to add the application name and a few other details like the type, domain, description and culture of the application. For our example here let’s call it “BookMyHotel”.

pasted image 0 (1)

Once you click on “Add App” you have successfully created a new LUIS Application. You should now be able to see your application listed on the applications dashboard as below.
pasted image 0 (2)
Click on the app and you will now have an empty dashboard with a left-hand menu panel.


Intents, Entities and Utterances


Short version:

Intents are statements that we feed LUIS to determine the intent of the user, by detecting entities in an utterance.


The not-so-short version:

We create intents in LUIS in order to encapsulate an intention behind a customer query. To understand this, let’s create a new intent named “SearchAHotel” using the steps below:

  • Go to Intents in the left-hand menu panel, then click the plus sign new_16x16.
  • In the Add a new Intent dialog box, type “SearchAHotel” as the intent name.
  • In the text box that appears below the intent, type a sample utterance for your intent. For example, type in the following “I am looking for hotels around California”.
  • When finished, click “Save”.

pasted image 0 (3)

As you can see there is also an “Add Action” link. We will come back to that later. After you click save you should now see a new Utterance added.

Notice that the whole statement is lowercase. Click submit and the utterance would be added successfully against the “SearchAHotels” Intent. The next time you try to use this particular utterance, LUIS would identify that you intend to search a hotel.

Now, the reason that this is not efficient is because you will notice that LUIS does not recognize any other variants of the above sentence. For eg: If you type “I need a hotel”, even the human intention is hotel booking, LUIS will fail to recognize this. Also, if you try to add a lot of utterances for this intent, and then add another intent with a similar statement (not necessarily the same, but nearly similar), LUIS will not be able to identify the correct intent.

And so, enter “Entities”.

We add entities in order to explicitly identify key elements in an utterance against an intent. In other words, an entity clarifies what the user actually wants in an intent, thus distinguishing it from other intents. To understand what this means let’s create two entities for our sample. We will first make a custom “Hotel” entity and then add an inbuilt “geography” entity.

  • Click on the plus sign new_16x16 next to Entities in the left panel.
  • In the Add a new Entity dialog box, type “Hotel” as the entity name.
  • Select Include Children, and then click “Hierarchical”.
  • Click the plus sign next to new_16x16 Entity Children to add the children/components of the composite.
  • To delete a child, if you made a mistake, click the trash can sign delete_1 next to the entity child.
  • When finished, click “Save”.

I have added a few children to the “Hotel” entity here as shown below.
pasted image 0 (5)

To activate the inbuilt “geography” entity, you can click on the new_16x16 sign beside “Pre-built Entities” and select the same. Click Ok.

pasted image 0 (6)

After adding the entities you will notice the entities added on your left-hand side panel. Click ‘train’. Let’s try to put another utterance in the “New Utterance” section.

pasted image 0 (8)

This time we notice a shaded word “california” which on hover, tells us that it belongs to the geography entity. Also, you will notice that individual words and phrases are now clickable and these can be mapped to a custom entity. Note: Hierarchical and composite children differ such that composite children are entities that can be mapped on a “belongs to” or “has a” relationship basis rather than a parent-child relationship as is the case for hierarchical children.

So let’s map the word hotel to our hotel entity.

pasted image 0 (7)

After adding a few more (10-11) utterances with entity mapping, click on the “Train” button below. This will use the Microsoft’s machine learning packages to train the application for similar patterns.

pasted image 0 (10)

The next time you try different utterances, you will notice that the word hotel and country/city names are already mapped to the entities and it gives a high probable value for our SearchAHotel intent!


pasted image 0 (9)

So that basically means that your bot now recognizes user statements when he intends to book a hotel. Cool, isn’t it?!!

Now that we know that our bot is smart enough to understand intents, we need the bot to respond in a way that will fulfill the particular intent. And this is where we talk about actions and fulfillments.

Actions and Fulfillments

Every action bound to an intent needs to satisfy a particular requirement in order to be triggered. In LUIS, these requirements are known as parameters. It presently supports only one action per intent. Each action can include a group of parameters derived from entities. The parameter can be optional or required, LUIS assumes that an action can be triggered and fulfilled only when all the required parameters are satisfied.

For our example let’s add some actions with parameters. Before we do this, we will need to add some other entities like “Greeting” and the inbuilt “number” entity. The “Greeting” entity will help identify any greeting (hi, hello and other child entities) mentioned in the utterance which is non-mandatory. We will also attempt to fulfill this action by asking the user the location and number of guests. As shown below we can see action parameters greeting, location and guests are mapped to respective entity types and a “Prompt” that will be asked to the user in the order that these parameters are defined, each time the intent is triggered.
pasted image 0 (11)

So an example conversation would be as follows:

User: Hi, I would like to book a hotel

Bot: Which location are you planning to visit?

User: California

Bot: How many guests?

User: 2

Bot: <Fulfilled output>

The fulfilled output would be any value that we set as a result of the completion state of an intent. We can set the fulfillment in LUIS or we can have our own application detect the “Completion” state from the JSON output provided by LUIS Programmatic APIs. So an example final output would be

Bot: Thank you for providing me the details, let me check for some hotels around this area.

The JSON output of LUIS can also be obtained each time by querying the output using LUIS’s app URL after publishing the application. To know, let’s understand how to publish and test our bot.

Publishing and testing the bot

Once you have trained LUIS with your required intents, we can publish the bot for our external application to consume. For this simply click the ‘publish’ button on the left panel and you should now be seeing a publish modal like below. Click ‘Update published application’. After this, you can query the application with a sample utterance. On clicking enter, you will be redirected to the JSON output page, where all data along with parameter prompts will be present.
Untitled Diagram

Fig: Publishing a LUIS Application and querying the app. The URL shown is the actual query URL.


pasted image 0 (12)

Partial response from above query


pasted image 0 (13)

Dialog returned from above query


What Next?

The possibilities are limitless as to how these APIs can be used – Be it your wearables, web/mobile application, and IoT devices, these services enable you to create a customer-centric user experience with just a minimal chatbot interface on your website. There are also services that surpass traditional chats and allow audio based feeds to your customer. Bots can also be integrated to external chat services like Facebook Messenger, Slack, etc. All these features give more exposure to your business services.

Watch this space for a follow-up blog on Amazon Services which performs similar functions with audio capabilities.