What is LUIS? LUIS is a service provided by Microsoft that allows your bot to understand, interpret, and recognize what the user is conveying. With this service, your bot can understand intents and trigger the appropriate response.

Before we begin experimenting with LUIS, let us first understand its basic concepts:

  • Utterance – what the user says / textual input
  • Intent – what action the user wants to do
  • Entity – what the user is referring to

To better understand, let’s have some sample:

UtteranceIntentEntity
Utterance
Give me a quote for the TV
GiveQuoteTV
Send the file to JoeSendFileJoe
Close all pending orders tomorrow ClosePendingOrderAll, Tomorrow

Before getting into all the action, the first thing to do is to design what our bot will do.

If you need guidance on planning your app, click here. We will follow the Plan Your App steps from the LUIS documentation.

Getting Started

  1. Identify your domain.
    • For our bot, we are going to do a simple calculator bot.
    • It will handle addition, subtraction, multiplication and division.
    • We will use LUIS to identify the user’s intent and entities/integers within the utterances.
  2. Identify your intents.
    • We have the following intents:
      •  Addition
      • Subtraction
      • Multiplication
      • Division
  1. Identify your entities.
    • We will use the prebuilt Number entity.

Setting Up LUIS

  1. Go to the LUIS portal, register, then sign in.
  2. Once you have successfully registered and signed-in, go to the My Apps tab and click New App.

  1. Fill in the Name and Culture fields.

  1. On the left pane, click Entities.

  1. Click Add prebuilt entity.

  1. Select number from the list, then click save.

  1. Your prebuilt entity will be created in the Entities list. Next, click Intents.

  1. Add 4 Intents (Addition, Subtraction, Multiplication, Division) and add Utterances similar to the one below:

NOTE: When you type an utterance, i.e. 1 plus 2, the numbers will automatically be labelled as entities. (For custom entities, you must manually label them.)

NOTE: There are some instances when the prebuilt entities are not automatically labelled. If that happens, click Train & Test on the left pane, then go back to the instances.

  1. You should have 5 intents including None.

  1. Click Train & Test, then click Train Application.
  2. Type Utterances on the left pane and you should see how the intents are recognized and scored on the right pane.

  1. Once you’re happy with the results, click Publish App on the left pane, then click Publish.
    • For the time being, we will be using the BootstrapKey which is for experimental use.

  1. Once you have published your app, copy the Endpoint URL. You will need this later.

  1. Copy the Endpoint URL in a browser address bar, and append a sample utterance. You will get the top scoring intent as recognized by LUIS along with the entities that have been detected.

  1. Let’s create a new Dialog that will use LUIS intents.
    • Get App ID by going to your LUIS app.

  • Get your API Key by clicking the My Keys tab and copying the Programmatic API Key.

  • Create a new Dialog named LUISDialog.cs and paste the code below.

  • In the LuisModel attribute of the class, add the Application ID and the Programmatic API Key
  • The LUISDialog should inherit from the Microsoft.Bot.Builder.Dialogs.LuisDialog
  • The LUISDialog should have a Serializable attribute.
  • The methods that will handle the intents from LUIS should have the LuisIntent attribute and should accept IDialogContext and Microsoft.Bot.Builder.Luis.Models.LuisResult
  1. Update the MessagesController.cs to use the newly created LUISDialog.

 

Let’s try it!