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

GH-3603: Refactor Result class to make scores argument non-optional #3638

Merged
merged 1 commit into from
Mar 15, 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
19 changes: 15 additions & 4 deletions flair/training_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,30 @@ def __init__(
self,
main_score: float,
detailed_results: str,
scores: dict,
classification_report: Optional[dict] = None,
scores: Optional[dict] = None,
) -> None:
classification_report = classification_report if classification_report is not None else {}
assert scores is not None and "loss" in scores, "No loss provided."
"""Initialize Result object for model evaluation.

Args:
main_score: The primary evaluation metric
detailed_results: Detailed evaluation results as string
scores: Dictionary containing evaluation metrics including 'loss'
classification_report: Optional classification report dictionary

Raises:
ValueError: If scores does not contain 'loss' key
"""
if "loss" not in scores:
raise ValueError("scores parameter must contain 'loss' key")

self.main_score: float = main_score
self.scores = scores
self.detailed_results: str = detailed_results
self.classification_report = classification_report if classification_report is not None else {}

@property
def loss(self):
def loss(self) -> float:
return self.scores["loss"]

def __str__(self) -> str:
Expand Down