【问题标题】:Luis choosing between two intent路易斯在两种意图之间做出选择
【发布时间】:2018-08-03 01:31:06
【问题描述】:

如果对话的 luis 最高意图得分是 0.15,第二个是 0.14,机器人是否可以询问用户他们是指第一个意图还是第二个意图?如果是的话怎么做?我一直在搜索文档示例,似乎没有任何解决方案,只是发出越来越多的话语,所以这不会发生;对吗?

【问题讨论】:

  • the luis highest intent score for a conversation is 0.15, and the second is 0.14 您能否分享您在 LUIS 应用中定义和创建的意图和实体的详细信息?
  • 我的 LUIS 应用程序中有太多意图,但我认为这是因为我的 3 个意图与支付某些东西(财产、税收、图书馆服务)有关,结果是 0.11 和 0.09。虽然实体明智,但在这 3 上没有任何内容,只是一个话语。虽然甚至有可能让机器人重新询问用户吗?
  • 您好@user3646742,我创建了一个示例来满足您的要求,请参考我的回复。

标签: c# botframework microsoft-cognitive azure-language-understanding


【解决方案1】:

如果对话的 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);
    }
} 

测试结果:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-25
    • 2020-06-30
    • 2013-06-03
    • 2017-12-26
    • 1970-01-01
    • 2011-11-03
    相关资源
    最近更新 更多