Skip to content

Commit 15be790

Browse files
committed
feat(base): add asserts and better error handling
1 parent 7cdf31b commit 15be790

File tree

1 file changed

+7
-1
lines changed
  • signwriting_evaluation/metrics

1 file changed

+7
-1
lines changed

signwriting_evaluation/metrics/base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ def score_max(self, hypothesis: str, references: list[str]) -> float:
1919

2020
def validate_corpus_score_input(self, hypotheses: list[str], references: list[list[str]]):
2121
# This method is designed to avoid mistakes in the use of the corpus_score method
22+
assert type(hypotheses) == list, "Hypotheses must be a list"
23+
assert type(references) == list, "References must be a list"
24+
if len(references) > 0:
25+
reference_type = type(references[0])
26+
assert reference_type == list, f"References must be a list of lists (found list of {reference_type})"
27+
2228
for reference in references:
2329
assert len(hypotheses) == len(reference), \
24-
"Hypothesis and reference must have the same number of instances"
30+
f"Hypotheses ({len(hypotheses)}) and reference ({len(references)}) must have the same number of instances"
2531

2632
def corpus_score(self, hypotheses: list[str], references: list[list[str]]) -> float:
2733
# Default implementation: average over sentence scores

0 commit comments

Comments
 (0)