Fix UnicodeScripts pre-tokenizer dropping leading spaces - #2382
Open
Kayvan-Zahiri wants to merge 1 commit into
Open
Kayvan-Zahiri wants to merge 1 commit into
Kayvan-Zahiri wants to merge 1 commit into
Conversation
`fixed_script(' ')` returns `Script::Any`, and the boundary `filter_map`
only emits an offset for a non-Any script. A leading run of spaces
therefore emits no boundary, `ranges` does not start at 0, and those
bytes never land in a split. `PreTokenizedString::split` does not check
that splits tile the input, so the spaces are dropped silently.
Anchor the first boundary at 0, and seed `ranges` when the input is
entirely `Script::Any` (previously `" "` produced zero splits).
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DQughgr95y4B9H1jfaQH8o
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.
UnicodeScriptssilently drops a leading run of spaces.fixed_script(' ')returnsScript::Any, and the boundaryfilter_maponly emits an offset when the script is notAny, sorangesstarts past the spaces.PreTokenizedString::splitdoes not check that splits tile the input, so those bytes just vanish.On main today:
The pre-tokenizer contradicts itself on the same character: a trailing space is absorbed, a leading one is destroyed, and its own test is named
spaces_are_included_in_every_script.Through a real
Tokenizer(WordLevel vocab holding both"Yes"and" Yes")," Yes"and"Yes"encode identically, so the" Yes"entry is unreachable and offsets cover 3 of 4 bytes.Fix anchors the first boundary at 0, which merges the leading spaces into the following run rather than emitting a bare space token.
cargo test --lib: 201 pass + 1 fail before, 202 pass after.cargo fmt --checkandcargo clippy --all-targets -D warningsare clean.馃 Generated with Claude Code