fix: include Korean Hangul and Japanese kana in CJK token heuristic#2
Open
haosenwang1018 wants to merge 1 commit intoaeromomo:mainfrom
Open
fix: include Korean Hangul and Japanese kana in CJK token heuristic#2haosenwang1018 wants to merge 1 commit intoaeromomo:mainfrom
haosenwang1018 wants to merge 1 commit intoaeromomo:mainfrom
Conversation
The CJK-aware token estimation regex only matched Chinese characters and fullwidth forms, missing Korean Hangul syllables (U+AC00-U+D7AF) and Japanese Hiragana (U+3040-U+309F) / Katakana (U+30A0-U+30FF). This caused Korean and Japanese text to be estimated at the ASCII rate (~4 chars/token) instead of the CJK rate (~1.5 chars/token), producing significantly lower token counts. Added Hangul Syllables, Hiragana, and Katakana ranges to the regex and added corresponding tests.
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.
Problem
The CJK-aware token estimation regex in
lib/tokens.pyonly matches Chinese characters (U+4E00–U+9FFF, U+3400–U+4DBF) and fullwidth forms. It misses:This causes Korean and Japanese text to fall through to the ASCII estimation rate (~4 chars/token) instead of the CJK rate (~1.5 chars/token), producing significantly underestimated token counts for these languages.
Fix
Extended
_CJK_REto include Hangul Syllables, Hiragana, and Katakana Unicode ranges.Tests
Added 4 new tests:
test_korean— basic Korean text estimationtest_japanese_hiragana— Hiragana texttest_japanese_katakana— Katakana texttest_cjk_heuristic_covers_all_scripts— validates Hangul gets CJK rates in heuristic mode