Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in metrics loading in tasks #1487

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading