Skip to main content

Microsoft Bot Framework Basics: Building Intelligent Bots - Adding Language Understanding Capability (Part 2)


The following article demonstrates how to use LUIS to add conversational intelligence to your apps. The focus will be about creating and consuming Language Understanding Models. We'll add Language Understanding capabilities to the news bot from the previous article. After this article, the bot will be able to interpret English language and map sentences to specific functions in the code.


Microsoft’s Language Understanding Intelligent Service (LUIS) offers a fast and effective way of adding language understanding to applications.
With LUIS, you can use pre-existing, world-class, pre-built models from Bing and Cortana whenever they suit your purposes – and when you need specialized models, LUIS guides you through the process of quickly building them.
Before proceeding, it is important that you understand the basic concepts of LUIS.

a. Intents: Consider intent as an intention or action. What action should a sentence trigger? Search for a news? Look for help? Proceed with sign up? Those can be examples of Intents. Intents match user requests with the actions that should be taken by your app.

b. Utterances: Utterances are sentences representing examples of user queries or commands that your application is expected to receive and interpret. LUIS learns from these utterances and your app is able to generalize and understand similar contexts.

For each intent, add example utterances that trigger this intent and include as many utterance variations as you expect users to say.

c. Entities: An entity represents a class including a collection of similar objects (places, things, people, events or concepts). Entities describe information relevant to the intent, and sometimes they are essential for your app to perform its task.
Imagine a news bot that search for a news. How will the bot know which work in the sentence he should use to search for news? This item that he should search about is called the Entity. Example, from the sentence search for news about Mauritius. Mauritius will be the entity.
Now that you understand the basic concepts of LUIS, let’s go and create your LUIS application. 

Creating a LUIS App

To create a LUIS application, go to, register and click on create a new App.

Once you click on new app, you will get screen below to add the basic application details.

Once you click create, you are redirected to the bot dashboard where you can see statistics about the bot.

In this example, we’ll create a bot that allows us to search for news, register for news and get help.
Later in this article, we’ll build and enhance the bot to understand the sentiment of the news, therefore our bot will be able to detect whether a news has a positive or negative sentiment.


Therefore, the bot will have 4 intents, namely, SearchNewsAskHelpRegister and None.
All LUIS application has a None intent created by default which represents any text that it cannot interpret.
Next, click on intent on the dashboard and select Add Intent to add the 4 intents.

Define the Utterances and Entities

For each of the Intents, we now need to add the Utterance and Entities. Click on each of the Intents and start adding the Utterance.
In the example below, we add the utterance “What are the news in Mauritius”.
Now, the question is, how will the bot identify what is the word he needs to search for? This is what Entities are for!
Then, from the Utterance, we select the word news which represents the entity. We need to do the same for a few utterance which will be used to train the model.

In the example below, the word Mauritius is the entity. The bot will know that it needs to search for news aboutMauritius.

We need to add a few more examples of the entities such that LUIS has enough materials to learn. Let's add other examples as below.

Now, we also need to be able to identity the good and the bad news. How will the bot know which words to identify good and bad news. For this purpose, we also need to train our bot by adding utterances referencing good and bad news.
The next step is to add the utterance and entity for other Intents such as register for news or to ask for help.

Train the model

The next step is the train the model. To do so, from the left menu, click on Train & Test and click on Train Application.
At this stage, LUIS will learn from all the information that you have entered and should now be able to identify Intents and Entities for new sentences.

Test the Application

Once the model is trained, you can now type in sample sentences and see if it find the intent and entities correctly.

As expected, when we input new sentences, the LUIS correctly identified the intent and entities.
Once done, click on publish and be able to call the LUIS app from the Bot.

Setting up the LuisDialog

Now that the LUIS service is setup, we now need to add t in the bot project to be able to recognize each intents of the user.
What will happen now is that whenever the user input a text, this will be sent to the LUIS model to identify each Intent and their Entities.
To proceed, create a new class RootDialog which implements the LusDialog Object and is specialized to handle intents and entities from LUIS

public class RootDialog : LuisDialog<object>
You also need to add the keys of your LUIS App Id and Subscription key as above. Both can be retrieved in the Publish tab of the LUIS model.
Now, it’s time to map the LUIS intents to the code in out bot. To do so, we need to add specific functions in the classRootDialog and decorate each function having the name of the intent in the LUIS model. 

Proceed with the same steps for all the other intents, also, always create the “none” intent for cases the LUIS model could 
not map the utterance to any intent.

public async Task None(IDialogContext context, LuisResult result)
public async Task Help(IDialogContext context, LuisResult result)
public async Task Subscribe(IDialogContext context, LuisResult result)

Let’s see how the bots behave. As you run the program and ask the bots questions related to the intents, you will see that the bot will now reach the code as per the intent and the entities.


In this article, the use of LUIS to add language capability to the bot has been demonstrated. As discussed, with Microsoft Cognitive Services, it's very easy to add "intelligence" to Apps. In the next article, we'll discuss how we can leverage on the Bing News API, make the bot fetch news from the internet just by asking it using plain English.


a. Understanding Natural Language - LUIS 


Popular posts from this blog

Creating and Querying Microsoft Azure DocumentDB

DocumentDB is the latest storage option added to Microsoft Azure.
It is a no-sql storage service that stores JSON documents natively and provides indexing capabilities along with other interesting features.

This article is available available on theMicrosoft Technet Wiki. This article was highlighted in theTop Contributor awardson the 12th of October 2014. This article was highlighted in the TNWiki Article Spotlight. This article was highlighted in the The Microsoft TechNet Guru Awards! (October 2014).

DocumentDB is the latest storage option added to Microsoft Azure.
It is a no-sql storage service that stores JSON documents natively and provides indexing capabilities along with other interesting features.
This wiki shall introduce you to this new service.

Setting up a Microsoft Azure DocumentDBGo to the new Microsoft Azure Portal. 

 Click on New > DocumentDB

Enter A Database ID and hit Create!

Query Unstructured Data From SQL Server Using PolyBase

Scope The following article demonstrates how unstructured data and relational data can be queried, joined and processed in a single query using PolyBase, a new feature in SQL Server 2016. Pre-RequisitesIntroduction to Big Data Analytics Using Microsoft Azure Big Data Analytics Using Hive on Microsoft Azure Analyze Twitter Data With Hive in Azure HDInsight Running Hadoop on Linux using Azure HDInsight  Introduction Traditionally, Big Data is processed using Apache Hadoop which is totally fine. But what if the result of this needs to be linked to the traditional Relation Database? For example, assume that from the analysis of tons of application logs, marketing needs to contact some customs that faced problems in an application following a failure in the application.
This problem is solved with PolyBase. PolyBase allows you to use Transact-SQL (T-SQL) statements to access data stored in Hadoop or Azure Blob Storage and query it in an ad-hoc fashion. It also lets you query semi-structure…

Creating and Deploying Microsoft Azure WebJobs

Azure WebJobs enables you to run programs or scripts in your website as background processes. It runs and scales as part of Azure Web Sites.
This article focuses on the basics of WebJobs before demonstrating an example where it can be used.

This article is also available on the Mirosoft TechNet Wiki.
This article was highlighted in the The Microsoft TechNet Guru Awards! (October 2014).

What is Microsoft Azure WebJobs?
Azure WebJobs enables you to run programs or scripts in your website as background processes. It runs and scales as part of Azure Web Sites.

What Scheduling Options is supported by Microsoft Azure WebJobs? Azure WebJobs can run Continuously, On Demand or on a Schedule.
In what language/scripts are WebJobs written?
Azure WebJobs can be created using the following scripts:  .cmd, .bat, .exe (using windows cmd).ps1 (using powershell).sh (using bash).php (using php).py (using python).js (using node)In this article, the use of c# command line app shall be demonstrated.