From 8dcf8fed89d8bc04b4fb1cb5313d224c84184507 Mon Sep 17 00:00:00 2001 From: Benjamin Trent <4357155+benwtrent@users.noreply.github.com> Date: Thu, 7 Jul 2022 10:17:48 -0400 Subject: [PATCH 1/3] [ML] fix NLP question_answering task when best answer is only one token --- .../xpack/ml/inference/nlp/QuestionAnsweringProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/nlp/QuestionAnsweringProcessor.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/nlp/QuestionAnsweringProcessor.java index c29e171314af1..896ba47b28549 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/nlp/QuestionAnsweringProcessor.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/nlp/QuestionAnsweringProcessor.java @@ -212,7 +212,7 @@ static void topScores( if (startNormalized[i] == 0) { continue; } - for (int j = i + 1; j < (maxAnswerLength + i) && j < tokenSize; j++) { + for (int j = i; j < (maxAnswerLength + i) && j < tokenSize; j++) { double score = startNormalized[i] * endNormalized[j]; if (score > maxScore) { maxScore = score; From 7f66d5e1446de4e3b5a41ed8f54a2abe99cf3bda Mon Sep 17 00:00:00 2001 From: Benjamin Trent Date: Thu, 7 Jul 2022 10:20:25 -0400 Subject: [PATCH 2/3] Update docs/changelog/88347.yaml --- docs/changelog/88347.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/changelog/88347.yaml diff --git a/docs/changelog/88347.yaml b/docs/changelog/88347.yaml new file mode 100644 index 0000000000000..33f19cdd079cb --- /dev/null +++ b/docs/changelog/88347.yaml @@ -0,0 +1,5 @@ +pr: 88347 +summary: Fix NLP `question_answering` task when best answer is only one token +area: Machine Learning +type: bug +issues: [] From 1f2119b2c5b11b11e55156a366dd93af40aa4ca4 Mon Sep 17 00:00:00 2001 From: Benjamin Trent <4357155+benwtrent@users.noreply.github.com> Date: Fri, 8 Jul 2022 08:56:14 -0400 Subject: [PATCH 3/3] fixing bug for split input as well --- .../xpack/ml/inference/nlp/QuestionAnsweringProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/nlp/QuestionAnsweringProcessor.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/nlp/QuestionAnsweringProcessor.java index 896ba47b28549..33b08d13c49b2 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/nlp/QuestionAnsweringProcessor.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/nlp/QuestionAnsweringProcessor.java @@ -224,7 +224,7 @@ static void topScores( return; } for (int i = seq2Start; i < tokenSize; i++) { - for (int j = i + 1; j < (maxAnswerLength + i) && j < tokenSize; j++) { + for (int j = i; j < (maxAnswerLength + i) && j < tokenSize; j++) { topScoresCollector.accept( new ScoreAndIndices(i - seq2Start, j - seq2Start, startNormalized[i] * endNormalized[j], spanIndex) );