LUIS Intents and Entities

LUIS is Microsofts's Natural Language Processing offering. It supports a wide variety of European and Asian languages. Full documentation is available on the LUIS site.

Before attempting to work with LUIS's entities, make sure you have a solid understanding of how Slots and Intent and Entity Mapping work.

Before linking up your intents and entities, be sure to first connect your LUIS agent's Cloud Configuration to your bot.

The first step is to fetch your agent's intent names. To do this, launch LUIS, select the agent whose intents you are using and click Build in the side navigation.

LUIS Intents list

*A LUIS agent with 3 intents.*

Here you can see all the intents associated with this agent. These are the intent names you will need to use in the Stackchat Bot Builder.

To trigger navigation to a Stackchat flow when this intent is detected, open the Configure AI dialogue for the Flow you want to navigate to.

LUIS AI Configuration Location

*The Configure AI button in the Graph View.*

In the overlay, add the intent name from LUIS that you want to map to the Flow. Be sure to copy it exactly, as it is case-sensitive.

Copy Intent from LUIS

*An exact match including case is required.*

Paste the intent name into your desired location in Stackchat.

LUIS Paste Intent to Stackchat

*An exact match achieved.*

Now, you can enter the entities associated with that intent.

Whereas intents represent the user's overall intention in their utterance, entities represent key words in the utterance that we want to extract. There are two types of entities in Dialogflow, custom entities (those created by you in a variety of formats such as list, composite, simple and regex entities) and system entities (pre-built entities provided by LUIS in order to facilitate handling the most popular common concepts).

There is no location in LUIS where you can see which entities are associated with each intent. Instead we will need to remember which entities are associated with each intent. We can see all entities associated with the agent by clicking Intent in the navigation on the left.

Custom entities are no more difficult than dealing with the intent, in that it is a one-to-one mapping between LUIS and Stackchat. For example, in the Clothing intent used above, there are three custom entities, Color, Size, and Clothing Type.

LUIS Custom Entities

*You can assign whatever name you wish to custom entities.*

Type or paste the name into Stackchat and select the Stackchat slot you wish to map it to. In this example, the Stackchat slot has the same name as the Dialogflow entity to prevent confusion.

LUIS Entity Connection to Slot

*LUIS entity names pasted into Stackchat.*

System or prebuilt entities are used by LUIS to detect standard ipnuts such as cities, dates and numbers.

The name of each prebuilt entity is determined by LUIS, and their naming conventions must be followed. It is recommended that you review the full list of LUIS Prebuilt Entities to become familiar with how they work.

LUIS has both mapping prebuilt entities, which contain primitive data, and composite prebuilt entities populated with objects.

Mapping prebuilt entities are added to Stackchat in a similar manner to custom entities. An example is the geographyV2 entity. This entity identifies cities, nations, points of interest, continents and states in utterances and is populated by a string representing the geographic unit that was detected.

LUIS Prebuilt Entity

*`geographyV2` and `datetimeV2` are both prebuilt entities.*

To map this sytem entity to a Stackchat text slot, you will need to find the proper format for the prebuilt entity and the subtypes you wish to use. The easiest way to do this is to test your bot or consult the LUIS documentation.

LUIS Test Interface

*Make sure your bot is both trained and published.*

Enter an utterance that will trigger your intent and entities. In this example of a weather intent, we will enter a simple statement that will trigger both relevant entities, "Weather Singapore today".

LUIS Test Utterance

*`geographyV2` and `datetimeV2` are both prebuilt entities.*

Click on the utterance you just made or Inspect to see details of the interaction.

LUIS Test Panel

*This will show details of LUIS ingestion.*

In this case Singapore registers as a prebuilt geographyV2 prebuilt entity, but we will need more information to map the entity in Stackchat.Then click Compare with Published. This will reveal more data about the ingestion.

LUIS Test Panel Expanded

*Publishing the agent is required for this step to work.*

Now we can see the full name of the entity type, builtin.geographyV2.countryRegion. This can be mapped into Stackchat as seen below.

LUIS Prebuilt Entity Mapped in Stackchat

*Publishing the agent is required for this step to work.*

Prebuilt composite entities (i.e those populated with an object) have more than one piece of information that can be mapped to Stackchat slots. These require a different slot configuration.

From the intent we have been looking at so far, an example of a prebuilt composite entity is datetimeV2 for a date range. This includes two pieces of data, a start and end date.

In this case, I've said to the bot "Weather Chicago next week". We can then return to the published view as seen below.

LUIS Prebuilt Composite Entity Mapped

*Here we can see that it identifies as `builtin.datetimeV2.daterange`.*

However, this is not enough information, as we have two parts. To see them, click Show JSON View. This will show the raw JSON output from the API.

LUIS Prebuilt Composite Entity JSON Response

*Dig in here to see the real output.*

Once selected, we can see the two components of the entity.

LUIS Prebuilt Composite Entity JSON Response

*Here we see a start and end.*

Now it is just a matter of properly formatting the start and end subtypes to place in Stackchat. We will need both the type name, in this case, builtin.datetimeV2.daterange and the subtype. We need a connector between the two, which for LUIS is :: We can then map them to two separate slots as seen below.

LUIS Prebuilt Composite Entity in Stackchat

*The full names are `builtin.datetimeV2.daterange::start` and `builtin.datetimeV2.daterange::end`.*

The format will always be {LUIS Prebuilt Entity Type}::{LUIS Prebuilt Entity Subtype}. Please be sure to consult the LUIS Prebuilt Entity Documentation to confirm you are using the correct Types and Subtypes.