Skip to content

Commit

Permalink
fix: check for None in SAS eval input (#7909)
Browse files Browse the repository at this point in the history
* check for None in SAS input

* Update releasenotes/notes/check-for-None-SAS-eval-0b982ccc1491ee83.yaml

---------

Co-authored-by: David S. Batista <[email protected]>
  • Loading branch information
lbux and davidsbatista committed Jun 21, 2024
1 parent f5a34d4 commit 9c45203
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions haystack/components/evaluators/sas_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ def run(self, ground_truth_answers: List[str], predicted_answers: List[str]) ->
if len(ground_truth_answers) != len(predicted_answers):
raise ValueError("The number of predictions and labels must be the same.")

if any(answer is None for answer in predicted_answers):
raise ValueError("Predicted answers must not contain None values.")

if len(predicted_answers) == 0:
return {"score": 0.0, "individual_scores": [0.0]}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
`SASEvaluator` now raises a `ValueError` if a `None` value is contained in the `predicted_answers` input.
15 changes: 15 additions & 0 deletions test/components/evaluators/test_sas_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ def test_run_with_different_lengths(self):
with pytest.raises(ValueError):
evaluator.run(ground_truth_answers=ground_truths, predicted_answers=predictions)

def test_run_with_none_in_predictions(self):
evaluator = SASEvaluator()
ground_truths = [
"A construction budget of US $2.3 billion",
"The Eiffel Tower, completed in 1889, symbolizes Paris's cultural magnificence.",
"The Meiji Restoration in 1868 transformed Japan into a modernized world power.",
]
predictions = [
"A construction budget of US $2.3 billion",
None,
"The Meiji Restoration in 1868 transformed Japan into a modernized world power.",
]
with pytest.raises(ValueError):
evaluator.run(ground_truth_answers=ground_truths, predicted_answers=predictions)

def test_run_not_warmed_up(self):
evaluator = SASEvaluator()
ground_truths = [
Expand Down

0 comments on commit 9c45203

Please sign in to comment.