Chapter 4. Letting Applications Understand Commands

"LUIS saved us tremendous time while going from a prototype to production."

- Eyal Yavor, Cofounder and CTO of Meekan

Throughout the previous chapters, we have focused on vision APIs. Starting with this chapter, we will move on to language APIs, where we will start with the Language Understanding Intelligent Service (LUIS). Throughout this chapter, you will learn how to create and maintain language-understanding models.

By the end of this chapter, we will have covered the following topics:

  • Creating language-understanding models
  • Handling common requests using prebuilt models from Bing and Cortana

Creating language-understanding models

Sometimes, we might wish that our computer could understand what we want. As we go on with our day-to-day business, we want to be able to talk to our computer, or mobile phone, using regular sentences. This is hard to do without any extra help.

Utilizing the power of LUIS, we can now solve this problem. By creating language-understanding models, we can allow applications to understand what users want. We can also recognize key data, which is, typically, data that you want to be part of a query or command. If you are asking for the latest news on a certain issue, then the key data would be the topic of the news that you are asking for.

Creating an application

To get started with LUIS, you should head over to https://www.luis.ai. This is where we will set up our application. Click on the Sign in or create an account button to get started.

Let's create our first application. Click on My Apps from the top menu. This should take you back to the application list, which should be empty. Click on New App.

In the form that is shown, we fill in the given information about our application. We are required to give the application a name. We also need to indicate an atypical usage scenario, which will be set by default to Other (please specify). Instead, set this to SmartHouseApplication. This application falls under the Tools domain. We will choose an English Application Culture.

The other languages that are available are Brazilian, Portuguese, Chinese, French, German, Italian, Japanese, and Spanish.

The following screenshot shows how we can define the application:

Creating an application

When you click on the Create button, the application will be created. This process will take about a minute or so to complete, so just be patient.

When the application has been created, you will be taken to the application's home base, as shown in the following screenshot:

Creating an application

As you can see, we have a variety of features to use, and we will cover the important ones here.

The application we will build will be aimed at our smart house application. We will configure the application to recognize commands to set the temperature in different rooms. In addition, we would like it to tell us what the temperatures in the different rooms are.

Recognizing key data using entities

One of the key features of LUIS is the ability to recognize key data in sentences. The instances of this key data are known as entities. In a news application, an example of an entity would be the topic. If we ask to get the latest news, we could specify a topic for the service to recognize.

For our application, we want to add an entity for our rooms. We do this by selecting Entities in the left-hand pane. Then we click on Add custom entity.

We will be presented with the following screen:

Recognizing key data using entities

Enter the name of the entity and click on the Save button. That's it—you have now created the first entity. We will see how to use this in a bit.

As you may have noticed, there is a drop-down list called Entity type in the entity creation form. Entity types are a way to create hierarchical entities, which is basically about defining relationships between entities.

As an example, you can imagine searching for news inside a given time frame. The generic top-level entity is Date. Going from there, you can define two children, StartDate and EndDate. These will be recognized by the service, where models will be built for the entity and its children.

To add a hierarchical child entity, check the checkbox and select Hierarchical from the selection. Click on the + button next to Entity Children for each child you want to add, as shown in the following screenshot. Enter the name of the child:

Recognizing key data using entities

The other types of entities you can add are called composite entities. This is a type of entity that is formed by a set of existing entities. This is what we would call a has-a relationship, so the components are children, but not in a parent-child relationship.

Composite entities do not share common traits as hierarchical entities do. When deleting the top-level entity, you do not delete components. Using composite entities, LUIS can identify groups of entities, which are then treated as a single entity.

Using composite entities is like ordering a pizza. You can order a pizza by stating I want a large pizza with mushrooms and pepperoni. In this example, we can see the size as an entity, and we can also see the two toppings as entities. Combining these could make a composite entity, which is called an order.

The last type of entity you can add is called a list entity. This is a customized list of entity values to be used as keywords or identifiers within utterances.

When using entities, there may be times where an entity consists of several words. In our case, with the Rooms entity, we may ask for the living room. To be able to identify such phrasings, we can define a feature list. This is a comma-separated list that can contain some or all of the expected phrases.

Let's add one for our application. On the left-hand side, at the bottom of the pane, you will see Features. Select this and click on Add phrase list to create a new list. Call it Rooms and add the different rooms that you would expect to find in a house, as shown in the following screenshot:

Recognizing key data using entities

By clicking on Recommend on the right-hand side, LUIS will recommend more values related to the ones you have already entered.

We will see how this is utilized later.

In addition to creating phrase lists, we can create pattern features. The typical use case of using pattern features is when you have data that matches patterns but it is not feasible to enter them as a phrase list. Pattern features are typically used with product numbers.

Understanding what the user wants using intents

Now that we have defined an entity, it is time to see how it fits in with intents. An intent is basically the purpose of a sentence.

We can add intents to our application by selecting the Intents option in the left-hand pane. Click on Add intent. When we add an intent, we give it a name. The name should be descriptive of what the intent is. We want to add an intent named GetRoomTemperature, where the goal is to get the temperature of a given room, as shown in the following screenshot:

Understanding what the user wants using intents

When you click on the Save button, you will be taken to the utterance page. Here, we can add sentences that we can use for the intent, so let's add one. Enter what is the temperature in the kitchen? and press Enter. The sentence (or utterance, as it is called) will be ready for labeling. Labeling an utterance means that we define what intent it belongs to. We should also make sure that we mark entities with the correct type.

The following screenshot shows the labeling process for our first utterance:

Understanding what the user wants using intents

As you can see, the entity is marked. You can tell LUIS that a word is a given entity by clicking on the word. This will pop up a menu containing all the available entities, and you can then select the correct one. Also, note how the GetRoomTemperature intent is selected in the drop-down list. Click Train once you are done labeling your utterances.

All applications are created with a default intent called None. This intent will encompass sentences that do not belong to our application at all. If we were to say Order a large pizza with mushrooms and pepperoni, this would end up with None as the intent.

When you are creating intents, you should define at least three to five utterances. This will give LUIS something to work with, and, as such, it can create better models. We will see how we can improve performance later in this chapter.

Simplifying development using prebuilt models

Building entities and intents can be easy or it can be intricate. Fortunately, LUIS provides a set of prebuilt entities that stem from Bing. These entities will be included in the applications, as well as on the web, while going through the labeling process.

The following table describes all the available prebuilt entities:

Entity

Example

builtin.number

Five, 23.21

builtin.ordinal

Second, 3rd

builtin.temperature

2 degrees Celsius, 104 F

builtin.dimension

231 square kilometers

builtin.age

27 years old

builtin.geography

City, country, point of interest

builtin.encyclopedia

Person, organization, event, TV episode, product, film, and so on

builtin.datetime

Date, time, duration, set

The last three have several subentities, as described in the Example column of the table.

We are going to add one of these prebuilt entities, so select Entities in the menu. Click on Add prebuilt entity, select temperature from the list, and click on Save.

With the newly created entity, we want to add a new intent called SetTemperature. If the example utterance is Set the temperature in the kitchen to 22 degrees Celsius, we can label the utterance as shown in the following screenshot:

Simplifying development using prebuilt models

As you can see, we have a room entity. We also have the prebuilt temperature entity clearly labeled. As the correct intent should be selected in the drop-down menu, we can click on the Train button to save the utterance.

Prebuilt domains

In addition to using prebuilt entities, we can use prebuilt domains. These are entities and intents that already exist, leveraging commonly used intents and entities from different domains. By using these intents and entities, you can use models that you would typically use in Windows. A very basic example is setting up appointments in the calendar.

To use Cortana's prebuilt domain, you can select Prebuilt domains from the left-hand menu. This will open a list of available domains. By clicking Add domain, you can add the selected domain, as shown in the following screenshot:

Prebuilt domains

This will add the intents and entities for that specific domain to the list of intents and entities that is already defined, as shown in the following screenshot:

Prebuilt domains

The following list shows the top-level domains that are available with Cortana's prebuilt domains. For a complete list of the available prebuilt domains, please refer to Appendix A, LUIS Entities:

  • Calendar
  • Camera
  • Communication
  • Entertainment
  • Events
  • Fitness
  • Gaming
  • HomeAutomation
  • MovieTickets
  • Music
  • Note
  • OnDevice
  • Places
  • Reminder
  • RestaurantReservation
  • Taxi
  • Translate
  • Utilities
  • Weather
  • Web
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.123.147