fix: handle non-ASCII text in ROUGE-1 eval scorer#6444
Open
guptaishaan wants to merge 1 commit into
Open
Conversation
The `rouge_score` library's default tokenizer matches only ASCII alphanumeric Signed-off-by: Ishaan <ishaangupta0408@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
rouge_scorelibrary's default tokenizer matches only ASCII alphanumericcharacters (
[a-z0-9]+) and silently discards every other character. As aresult, text written in non-Latin scripts such as Thai (
สวัสดี), Chinese,Arabic, or any other language that uses non-ASCII code points is tokenized to
an empty list, which causes
_calculate_rouge_1_scoresto return a score of0.0 even when the candidate and reference strings are identical.
The fix introduces a small
_UnicodeTokenizerclass that extendsrouge_score.tokenizers.Tokenizer. Itstokenizemethod uses the regex[a-z0-9]+|[^\x00-\x7f]+to preserve contiguous runs of non-ASCII charactersas individual tokens while keeping the same ASCII-alphanumeric filtering for
Latin text. The
_calculate_rouge_1_scoreshelper is updated to pass thistokenizer to
RougeScorerinstead of usinguse_stemmer=Truewith thedefault ASCII-only tokenizer. Two regression tests for identical and
non-matching Thai strings are added to the existing test module.
Fixes #3111