Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make QnA Maker Active Learnings Thresholds user settable #2508

Merged
merged 8 commits into from
Aug 6, 2020
Merged
4 changes: 2 additions & 2 deletions libraries/botbuilder-ai/src/qnaMakerDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { RankerTypes } from './qnamaker-interfaces/rankerTypes';
import { QnAMaker, QnAMakerResult } from './';
import { FeedbackRecord, FeedbackRecords, QnAMakerMetadata } from './qnamaker-interfaces';
import { QnACardBuilder } from './qnaCardBuilder';
import { ActiveLearningUtils } from './qnamaker-utils/activeLearningUtils';

const V4_API_REGEX = /^https:\/\/.*\.azurewebsites\.net\/qnamaker\/?/i;

Expand Down Expand Up @@ -95,7 +96,6 @@ export class QnAMakerDialog extends WaterfallDialog {
// Dialog options parameters
private defaultCardNoMatchResponse: string = `Thanks for the feedback.`;
private defaultNoAnswer: string = `No QnAMaker answers found.`;
private maximumScoreForLowScoreVariation: number = 0.95;

private knowledgeBaseId: any;
private hostName: any;
Expand Down Expand Up @@ -254,7 +254,7 @@ export class QnAMakerDialog extends WaterfallDialog {

step.values[this.qnAData] = response.answers;

if (qnaResponse.answers.length > 0 && qnaResponse.answers[0].score <= this.maximumScoreForLowScoreVariation) {
if (qnaResponse.answers.length > 0 && qnaResponse.answers[0].score <= ActiveLearningUtils.MaximumScoreForLowScoreVariation / 100) {
qnaResponse.answers = qna.getLowScoreVariation(qnaResponse.answers);

if (isActiveLearningEnabled && qnaResponse.answers && qnaResponse.answers.length > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@

import { QnAMakerResult } from '../qnamaker-interfaces/qnamakerResult';

/** Minimum Score For Low Score Variation. */
const MinimumScoreForLowScoreVariation = 20;

/** Previous Low Score Variation Multiplier. */
const PreviousLowScoreVariationMultiplier = 0.7;

/** Max Low Score Variation Multiplier. */
const MaxLowScoreVariationMultiplier = 1.0;

/** Maximum Score For Low Score Variation. */
const MaximumScoreForLowScoreVariation = 95.0;

/**
* Generate Answer api utils class.
*
* @remarks
* This class is helper class for generate answer api, which is used to make queries to a single QnA Maker knowledge base and return the result.
*/
export class ActiveLearningUtils {
export class ActiveLearningUtils {
/** Minimum Score For Low Score Variation. */
static MinimumScoreForLowScoreVariation = 20;

/** Maximum Score For Low Score Variation. */
static MaximumScoreForLowScoreVariation = 95.0;

somigithub marked this conversation as resolved.
Show resolved Hide resolved
/**
* Returns list of qnaSearch results which have low score variation.
* @param {QnAMakerResult[]} qnaSearchResults A list of results returned from the QnA getAnswer call.
Expand All @@ -44,14 +44,14 @@ export class ActiveLearningUtils {
let filteredQnaSearchResult = [];
let topAnswerScore = qnaSearchResults[0].score * 100;

if (topAnswerScore > MaximumScoreForLowScoreVariation) {
if (topAnswerScore > ActiveLearningUtils.MaximumScoreForLowScoreVariation) {
filteredQnaSearchResult.push(qnaSearchResults[0]);
return filteredQnaSearchResult;
}

let prevScore = topAnswerScore;

if (topAnswerScore > MinimumScoreForLowScoreVariation) {
if (topAnswerScore > ActiveLearningUtils.MinimumScoreForLowScoreVariation) {
filteredQnaSearchResult.push(qnaSearchResults[0]);

for (let i = 1; i < qnaSearchResults.length; i++) {
Expand Down