Skip to content

Commit

Permalink
QnA Maker Active Learning Samples - Remove single answer suggestion c…
Browse files Browse the repository at this point in the history
…ode (#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
  • Loading branch information
rokulka authored and sgellock committed Feb 8, 2019
1 parent 54e8840 commit 9424847
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ public static class ActiveLearningHelper
/// </summary>
private const double MaxLowScoreVariationMultiplier = 2.0;

/// <summary>
/// Max Score For Single Answer Suggestion
/// </summary>
private const double MaxScoreForSingleAnswerSuggestion = 50;

/// <summary>
/// Maximum Score For Low Score Variation
Expand All @@ -46,45 +42,36 @@ public static List<QueryResult> GetLowScoreVariation(List<QueryResult> qnaSearch
{
var filteredQnaSearchResult = new List<QueryResult>();

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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 = [];
Expand All @@ -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]);
}
}
Expand All @@ -52,10 +49,6 @@ class ActiveLearningHelper{
return filteredQnaSearchResult;
}

isSingleAnswerSuggestion(score)
{
return (score < MaxScoreForSingleAnswerSuggestion);
}

includeForClustering(prevScore, currentScore, multiplier)
{
Expand Down

0 comments on commit 9424847

Please sign in to comment.