Luis在两种意图之间做出选择

3
如果一次会话中Luis的最高意图分数为0.15,第二高的为0.14,那么机器人是否可以询问用户他们是否指的是第一个意图还是第二个意图?如果可以,如何实现?我已经在文档示例中搜索了很久,似乎除了不断制作更多的话语以避免出现这种情况之外,没有其他解决方案;这是正确的吗?

Luis 对话的最高意图分数为0.15,第二个是0.14。您能分享一下您在 LUIS 应用程序中定义和创建的意图和实体的详细信息吗? - Fei Han
我的 LUIS 应用程序中有太多意图,但我认为这是因为我的 3 个意图涉及支付某些东西(财产、税收、图书馆服务),结果为 0.11 和 0.09。然而,就实体而言,在这三个意图上没有任何东西,只是一个话语。不过,让机器人重新询问用户是否可能? - user3646742
嗨@user3646742,我创建了一个示例以满足您的要求,请查看我的回复。 - Fei Han
1个回答

2
如果LUIS对话的最高意图分数为0.15,第二个意图为0.14,机器人是否可以询问用户是指第一个意图还是第二个意图?是的,我们可以实现此要求。以下示例代码适用于我,您可以参考它。
[Serializable]
public class MyLuisDialog : LuisDialog<object>
{
    public MyLuisDialog() : base(new LuisService(new LuisModelAttribute("xxxxxxx", 
        "xxxxxxx", 
        domain: "westus.api.cognitive.microsoft.com")))
    {
    }


    //modify Luis request to make it return all intents instead of just the topscoring intent
    protected override LuisRequest ModifyLuisRequest(LuisRequest request)
    {
        request.Verbose = true;
        return request;
    }

    protected override async Task DispatchToIntentHandler(IDialogContext context, IAwaitable<IMessageActivity> item, IntentRecommendation bestIntent, LuisResult result)
    {

        if (bestIntent.Intent == "FindFood" || bestIntent.Intent == "BuyFood")
        {
            if (result.Intents[0].Score - result.Intents[1].Score < 0.1)
            {
                bestIntent.Intent = "FindOrBuyFood";
                bestIntent.Score = 1;
            }
        }

        await base.DispatchToIntentHandler(context, item, bestIntent, result);
    }

    [LuisIntent("Greeting")]
    public async Task GreetingIntent(IDialogContext context, LuisResult result)
    {
        await this.ShowLuisResult(context, result);
    }

    //...
    //other intent handlers
    //...

    [LuisIntent("FindFood")]
    [LuisIntent("BuyFood")]
    public async Task FoodIntent(IDialogContext context, LuisResult result)
    {
        await this.ShowLuisResult(context, result);
    }

    [LuisIntent("FindOrBuyFood")]
    public async Task FindOrBuyFoodIntent(IDialogContext context, LuisResult result)
    {
        var food = "food";

        if (result.Entities.Count() > 0)
        {
            food = result.Entities[0].Entity;
        }

        List<string> options = new List<string>() { $"Find {food}", $"Buy {food}" };

        PromptDialog.Choice(
            context: context,
            resume: ChoiceReceivedAsync,
            options: options,
            prompt: "Hi. Please Select one option :",
            retry: "Please try again.",
            promptStyle: PromptStyle.Auto
            );
    }

    private async Task ChoiceReceivedAsync(IDialogContext context, IAwaitable<object> result)
    {
        var option = await result;

        //your code logic here

        await context.PostAsync($"You selected the '{option}'");

        context.Wait(MessageReceived);
    }

    private async Task ShowLuisResult(IDialogContext context, LuisResult result)
    {
        await context.PostAsync($"You have reached {result.Intents[0].Intent} intent.");
        context.Wait(MessageReceived);
    }
} 

测试结果:

在此输入图片描述


(注:本文为IT技术相关内容,翻译时需注意专业术语的准确性和易懂性)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接