Fixes #396: auto-detect CJK text in NgramSampleEvaluator scoring - #515
Conversation
|
Thanks for identifying this use case and contributing the initial implementation! I pushed a follow-up commit that preserves the intent of your proposal while avoiding an implicit behavior change. The evaluator now supports an explicit
This keeps existing behavior backward-compatible and predictable, while still supporting datasets containing both English and Chinese text. I also expanded Han character coverage, updated the evaluator/filter descriptions, and added regression tests for English, Chinese, mixed-language text, and extended Han characters. Since #396 was previously addressed through explicit |
Fixes #396
Problem
In the default
language='en'mode,NgramSampleEvaluator._score_funcsplits text viastr.split(). Chinese text has no spaces, so the whole sentence becomes a single token; withngrams=5the token count is below the threshold and the sample always scores0.0, causing all Chinese samples to be filtered out — contradicting the documented example output.Fix
In
dataflow/operators/general_text/eval/ngram_sample_evaluator.py, the splitting condition now also checks for CJK characters (re.search(r'[\u4e00-\u9fff]', content)): when CJK text is detected, it falls back to character-level splitting even inenmode.language='zh': behavior unchanged (character-level splitting)enmode: now correctly scored instead of0.0Updated
get_desc(zh/en) to document the auto-detection.