Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/lighteval/metrics/normalizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ def lower(text: str) -> str:
def _tokenize(text):
return re.split(" |-", text)

tokens = [white_space_fix(remove_articles(homogeneize_numbers(remove_punc(lower(t))))) for t in _tokenize(text)]
# homogeneize_numbers must run before remove_punc: otherwise remove_punc strips the decimal
# point first, so "1.0" -> "10" -> float -> "10.0" (distinct numbers collide, and 1.0 != 1).
tokens = [white_space_fix(remove_articles(remove_punc(homogeneize_numbers(lower(t))))) for t in _tokenize(text)]
return " ".join([t for t in tokens if t != ""]).strip()


Expand Down
9 changes: 9 additions & 0 deletions tests/test_unit_base_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ def test_quasi_exact_match(self):
res = em.compute_one_item("", "")
assert res == 0

def test_quasi_exact_match_numbers(self):
em = ExactMatches(normalize_gold=helm_normalizer, normalize_pred=helm_normalizer)

# Numbers that are equal but formatted differently must match (homogeneize_numbers' goal).
assert em.compute_one_item("1.0", "1") == 1
# Distinct numbers must NOT be scored as an exact match.
assert em.compute_one_item("10", "1.0") == 0
assert em.compute_one_item("3.14", "314") == 0

def test_prefix_exact_match(self):
em = ExactMatches(
strip_strings=True,
Expand Down