Once you're up with a new project with the basic template provided in the Introduction, you should be able to add a LUISRecognizer like so -
var model = '' // Your LUIS Endpoint link comes here
var recognizer = new builder.LuisRecognizer(model);
Now, recognizer
is a LUISRecognizer and can pass intents based on your defined LUIS Model. You can add the recognizer
to your intents by
var intents = new builder.IntentDialog({recognizers: [recognizer]});
Your bot is now capable of handling intents from LUIS. Any named intents on LUIS can be detected by using the matches
property of IntentDialog
class. So say, an intent named hi
is defined in the LUIS model, to recognize the intent on the bot,
intents.matches('hi', function(session) {
session.send("Hey :-)");
});
Creating a LUIS Model requires little to no programming experience. However, you need to be familiar with 2 important terms that will be used extensively.
Hi
will identify a function that needs to be executed whenever the user sends "Hi". Intents are uniquely named in your program/model.1:00 pm
is an entity that needs to be recognized by the chat-bot to set an alarm.Note: Images of the website are not provided as the front-end my change, but the core concept remains the same.
To create a new model, go to LUIS.ai and sign-in with your Microsoft Account to be taken to the app creation page. Where a blank project can be created.
Defining Intents:
Intents can be defined on the Intents
tab. They identify what function you need to perform when the user enters anything.
All applications have a default None
intent, which is activated whenever the user input matches no other intent.
To define an intent,
utterances
to the intent. Utterances are what you want the user to send in order to activate the intent that you are defining.
Try feeding as many different utterances
as possible in order for LUIS to associate intents
and utterances
properly.Train
button on Train and Test
Tab. After training the app can be tested in the panel below.Publish App
Tab. You should now get an endpoint URL that should be put in while defining LUISRecognizer
in your bot code.An entity is the information that your bot extracts from a particular utterance conforming to an intent.
Eg- Let My name is John Doe
belong to an intent called introduction
. For your bot to understand and extract the name John Doe
from the sentence, you need to define an entity which does so. You can name the entity whatever you wish, but it is best to name it as something pertaining to what it extracts. In our example, we can call our entity name
.
Entities can be re-used between different intents, to extract different things. So the best principle would be to make an entity that extracts only type of data and use it across different intents. Therefore, in our above example, say Book a flight on Emirates
belongs to the intent booking
, then the same entity, name
, can be used to extract the flight name emirates
.
You need to keep in mind two things before you go on defining entities -
Adding pre-built entities
Pre-built entities are, as the name suggests, pre-built i.e. they are already configured to extract a particular type of data across the intent they are added to. An example can be the entity number
that extracts numbers from the intent it is assigned to. The numbers can be either in numeric or alphabetical like 10
or ten
.
For a full list of all pre-built entities, you can visit [Pre-built Entities List][1].
To add pre-built entities,
entities
tab.Add pre-built entities
and select the entity you want to add to the model and hit save.Adding Custom Entities Custom Entities are of 4 types,
name
in the examples above is a simple entity.Defining Simple Entities
entities
tab.Add Custom Entities
Save
.All other type of entities can be added in the same way by just changing the Entity Type
to one of the above types. In hierarchical and composite entity types, you'll also need to give the children names along with the parent entity name. Defining List entities is a little different than the rest.
Defining List Entities
After you follow the above steps to create a List Entity
by putting th Entity Type
as List, you'll be directed to the details page of the entity you just defined.
You can also import entire lists by using an array of JSON Objects, of the form:
[
{
"canonicalForm": "Hey",
"list": [
"Howdy",
"Hi"
]
},
.
.
.
]
Associating an entity with an intent
Pre-built
and list
entities already have a set of values defined which can be extracted from all utterences, however, Simple
, Hierarchical
and Composite
utterances need to be trained to pick up values.
This can be done by
intents
tab and choose the intent you'd like to add the entity to.My name is John Doe
as an utterance.john doe
in the above example.Name
will be the entity selected in the above example.var recognizer = new builder.LUISRecognizer('Your model's URL');
var intents = new builder.IntentDialog({recognizers: [recognizer]});