New intent in LUIS for multi turn dialogs

孤街醉人 提交于 2020-07-08 00:39:20

问题


I am going to create a multi-turn dialog. I didn't get how it should be connected with LUIS models. I checked out documentation, but there are samples with only one turn dialogs. Also, I use Virtual Assistant template. I want to do something like this.

User: I want to book a flight

Bot: What is the destination?

User: London

Bot: When?

User: 21st of September.

Bot: The ticket was bought.

The questions are what happens on the second step? Should I check out dispatcher? Should I add all possible phrases for all steps inside the intent?


回答1:


General LUIS stuff

For your LUIS model you will need your intents - BookFlight and None. Under your BookFlight intent you will have your Utterances - all the phrases you want to be able to trigger the BookFlight intent.

MyLuisApp
--BookFlight
----I want to book a flight
----Book a flight
----I need a plane ticket
----etc
--None
----Utterances that don't match any of your intents

The none intent is VERY important as per this documentation.


Adding this functionality to a new bot or the core bot template

There are a couple different samples provided on how you could achieve this, but the best way is using Dialogs. What you want is a Waterfall Dialog. Inside this Dialog you can define each stage in the waterfall e.g. Ask for destination, ask for date etc.

In order to trigger the BookFlight waterfall you would have a MainDialog that handled every request, and checks with the LUIS dispatcher link1 and link2 to find out the users intent as per this example. If the intent is BookFlight then you would start the BookFlightDialog which contains the book flight waterfall.

...
// Check dispatch result
var dispatchResult = await cognitiveModels.DispatchService.RecognizeAsync<DispatchLuis>(dc.Context, CancellationToken.None);
var intent = dispatchResult.TopIntent().intent;

if (intent == "BookFlight")
{
    // Start BookFlightDialog
    await dc.BeginDialogAsync(nameof(BookFlightDialog));
}


General Waterfall Dialog stuff

You'd define your steps as something like:

var waterfallSteps = new WaterfallStep[]
{
    AskDestinationAsync,
    AskDepartureDateAsync,
    ConfirmStepAsync,
    FinishDialogAsync,
};

For your scenario there is actually a sample that has already been created with the BookFlight intent available here. There is a full guide on how to get this setup and working in the official documentation. So you can test to see how everything works then modify it as you need.

Other interesting links:

  • Custom prompt sample - roll your own.
  • Multi-turn sample - waterfall dialog.

Virtual Assistant stuff

Once you understand how the above works you will be able to modify the Virtual Assistant template to handle the BookFlight intent by taking the following actions:

  • Adding a BookFlight intent to your existing LUIS DISPATCH app that is connected to your VA template.
  • Adding utterances to the BookFlight intent.
  • Save and train your LUIS app.
  • Publish your LUIS app.
  • Running the update_cognitive_models.ps1 script as per step 3 of the instructions here which will pull down the changes (your new intent and utterances).
    • .\Deployment\Scripts\update_cognitive_models.ps1 -RemoteToLocal
      • NOTE: This command must be run using PowerShell Core and from the root of your project Directory, i.e. inside your Virtual Assistant folder.

The result of running this script should be a bunch of files created locally, as well as the DispatchLuis.cs file being updated to include your new intent. You should also check the Summary.html file that is created to see that your new intent is there. You will now have to update the VA code to actually do something when your new intent is triggered - add another if/case statement inside the RouteAsync method of the MainDialog.cs file - see here for an example.

Something like this:

MainDialog.cs

protected override async Task RouteAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
{
    // Call to dispatch to get intent

    if (intent == DispatchLuis.Intent.bookflight)
    {
        // Start BookFlightDialog
        await dc.BeginDialogAsync(nameof(BookFlightDialog));
    }
    ...
}


来源:https://stackoverflow.com/questions/56682939/new-intent-in-luis-for-multi-turn-dialogs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!