Skip to content

fix(exact_match): strip unicode and multilingual punctuation when ignore_punctuation is True - #837

Open
reginaldalfret wants to merge 1 commit into
huggingface:mainfrom
reginaldalfret:fix/exact-match-unicode-punctuation
Open

reginaldalfret wants to merge 1 commit into
huggingface:mainfrom
reginaldalfret:fix/exact-match-unicode-punctuation

Conversation

@reginaldalfret

Copy link
Copy Markdown

What does this PR do?

Fixes #836

When ignore_punctuation=True was passed to the exact_match metric, it previously constructed a translation table using string.punctuation:

repl_table = string.punctuation.maketrans("", "", string.punctuation)

This only removed standard ASCII punctuation (!"#$%&\'()*+,-./:;<=>?@[\\]^_{|}~). As a result, non-ASCII and multilingual punctuation marks (e.g. Arabic comma ،, Spanish inverted marks ¿¡, European quotes «», and CJK punctuation ,。!?) were preserved, causing correct multilingual answers to score 0.0`.

Solution

  • Construct a comprehensive punctuation translation table that strips all Unicode punctuation marks (unicodedata.category(c).startswith("P")) while retaining all characters in string.punctuation for full backwards compatibility.
  • Ensure ExactMatch._compute returns a native float so that numpy 2.0+ does not wrap the result in np.float64(...).
  • Add unit tests in tests/test_exact_match_unicode.py covering ASCII, Arabic, CJK, inverted Spanish marks, and quote marks.

Before submitting

  • Did you read the contributor guideline?
  • Did you write any new necessary tests?

…ore_punctuation is True

Closes huggingface#836

Signed-off-by: reginaldalfret <reginaldalfret@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

exact_match: ignore_punctuation only removes ASCII punctuation

1 participant