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

Add per-task metrics #3605

Merged
merged 3 commits into from
Feb 3, 2025
Merged
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
8 changes: 7 additions & 1 deletion flair/models/multitask_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def evaluate( # type: ignore[override]
main_score = 0.0
all_detailed_results = ""
all_classification_report: dict[str, dict[str, Any]] = {}
scores: dict[Any, float] = {}

for task_id, split in batch_split.items():
result = self.tasks[task_id].evaluate(
Expand Down Expand Up @@ -194,7 +195,12 @@ def evaluate( # type: ignore[override]
)
all_classification_report[task_id] = result.classification_report

scores = {"loss": loss.item() / len(batch_split)}
# Add metrics so they will be available to _publish_eval_result.
for avg_type in ("micro avg", "macro avg"):
for metric_type in ("f1-score", "precision", "recall"):
scores[(task_id, avg_type, metric_type)] = result.classification_report[avg_type][metric_type]

scores["loss"] = loss.item() / len(batch_split)

return Result(
main_score=main_score / len(batch_split),
Expand Down