c# - Microsoft 认知服务 - 限制 Luis Api 中的意图
问题描述
我们已经开始尝试使用 Microsoft.CognitiveServices.Speech nuget 包 ( https://docs.microsoft.com/en-gb/azure/cognitive-services/speech-service/how-to-recognize-intents-from-speech-夏普)。这很棒,因为它允许建立语言模型,并且您可以特别包含要匹配的意图:
// Creates a Language Understanding model using the app id, and adds specific intents from your model
var model = LanguageUnderstandingModel.FromAppId("YourLanguageUnderstandingAppId");
recognizer.AddIntent(model, "YourLanguageUnderstandingIntentName1", "id1");
recognizer.AddIntent(model, "YourLanguageUnderstandingIntentName2", "id2");
recognizer.AddIntent(model, "YourLanguageUnderstandingIntentName3", "any-IntentId-here");
但是,我们正在构建一个 API 并将传递文本,这将使用 API 端点调用 Luis,这是非常基本的,如下所示:
using (var client = new HttpClient())
{
var queryString = HttpUtility.ParseQueryString(String.Empty);
// The request header contains your subscription key
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", _cognitiveSettings.SubscriptionKey);
// The "q" parameter contains the utterance to send to LUIS
queryString["q"] = query;
// These optional request parameters are set to their default values
queryString["staging"] = _cognitiveSettings.IsProduction ? bool.FalseString : bool.TrueString;
queryString["timezoneOffset"] = "0";
queryString["verbose"] = "true";
queryString["spellCheck"] = "false";
var endpointUri = $"https://westeurope.api.cognitive.microsoft.com/luis/v2.0/apps/{_luisAppId}?{queryString}";
var response = await client.GetAsync(endpointUri);
var responseJson = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<IntentResponseModel>(responseJson);
}
有没有办法控制我们希望为特定文本字符串返回的意图?我们可以将 verbose 设置为 true,以便它返回具有匹配评级的所有意图,但我们希望能够根据状态指定意图的子集并尝试匹配这些意图。看来您可以使用音频使用 SDK 来做到这一点,这可以使用文本来完成(是否有文本 SDK?)。
此外,是否有办法让 JSON 中返回的实体与填充它们的意图相匹配,看起来意图和实体之间没有链接。
解决方案
不幸的是,不,没有办法控制返回的意图。在应用程序中,您需要过滤返回的意图以限制与特定文本字符串匹配的内容。