Skip to content

Stage 4: Create and Configure LUIS

Sanoobk edited this page Sep 25, 2019 · 1 revision

Stage 4: Create and Configure LUIS

Create a basic LUIS (Language Understanding Intelligent Service) app following the Microsoft article.

  • Try steps up to testing the endpoint with a GET https request.
  • In this solution, we will reuse the 'Entities' of the 'Home Automation' prebuilt domain of LUIS.
  • Export of Utterances, Entities and Intents used for this solution is added to the source repo.
  • Utterances and Intents of 'Home Automation' prebuilt domain was deleted.
  • Import the provided luis.json file and upload via the LUIS portal Manage link. (Ensure to update the link with your Application ID)
  • Train the App and Test with some Utterances.
    • E.g. 1: "Get all blue bikes" - This should return 'BikeMike.GetLatestBikes' as the Top Scoring Intent.
    • E.g. 2: "Show list of beans" - This should return 'None' as the Top Scoring Intent.
    • Adding Utterances to Intent 'None' is important and should constitute 10-20% of the total Utterances authored.
  • Curating the Utterances, Entities and Intents is important to improve accuracy.
  • Publish the App as the final step.

Configure appsettings.json key values for LUISSettings.

Key Source Code Excerpts:

Below lines of code will fetch the LUIS response based on the user input utterance. Response is managed using dynamic objects. Strongly typed objects based on custom LUIS response Intents and Entities can also be implemented for flexibility.

private async Task<DocumentSearchResult<dynamic>> ProcessUserUtterance(string utterance)
{
dynamic LuisResponse;
var LuisIntents = new List<dynamic>();
var LuisEntities = new List<dynamic>();
var Luisquery = string.Empty;
dynamic LuisTopScoringIntent;

var response = FecthLUISResponseAsync(luisEndPoint + utterance);

Below lines of code first deserialize the LUIS response to list of dynamic objects using the Newtonsoft.json nuget package. Based on the Intent returned from LUIS, the corresponding function is called. In the below case, the intent is to search for latest bikes.

LuisIntents = (LuisResponse.intents as JArray).ToList<dynamic>();
LuisEntities = (LuisResponse.entities as JArray).ToList<dynamic>();
var SearchEntities = new List<dynamic>();

if (LuisTopScoringIntent.intent == "BikeMike.GetLatestBikes")
{
return await AzureSearchQueryRequest(LuisEntities);
}