1

Lets assume LUIS app with 100 intents. How can I retrieve popular top ten intent names(predicted as the top scoring intent) along with endpoint hit count?

I want to show something like this on UI. enter image description here

dd619
  • 5,910
  • 8
  • 35
  • 60
  • So you're saying you're building an app with a GUI and you want it to display the number of times each intent has been predicted as the top intent? Remember what happens when your LUIS endpoint is hit. An endpoint hit is not intrinsically associated with an intent from LUIS's perspective. LUIS just gives a score to each intent based on the provided utterance. It's up to the client to decide what to do with those results, so any concept of a LUIS call having one specific intent would be from the client's perspective. Therefore you may have to log your own telemetry for this. Would that be okay? – Kyle Delaney Nov 20 '19 at 18:20
  • You are right. I want to "display the number of times each intent has been predicted as the top intent" and i may need to add extra code for that. – dd619 Nov 21 '19 at 08:54
  • Is my answer acceptable? – Kyle Delaney Nov 26 '19 at 00:53
  • @KyleDelaney using your answer i can download the logs but it requires to count prediction endpoint by myself manually. – dd619 Nov 26 '19 at 11:17
  • No, you would write a query that counts the predictions automatically. Why would you do it manually? – Kyle Delaney Nov 26 '19 at 17:38
  • ohh...inline api query.....upvoted your answer. Can you please provide more details in your answer regarding this with example in any programming language? – dd619 Nov 27 '19 at 05:12

2 Answers2

1

Microsoft has a tutorial to add LUIS data to Application Insights (nodejs, but I'm sure you can find/do something similar if you are using C#). From there, you can use Logs (Analytics) to identify the intents for each utterance and count/graph them. In my case, I removed None and NULL intents as I wanted a breakdown of recognized intents only, but you could leave out those lines if you want to see everything. The "take" operator gives you the first n rows. Make sure you sort first or it won't necessarily be the top n.

requests
| where url endswith "messages"
| where timestamp > ago(30d)
| project timestamp, duration, performanceBucket, resultCode, url, id
| parse kind = regex url with *"(?i)http://"botName".azurewebsites.net/api/messages"
| join kind= inner (
traces | extend id = operation_ParentId
) on id
| where message == "LUIS"
| extend topIntent = tostring(customDimensions.LUIS_luisResponse_luisResult_topScoringIntent_intent)
| where topIntent != "None"
| where topIntent != ""
| summarize count() by topIntent
| order by count_ desc
| take 10

Here is the resulting table. I actually like to render piechart for mine, but I made this one a table of top 10 to fit your requirement.

enter image description here

If this isn't what you're after, let me know and I'll try to assist further.

billoverton
  • 2,705
  • 2
  • 9
  • 32
1

It turns out LUIS actually does have a way of recording intent predictions for you. As long as you call your prediction endpoint with the log parameter set to true, the query results will be logged. The v2 API says log is true by default, though my testing indicates that you have to explicitly set log to true for the v3 prediction endpoint.

You can retrieve those logs using this v2 API or this v3 API and then you can query the data from there. Here's a C# 8.0 example with some code borrowed from this answer:

// Get LUIS logs
using var luis = new LUISAuthoringClient(new Microsoft.Azure.CognitiveServices
    .Language.LUIS.Authoring.ApiKeyServiceClientCredentials(YOUR_AUTHORING_KEY))
{
    Endpoint = $"https://{YOUR_AUTHORING_REGION}.api.cognitive.microsoft.com"
};

using var stream = await luis.Apps.DownloadQueryLogsAsync(new Guid(YOUR_LUIS_APP_ID));
using var parser = new TextFieldParser(stream);

parser.SetDelimiters(",");

// The first row should be something like:
// Query,UTC DateTime,Response,SecondaryId,Region
var csvHeaders = parser.ReadFields();
var responseColumn = Array.IndexOf(csvHeaders, "Response");
var intentCount = new Dictionary<string, int>();

while (!parser.EndOfData)
{
    // Process row
    var fields = parser.ReadFields();
    var responseObject = JObject.Parse(fields[responseColumn]);
    var topIntent = responseObject["prediction"]["topIntent"].ToString();

    if (!intentCount.TryGetValue(topIntent, out var count))
    {
        count = 0;
    }

    intentCount[topIntent] = ++count;
}

// Query processed logs
var top10 = intentCount.OrderByDescending(kvp => kvp.Value).Take(10);

// Example output: [["Greeting",5],["None",3],["Cancel",1],["Help",1]]
Console.WriteLine(JsonConvert.SerializeObject(top10
    .Select(kvp => new object[] { kvp.Key, kvp.Value })));
Kyle Delaney
  • 11,616
  • 6
  • 39
  • 66