fix: check for None in SAS eval input (#7909)

* check for None in SAS input

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

---------

Co-authored-by: David S. Batista <dsbatista@gmail.com>
This commit is contained in:
Ulises M 2024-06-21 05:22:33 -07:00 committed by GitHub
parent f5a34d4d5c
commit 9c45203a76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 0 deletions

View File

@ -157,6 +157,9 @@ class SASEvaluator:
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]}

View File

@ -0,0 +1,4 @@
---
fixes:
- |
`SASEvaluator` now raises a `ValueError` if a `None` value is contained in the `predicted_answers` input.

View File

@ -73,6 +73,21 @@ class TestSASEvaluator:
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 = [