Skip to content

Commit

Permalink
Fix bug in metrics loading in tasks (#1487)
Browse files Browse the repository at this point in the history
Signed-off-by: elronbandel <[email protected]>
  • Loading branch information
elronbandel authored Jan 7, 2025
1 parent 07892a8 commit 83a2d28
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/unitxt/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class Task(InstanceOperator, ArtifactFetcherMixin):

def prepare_args(self):
super().prepare_args()
if isinstance(self.metrics, str):
self.metrics = [self.metrics]

if self.input_fields is not None and self.inputs is not None:
raise UnitxtError(
Expand Down
11 changes: 11 additions & 0 deletions tests/library/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any, Dict, List

from unitxt.catalog import get_from_catalog
from unitxt.error_utils import UnitxtError
from unitxt.task import Task

Expand All @@ -26,6 +27,16 @@ def test_task_metrics_type_checking(self):
str(e.exception),
)

def test_single_metric_string_loading(self):
task = get_from_catalog("tasks.qa.with_context[metrics=metrics.rouge]")
self.assertListEqual(task.metrics, ["metrics.rouge"])

def test_multiple_metrics_string_loading(self):
task = get_from_catalog(
"tasks.qa.with_context[metrics=[metrics.rouge, metrics.bleu]]"
)
self.assertListEqual(task.metrics, ["metrics.rouge", "metrics.bleu"])

def test_task_metrics_type_checking_with_inputs_outputs(self):
operator = Task(
inputs={"input": str},
Expand Down

0 comments on commit 83a2d28

Please sign in to comment.