To understand what a user is saying when writing with natural language, a simple syntax analysis is often not enough. We need tools that can analyze a phrase in its entirety and extract key concepts, often tailored to our own scope of application. For this we need tools that can provide an initial configuration, then specialized and monitored later, during development.
Among the many cognitive services provided by Microsoft Azure, LUIS is certainly one of the most interesting because it makes it simple to create a model for understanding the user’s requests, a model which can be developed and improved even by those who don’t have programming experience, thanks to an intuitive web interface.
A LUIS application allows us to analyze a request written in natural language, called Utterance, recognizing the Intent of the user, and possibly containing parameters called Entities. In practice, a model is created by deciding what are valid Intents, and providing examples for each of them. Examples that may contain one or more entities, either chosen from a prebuilt set or created expressly for our particular application domain.
An example is worth a thousand words
Let’s suppose we run our family’s ice cream shop and we want to deal with customers by chat: let’s create a LUIS application together that recognizes takeaway orders.
To create a LUIS application both an Azure account and a Language Understanding resource are needed. If you do not already have an account, you can sign up for free and take advantage of the free credit. After that, you can create the resource by following the Microsoft documentation.
After creating the resource, we can enter the LUIS console to create our application simply by choosing the name and the culture.
From the configuration panel, we can create our very first Intent: to recognize takeaway orders. We will call it TakeawayOrder. From this point, we can provide examples to instruct LUIS: phrases like “do you do takeaway?”, “I want some ice cream to pick up”, “can I order some ice cream?”, are all valid examples. It is important for the example phrases to be varied and written using natural language.
But an ice cream shop has so many flavours you can choose from! To make LUIS recognize them, we can define a new Feature.
Typing the flavours in the Values box, the suggestions box will be populated with terms related to the one already added. After we finish entering all the available flavours in our shop, let’s confirm them with Create.
We have the flavours now, but a customer could want to purchase more than one serving or flavor in a single order. To handle these cases correctly, LUIS allows us to create Machine Learned entities, which are basically entities composed of several sub-entities. In our case, we need an entity composed of two Features: flavour and number. Since we already created the former, we can create the latter by choosing it from the available prebuilt entities by clicking Add new prebuilt entity. At this point, we only need to create our IceCreamOrder entity, made up of two sub-entities.
After defining the entity, let’s return to the TakeawayOrder Intent in order to assign the Feature we’ve just created for it.
Now we just have to add example utterances containing this Feature, that will be not automatically recognized. Selecting them manually is required to allow the system to recognize them in the future.
Once we finish adding input phrases, we proceed with training and tests. In response to our request, we also receive a list of recognized features.
To summarize, our application is now capable of recognizing an Intent for takeaway orders, with the relative Entities that describe the quantity and flavour of the ice cream. Ideally, every phrase that can’t be recognized will be filed with the None Intent, but to ensure that the system is functioning correctly, it’s important to provide examples for this Intent, once again being sure that they are written in the most natural way possible.
Once our application has been tested, we want to make it available to the world. After publishing, our model will be available at a specific endpoint. We’ll then ask this model to make Predictions according to our users’ requests.
LUIS permits the simultaneous publication of two different versions of our model by using a mechanism called slot. Basically we have two slots called Production and Staging, that allow us to differentiate the production environment from the environment in which we can develop and test new features before releasing them.
In the Manage tab we can find the list of application versions. To create a new one, we only need to select a version and click on the Clone button. This way we can leave the production version untouched (published in the Production slot) and work on a new version not yet published in the Staging slot.
LUIS is available through the Microsoft SDKs or REST APIs. With both not only is it possible to predict intents, but also to modify the application in a phase called Authoring, with all the tools made available from the web portal.
Here are the official resources for further details: https://docs.microsoft.com/en-us/azure/cognitive-services/luis/developer-reference-resource#language-based-sdks
Improve the model
Once published, the application will be put to the test by the users who could formulate requests that the system doesn’t recognize. It’s important that the system is periodically assessed to ensure that it’s functioning correctly. With LUIS it is possible to review unclear requests, the ones with a low confidence score, in order to add them to the examples.
This operation is really simple: from the Build tab in LUIS we can enter Review Endpoint Utterances, where we can confirm the requests or assign them to another Intent.
The possibility for human operators to verify the outcomes is just one of the points listed by the Microsoft guidelines for Responsible AI. These principles help us understand the impact that our system has on the life of people using them, and what the common pitfalls are when developing it. If you would like to learn more about that, check out Michele’s post.
After we analyzed Natural Language Processing solutions in the previous article, we have seen how a tool like LUIS could be the next step after text analysis, essential for the interpretation of utterances and to decide what to do with the user requests.
Amazon and Google also provide ready-to-use solutions similar to LUIS, respectively called Lex and DialogFlow, although they are more focused on the development of chatbots. LUIS instead presents itself on the market as a more generic solution, usable in any context in which it is necessary to understand what a user wants and decide how to respond.
Tools like this are fundamental to a solution like the one we are developing at Ellycode, because they place emphasis on the possibility of improving the model and adapting it to the user’s domain. And if I can understand what the user is asking of me, I’m on the right path to answering correctly.
How? Keep following us!