From f072abeba0e28401788ee85afad6b0ddca173a95 Mon Sep 17 00:00:00 2001
From: Maximilian Kimmich <maximilian.kimmich@ims.uni-stuttgart.de>
Date: Tue, 1 Oct 2024 16:22:07 +0200
Subject: [PATCH] Update response parsing to use the first match

---
 evoprompt/task/question_answering.py  | 4 ++--
 evoprompt/task/text_classification.py | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/evoprompt/task/question_answering.py b/evoprompt/task/question_answering.py
index 7df612b..6266c86 100644
--- a/evoprompt/task/question_answering.py
+++ b/evoprompt/task/question_answering.py
@@ -107,14 +107,14 @@ class QuestionAnswering(Task):
         # otherwise the answer is from the context as enforced by the grammar
         prefix_to_match = self._get_prediction_prefix().replace(" ", r"\s?")
         matches = re.findall(
-            # regex that matches class labels after "Response: "
+            # regex that matches class labels after prediction prefix
             rf"(?:{prefix_to_match})?(.+)",
             response.splitlines()[-1],
             flags=re.IGNORECASE,
         )
         # look for an answer in the response, if not found, use whole response
         if matches:
-            return matches[-1]
+            return matches[0]
         else:
             return response
 
diff --git a/evoprompt/task/text_classification.py b/evoprompt/task/text_classification.py
index 6e1eae1..af30f15 100644
--- a/evoprompt/task/text_classification.py
+++ b/evoprompt/task/text_classification.py
@@ -28,7 +28,7 @@ class TextClassification(Task):
                 flags=re.IGNORECASE,
             )
             if matches:
-                return matches[-1]
+                return matches[0]
             else:
                 # look for a label in the response, if not found, return failed
                 matches = re.findall(
-- 
GitLab