0
votes

I have a chatbot that routes to the appropriate KB in QnAMaker based on intent. E.g. if the question is related to Project management, then it will route to the Project management KB.

My dilemma now is how to run active learning based on the intent and routing the suggestions back to the appropriate KB.

Appreciate anyone's advice on this.

I have taken the Active learning example from Microsoft to initialize the dialog in the constructor but am unable to detect the input query.

public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
        {
            // Handle Message activity type, which is the main activity type for shown within a conversational interface
            // Message activities may contain text, speech, interactive cards, and binary or unknown attachments.
            // see https://aka.ms/about-bot-activity-message to learn more about the message and other activity types
            if (turnContext.Activity.Type == ActivityTypes.Message)
            {
                DialogContext dialogContext = await _dialogs.CreateContextAsync(turnContext, cancellationToken);
                DialogTurnResult results = await dialogContext.ContinueDialogAsync(cancellationToken);
                switch (results.Status)
                {
                    case DialogTurnStatus.Cancelled:
                    case DialogTurnStatus.Empty:                    
                        await dialogContext.BeginDialogAsync(_dialogHelper.ActiveLearningDialogName, _qnaMakerOptions, cancellationToken);
                        break;
                    case DialogTurnStatus.Complete:
                        break;
                    case DialogTurnStatus.Waiting:
                        // If there is an active dialog, we don't need to do anything here.
                        break;                    
                }

                await _accessors.ConversationState.SaveChangesAsync(turnContext);
            }
            else if (turnContext.Activity.Type == ActivityTypes.ConversationUpdate)
            {
                if (turnContext.Activity.MembersAdded != null)
                {
                    // Send a welcome message to the user and tell them what actions they may perform to use this bot
                    await SendWelcomeMessageAsync(turnContext, cancellationToken);
                }
            }
            else
            {
                await turnContext.SendActivityAsync($"{turnContext.Activity.Type} event detected", cancellationToken: cancellationToken);
            }
        }

I expect the active learning result to be displayed based on the intent and routing to the correct QnA KB.

1
Could you link to the example that you are following? Also QnA Maker KBs support different types of Active Learning. You can enable implicit Active Learning for each KB in the QnA Maker Portal. You can also enable Active Learning for your LUIS Apps within the LUIS portal.Matt Stannett

1 Answers

0
votes

As Matt Stannett suggested, you should probably clarify what type of Active Learning you're using, as there's active learning for both QnA & LUIS.

You should consider looking into using Dispatch, which would route to the appropriate QnA KB, LUIS app, or other miscellaneous services it supports.

See NLP with Dispatch sample for how to link together LUIS intents and QnA Maker.

Snippet:

private async Task DispatchToTopIntentAsync(ITurnContext<IMessageActivity> turnContext, string intent, RecognizerResult recognizerResult, CancellationToken cancellationToken)
{
    switch (intent)
    {
        case "l_HomeAutomation":
            await ProcessHomeAutomationAsync(turnContext, recognizerResult.Properties["luisResult"] as LuisResult, cancellationToken);
            break;
        case "l_Weather":
            await ProcessWeatherAsync(turnContext, recognizerResult.Properties["luisResult"] as LuisResult, cancellationToken);
            break;
        case "q_sample-qna":
            await ProcessSampleQnAAsync(turnContext, cancellationToken);
            break;
        default:
            _logger.LogInformation($"Dispatch unrecognized intent: {intent}.");
            await turnContext.SendActivityAsync(MessageFactory.Text($"Dispatch unrecognized intent: {intent}."), cancellationToken);
            break;
    }
}

And then for the logic of each intent, you can process the QnA as you have already done using the active learning sample.

You can also look at the CoreBot sample to help give you ideas of how to tie in dialogs with services like LUIS (which is what Dispatch is--it's essentially a parent LUIS model that routes to children services like QnA Maker or other LUIS models connected to it)


Also, recently as of 4.5 release, the SDKs now natively support Active Learning and are no longer just in experimental:

https://github.com/Microsoft/botbuilder-dotnet/blob/master/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMaker.cs#L200

You can take a look at the unit tests to see how to call the Train API directly from your process qna intent.