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

Fix LowScoreVariation and add return types [PORT] #2266

Merged
merged 4 commits into from
Jun 30, 2020
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions libraries/botbuilder-ai/src/qnamaker-utils/activeLearningUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

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

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

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

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

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

/**
Expand All @@ -26,31 +26,36 @@ const MaximumScoreForLowScoreVariation = 95.0;
* @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 {
/**
* Returns list of qnaSearch results which have low score variation.
* @param {QnAMakerResult[]} qnaSearchResults A list of results returned from the QnA getAnswer call.
* @returns List of filtered qnaSearch results.
*/
public static getLowScoreVariation(qnaSearchResults: QnAMakerResult[]){

if (qnaSearchResults == null || qnaSearchResults.length == 0){
public static getLowScoreVariation(qnaSearchResults: QnAMakerResult[]): QnAMakerResult[] {
if (qnaSearchResults == null || qnaSearchResults.length == 0) {
return [];
}

if(qnaSearchResults.length == 1){
if (qnaSearchResults.length == 1) {
return qnaSearchResults;
}

var filteredQnaSearchResult = [];
var topAnswerScore = qnaSearchResults[0].score * 100;
var prevScore = topAnswerScore;
let filteredQnaSearchResult = [];
let topAnswerScore = qnaSearchResults[0].score * 100;

if((topAnswerScore > MinimumScoreForLowScoreVariation) && (topAnswerScore <= MaximumScoreForLowScoreVariation)){
if (topAnswerScore > MaximumScoreForLowScoreVariation) {
filteredQnaSearchResult.push(qnaSearchResults[0]);
return filteredQnaSearchResult;
}

let prevScore = topAnswerScore;

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

for(var i = 1; i < qnaSearchResults.length; i++){
if (ActiveLearningUtils.includeForClustering(prevScore, qnaSearchResults[i].score * 100, PreviousLowScoreVariationMultiplier) && this.includeForClustering(topAnswerScore, qnaSearchResults[i].score * 100, MaxLowScoreVariationMultiplier)){
for (let i = 1; i < qnaSearchResults.length; i++) {
if (ActiveLearningUtils.includeForClustering(prevScore, qnaSearchResults[i].score * 100, PreviousLowScoreVariationMultiplier) && this.includeForClustering(topAnswerScore, qnaSearchResults[i].score * 100, MaxLowScoreVariationMultiplier)) {
prevScore = qnaSearchResults[i].score * 100;
filteredQnaSearchResult.push(qnaSearchResults[i]);
}
Expand All @@ -61,8 +66,7 @@ export class ActiveLearningUtils {
}


private static includeForClustering(prevScore, currentScore, multiplier)
{
private static includeForClustering(prevScore, currentScore, multiplier): boolean {
return (prevScore - currentScore) < (multiplier * Math.sqrt(prevScore));
}
}