From 942484792509495f39fa020c7eb9b501d42f0433 Mon Sep 17 00:00:00 2001 From: rokulka <36928710+rokulka@users.noreply.github.com> Date: Fri, 8 Feb 2019 22:17:20 +0530 Subject: [PATCH] QnA Maker Active Learning Samples - Remove single answer suggestion code (#1206) * Initial Commit * Review comment updates * Active Learning parameter and KB changes * Adding qnamaker-activelearning-bot entry for .NetCore * Initial Commit * Review comment updates * Adding qnamaker-activelearning-bot entry for .NetCore * Initial commit 2 * Update readme * PR comments fixed * Remove single answer suggestion code Fix - prevScore update --- .../Helpers/ActiveLearningHelper.cs | 43 +++++++------------ .../Helpers/activeLearningHelper.js | 13 ++---- 2 files changed, 18 insertions(+), 38 deletions(-) diff --git a/experimental/csharp_dotnetcore/qnamaker-activelearning-bot/Helpers/ActiveLearningHelper.cs b/experimental/csharp_dotnetcore/qnamaker-activelearning-bot/Helpers/ActiveLearningHelper.cs index 31609d7015..e3c81b7383 100644 --- a/experimental/csharp_dotnetcore/qnamaker-activelearning-bot/Helpers/ActiveLearningHelper.cs +++ b/experimental/csharp_dotnetcore/qnamaker-activelearning-bot/Helpers/ActiveLearningHelper.cs @@ -27,10 +27,6 @@ public static class ActiveLearningHelper /// private const double MaxLowScoreVariationMultiplier = 2.0; - /// - /// Max Score For Single Answer Suggestion - /// - private const double MaxScoreForSingleAnswerSuggestion = 50; /// /// Maximum Score For Low Score Variation @@ -46,45 +42,36 @@ public static List GetLowScoreVariation(List qnaSearch { var filteredQnaSearchResult = new List(); - if (qnaSearchResults == null) + if (qnaSearchResults == null || qnaSearchResults.Count == 0) { return filteredQnaSearchResult; } - if (qnaSearchResults.Count > 0) + if (qnaSearchResults.Count == 1) { - if (qnaSearchResults.Count == 1 && IsSingleAnswerSuggestion(qnaSearchResults[0].Score)) - { - filteredQnaSearchResult.Add(qnaSearchResults[0]); - return filteredQnaSearchResult; - } + return qnaSearchResults; + } - var topAnswerScore = qnaSearchResults[0].Score * 100; - var prevScore = topAnswerScore; + var topAnswerScore = qnaSearchResults[0].Score * 100; + var prevScore = topAnswerScore; - if ((topAnswerScore > MinimumScoreForLowScoreVariation) && (topAnswerScore < MaximumScoreForLowScoreVariation)) - { - filteredQnaSearchResult.Add(qnaSearchResults[0]); + if ((topAnswerScore > MinimumScoreForLowScoreVariation) && (topAnswerScore < MaximumScoreForLowScoreVariation)) + { + filteredQnaSearchResult.Add(qnaSearchResults[0]); - for (var i = 1; i < qnaSearchResults.Count; i++) + for (var i = 1; i < qnaSearchResults.Count; i++) + { + if (IncludeForClustering(prevScore, qnaSearchResults[i].Score * 100, PreviousLowScoreVariationMultiplier) && IncludeForClustering(topAnswerScore, qnaSearchResults[i].Score * 100, MaxLowScoreVariationMultiplier)) { - if (IncludeForClustering(prevScore, qnaSearchResults[i].Score * 100, PreviousLowScoreVariationMultiplier) && IncludeForClustering(topAnswerScore, qnaSearchResults[i].Score * 100, MaxLowScoreVariationMultiplier)) - { - prevScore = qnaSearchResults[i].Score; - filteredQnaSearchResult.Add(qnaSearchResults[i]); - } + prevScore = qnaSearchResults[i].Score * 100; + filteredQnaSearchResult.Add(qnaSearchResults[i]); } } } - + return filteredQnaSearchResult; } - private static bool IsSingleAnswerSuggestion(double score) - { - return (score < MaxScoreForSingleAnswerSuggestion); - } - private static bool IncludeForClustering(double prevScore, double currentScore, double multiplier) { return (prevScore - currentScore) < (multiplier * Math.Sqrt(prevScore)); diff --git a/experimental/javascript_nodejs/qnamaker-activelearning-bot/Helpers/activeLearningHelper.js b/experimental/javascript_nodejs/qnamaker-activelearning-bot/Helpers/activeLearningHelper.js index f9b1dcef12..2db2858fda 100644 --- a/experimental/javascript_nodejs/qnamaker-activelearning-bot/Helpers/activeLearningHelper.js +++ b/experimental/javascript_nodejs/qnamaker-activelearning-bot/Helpers/activeLearningHelper.js @@ -12,9 +12,6 @@ const PreviousLowScoreVariationMultiplier = 1.4; // Max Low Score Variation Multiplier const MaxLowScoreVariationMultiplier = 2.0; -// Max Score For Single Answer Suggestion -const MaxScoreForSingleAnswerSuggestion = 50; - // Maximum Score For Low Score Variation const MaximumScoreForLowScoreVariation = 95.0; @@ -30,8 +27,8 @@ class ActiveLearningHelper{ return []; } - if(qnaSearchResults.length == 1 && this.isSingleAnswerSuggestion(qnaSearchResults[0].score)){ - return qnaSearchResults[0]; + if(qnaSearchResults.length == 1){ + return qnaSearchResults; } var filteredQnaSearchResult = []; @@ -43,7 +40,7 @@ class ActiveLearningHelper{ for(var i = 1; i < qnaSearchResults.length; i++){ if (this.includeForClustering(prevScore, qnaSearchResults[i].score * 100, PreviousLowScoreVariationMultiplier) && this.includeForClustering(topAnswerScore, qnaSearchResults[i].score * 100, MaxLowScoreVariationMultiplier)){ - prevScore = qnaSearchResults[i].score; + prevScore = qnaSearchResults[i].score * 100; filteredQnaSearchResult.push(qnaSearchResults[i]); } } @@ -52,10 +49,6 @@ class ActiveLearningHelper{ return filteredQnaSearchResult; } - isSingleAnswerSuggestion(score) - { - return (score < MaxScoreForSingleAnswerSuggestion); - } includeForClustering(prevScore, currentScore, multiplier) {