Your web browser is out of date. Update your browser for more security, speed and the best experience on this site.

Update your browser
CapTech Home Page

Blog May 29, 2018

Using LUIS to Create an App with Intent Prediction and Sentiment Analysis

Ram Ramkumar

At /build/ 2018, Microsoft unveiled major updates to its conversational AI tools, making it easier than ever to build, test, and deploy bots using Azure that can run on your own servers. According to CEO Satya Nadella, there are more than 30,000 active bots that use Microsoft's AI tools sending millions of messages every day. The company's focus on delivering powerful, open-source features to its developer community has continued to effectively lower the barriers to entry for many of its AI and cloud offerings.

One of the more highly anticipated new feature launches included Microsoft's language understanding module, LUIS. LUIS now includes improved support for converting speech to intents and analyzing user intent in natural language.

A LUIS app is a language model customized to process specific natural language needs. As this model is designed and trained to process specific user intentions or intents, the app can receive utterances and extract their intended meaning. Your client app can then take the appropriate actions.

In this walkthrough, we will be setting up an app to create and manage taxi bookings that can also identify positive, neutral, and negative sentiment from utterances.

LUIS Concepts

  • Intents: an intent represents an action users want to perform. You name and define intents that correspond to these actions. For example, booking flights, ordering food, turning off the lights could be intents
  • Utterances: an utterance is text input from a user that the app needs to understand, such as "Find me an Uber" or "When is the next flight to Paris?"
  • Entities: entities are like variables in algebra, representing detailed information within the user's utterance (Paris would be a location entity within the previous utterance). LUIS helps you predict and choose the right action to take by identifying the entities in the user's input.

Sentiment Analysis

Sentiment analysis is the ability of LUIS to understand if a user's utterance is positive, neutral, or negative. LUIS returns a sentiment and a score between 0 and 1 (negative < 0.5 (neutral) < positive).

Getting Started

Navigate to the LUIS site and select Create a new app.

In the dialog box, enter Reserving a Taxi with Sentiment Analysis and select Done.

Once the app has been created, select the app to navigate to a screen displaying the intents. It should contain only the None intent.

Adding a Prebuilt Domain

LUIS gives you the option to choose from a list of Prebuilt Domains that come with their own defined intents and entities. In the left menu, select the Prebuilt Domains option.

Select Add Domain for the Taxi prebuilt domain.

Once the domain has been added, select Intents from the left menu. You should now see additional Book, Cancel, and Track intents added to the list. Select the Taxi.Book intent.

Toggle the Entities view to see the utterances provided with specific entities attached.

Locate the input box at the top, enter the following, and hit Enter.

Once the utterance has been added, click on Seattle and select Taxi.PlaceName as the Entity.

Click on Uber and select the Entity Taxi.TransportationType.

That's how simple it is to add utterances and quickly define the entities within that sample utterance.

Training LUIS

Select the Train button from the top-right of the LUIS screen. This is how the model saves the edits and changes you've made to it.

Adding Sentiment Analysis

Sentiment Analysis is activated after Publish, so select Publish from the top-right of the LUIS screen.

Select Enable Sentiment Analysis from the External Services Settings menu.

Click on Publish.

Testing the model

Select Test from the top-right menu, type in the following, and click Inspect.

You can see that the model rightly chose the top scoring intent to be the Taxi.BookIntent (with a score of 0.94). In circumstances where your model did not select the correct intent, you can always select a different intent assignment to train the model appropriately.

You will also find that Sentiment Analysis labeled this utterance as Positive with a score of 0.7914257.

Now type in the following into the test input and hit Enter. You will notice that it chose the right intent, once again, but assigned a Sentiment Analysis label of Negative with a score of 0.133285254 based on the language and specific words used in this utterance.

Querying the endpoint

From the publish screen, click on the endpoint link in the Resources and Keys section. This will open the endpoint link in a new window.

Go to the end of the URL and find the last query string parameter in the URL q, for the utterance query. Enter "get me a taxi for 5 people to the nearest coffee shop." This should return a JSON object with the Taxi.Book intent with sentiment analysis extracted.

endpoint response

Using LUIS, you have quickly set up an app that uses pre-built domain models to predict the intent of a user's utterance and extract its sentiment. With this information, your client app (such as a bot) can then make the appropriate decision.