fix(evaluation): Support non-English responses in ROUGE-1 matching#6292
Open
agharsallah wants to merge 1 commit into
Open
fix(evaluation): Support non-English responses in ROUGE-1 matching#6292agharsallah wants to merge 1 commit into
agharsallah wants to merge 1 commit into
Conversation
The default rouge_score tokenizer drops every character outside [a-z0-9], so responses in non-Latin scripts (Thai, Chinese, Arabic, etc.) tokenize to nothing and response_match_score is always 0, even for identical texts. Use a Unicode-aware tokenizer that keeps non-ASCII word characters (including combining marks such as Thai vowel signs) and delegates ASCII tokens to the default tokenizer, so stemming and scores for English text are unchanged. Fixes google#3111 Signed-off-by: agharsallah <17379925+agharsallah@users.noreply.github.com>
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
The
response_match_scoremetric (RougeEvaluator) always returns 0 for responses in non-Latin scripts, even when the actual and expected responses are identical. The root cause is the defaultrouge_scoretokenizer, which lowercases the text and then replaces every character outside[a-z0-9]with a space — so Thai, Chinese, Arabic, Japanese, Cyrillic, etc. tokenize to an empty token list and every comparison scores 0.Reproduction on
main:Solution:
Pass a Unicode-aware tokenizer to
RougeScorerinfinal_response_match_v1.py:str.isalnum()plus Unicode combining-mark categories (Mn/Mc), so scripts with combining vowel signs (e.g. Thaiสวัสดี, Devanagari matras) stay intact as single tokens.rouge_score's ownDefaultTokenizer, so lowercasing, Porter stemming, and scores for English text are unchanged (guarded by an equivalence test).tokenizersis re-exported through the existinggoogle.adk.dependencies.rouge_scorerindirection, consistent with howrouge_scoreris imported today.Known limitation (noted for reviewers): languages written without spaces (Thai, Chinese) are matched at phrase granularity rather than word granularity, since proper word segmentation would require a language-specific segmenter. This PR fixes the "identical/overlapping text scores 0" bug without adding dependencies.
Testing Plan
Unit Tests:
New tests in
tests/unittests/evaluation/test_final_response_match_v1.py:_UnicodeAwareTokenizerproduces identical tokens torouge_score'sDefaultTokenizerfor ASCII inputs (regression guard for English scoring, incl. stemming, punctuation, digits, underscores)PASSEDManual End-to-End (E2E) Tests:
Ran the evaluator directly on the scenario from #3111 (agent instructed to reply with the word
สวัสดี, expected responseสวัสดี):Checklist
Additional context
Formatting verified with the repo-pinned tools:
pyink 25.12(unchanged),isort --profile google(clean),ruff 0.15.17(all checks passed), andscripts/compliance_checks.py(exit 0).