Microsoft Cognitive Services | Language Understanding and Intelligence System (LUIS)

How to make applications understand human langugage

By Sagar Durgannavar, Prolatech

How often we get ourselves in a situation when you scream "Please understand me!" and there is absolute silence in the response (or "Could not understand that!" - if you are talking to a program!).

I once found myself in same situation when a customer started talking with my app and I had to tell her that my app does not understand your language. You must click buttons placed in it. "That's a boring app!" she said.

How do we make machine understand Human Language??

So here are few steps that can help your application understand human language. Lets make our applications little more interesting.

LUIS is here to help! Relax!

About Language Understanding and Intelligence System
Step 1 : What is LUIS?

LUIS is a cloud based API service from Microsoft. You teach it, then it learns it, and then oolaa! it understands what your customer speaks! LUIS is "Language Understanding". I like to call it a baby whom I will teach how to understand the language! To know more on what is LUIS, check the below link. What is LUIS?

Step 2 : Let's Begin

To make things easier, lets consider you are making an e-commerce application where a customer walks in and says "I want to buy red nike shoes". Your application needs to understand few things before it goes inside store room to find one.

1. What product customer is looking to buy?
Ans: Shoes

2. What color?
Ans: Red

3. What brand?
Ans: Nike

Step 3 : Let's look at how we can get answers to above 3 questions from a single sentence using LUIS.

I consider you have signed up/ logged in to LUIS dashboard. If not, please do it from below link

Log In to LUIS

1. Create a new app

Create LUIS Application
There are couple of things you need to know before we go further.

• Intents

• Entities

Intents are the categories of user intentions.


In our scenario, we can define intents as follows:

a. Customer says "I want to buy red nike shoes".
Intent will be let's call it "PurchaseProduct".

b. Customer says "I want to return a product that I bought".
Intent will be "ReturnProduct".

c. Customer says "I need more information about a product."
Intent will be "CustomerCare".

In other words, Intents are the features that you provide in your app that a customer intents to use.

Let's create the same in LUIS. Click on "Create new intent"

LUIS- Intent
We will just focus on 1st intent- PurchaseProduct.

Entities are the data that you want to extract from a sentence. In our scenario, we can define entities as follows:

a. ProductType
b. ProductColor
c. ProductBrand etc..

Let's create the same in LUIS. Click on "Entities" and "Create new entity"

LUIS- Entities

(Create all the other Entities here)



LUIS- All Entities

We are all set now.

Step 4: Let's start training our model.

Here we start to teach our model. We type in sentences that we feel customer might say to buy a product.

Go back to "Intents" and click on the intent you have created ("PurchaseProduct" in this scenario).

Start typing in all the sentences (In LUIS world, these sentences are referenced to as "Utterances").

Hit enter after each utterance. Keep patience and type as many utterances as you can. More the utterances, the better LUIS will learn. This will make your application more accurate in understanding your customer.

LUIS - Utterances

Hover over each word that matters to you in each utterance and mark it with the appropriate entity. I call this as Entity Marking.

LUIS- Entity Marking

Once finished, your dashboard will look as shown below.

Final LUIS Entities marked


You can now click "Train" and get yourself a coffee!! Once your coffee is over and you get a green signal on the "Train" button, you can start typing in more utterances.
You will see "magic" that for few words, LUIS will automatically start tagging proper entities. If it has not, you can continue marking words with entities as you did earlier.


LUIS is trying its best to get trained. Keep patience and you will see it keeps improving its understanding skills as time goes by. Once you are satisfied with your model, click on "Train" and "Publish".

Step 5: Testing

You can use "Test" option to check working of your model.

Once ready, click on "Publish" and follow steps to publish your application.

You can use endpoints API to send utterances to your model from your client application. Endpoint API.

Send an utterance (customer's sentence) from client application to LUIS. Below is the JSON response you will get from LUIS.



Example: Customer says "I want to buy red nike shoes"

{
"query": "I want to buy red nike shoes.", "topScoringIntent": { "intent": "PurchaseProduct", "score": 0.99 },
"entities": [
{ "entity": "red", "type": "ProductColor", "startIndex": xx, "endIndex": xx, "score": 0.98 },
{ "entity": "nike", "type": "ProductBrand", "startIndex": xx, "endIndex": xx, "score": 0.98 },
{ "entity": "shoes", "type": "ProductType", "startIndex": xx, "endIndex": xx, "score": 0.98 }
]
}

Now your application understands below things:

1. What product customer is looking to buy?
Ans: Shoes

2. What color?
Ans: Red

3. What brand?
Ans: Nike

Application is now ready to go inside store room(or database as they call it!) to get the required product. Customer will be happy to see all the red nike shoes popping up on the screen. Application is now a little more smarter :)