Commit 0168674
committed
fix: correct _UnicodeTokenizer for CJK segmentation and stemming
The previous tokenizer had two defects:
- Its char-level fallback was unreachable: it split non-ASCII text on
whitespace first, and scripts without spaces (Chinese, Japanese, Thai)
yield a single token, so the `list(text)` fallback never ran. Two
different CJK strings sharing characters scored 0.0 instead of getting
partial credit.
- Passing a custom `tokenizer=` makes rouge-score ignore `use_stemmer`,
so English stemming was silently dropped (e.g. "running" no longer
matched "run").
Now ASCII-majority text is delegated to rouge-score's DefaultTokenizer
(preserving Porter stemming and existing behavior exactly), and non-ASCII
text keeps Latin/digit runs as words while splitting remaining word
characters individually so partial overlap is scored.
Verified: Thai exact=1.0, CJK exact=1.0, CJK partial(你好世界 vs 你好朋友)=0.5,
English stemming(running fast vs run fast)=1.0, Latin sanity matches default.1 parent d04be01 commit 0168674
1 file changed
Lines changed: 17 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
106 | 108 | | |
107 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
108 | 113 | | |
109 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
110 | 118 | | |
111 | 119 | | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
| 120 | + | |
| 121 | + | |
117 | 122 | | |
118 | 123 | | |
119 | 124 | | |
| |||
0 commit comments