Skip to content

Commit f98b32d

Browse files
committed
fix(base): correct asserts for huggingface output
1 parent 15be790 commit f98b32d

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
repos:
22
- repo: local
3-
files: ^signwriting/
43
hooks:
54
- id: pylint
65
name: pylint
@@ -9,7 +8,8 @@ repos:
98
types: [python]
109
- id: pytest
1110
name: pytest
12-
entry: pytest signwriting_evaluation
11+
entry: pytest .
1312
language: system
1413
types: [python]
14+
pass_filenames: false
1515

signwriting_evaluation/metrics/base.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,21 @@ 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"
22+
assert isinstance(hypotheses,list), "Hypotheses must be a list"
23+
assert isinstance(references, list), "References must be a list"
2424
if len(references) > 0:
2525
reference_type = type(references[0])
26-
assert reference_type == list, f"References must be a list of lists (found list of {reference_type})"
26+
assert reference_type in [list, tuple], \
27+
f"References must be a list of lists or tuples (found list of {reference_type})"
2728

2829
for reference in references:
2930
assert len(hypotheses) == len(reference), \
30-
f"Hypotheses ({len(hypotheses)}) and reference ({len(references)}) must have the same number of instances"
31+
(f"Hypotheses ({len(hypotheses)}) and reference ({len(reference)}) "
32+
f"must have the same number of instances (references is ({len(references)}))")
3133

3234
def corpus_score(self, hypotheses: list[str], references: list[list[str]]) -> float:
3335
# Default implementation: average over sentence scores
36+
# example: hypotheses=["hello"], references=[["hi"], ["hello"]]
3437
self.validate_corpus_score_input(hypotheses, references)
3538
transpose_references = list(zip(*references))
3639
return sum(self.score_max(h, r) for h, r in zip(hypotheses, transpose_references)) / len(hypotheses)

signwriting_evaluation/metrics/similarity.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ def error_rate(self, hyp: Sign, ref: Sign) -> float:
9999
return length_weight + mean_cost * (1 - length_weight)
100100

101101
def score_single_sign(self, hypothesis: str, reference: str) -> float:
102-
print("scoring", hypothesis, reference)
103102
# Calculate the evaluate score for a given hypothesis and ref.
104103
hyp = fsw_to_sign(hypothesis)
105104
ref = fsw_to_sign(reference)

0 commit comments

Comments
 (0)