Skip to content

Preserve Unicode and token boundaries when splitting malformed UTF-8 - #2895

Open
GCSimba wants to merge 1 commit into
openai:mainfrom
GCSimba:codex/fix-whisper-unicode-splitting
Open

GCSimba wants to merge 1 commit into
openai:mainfrom
GCSimba:codex/fix-whisper-unicode-splitting

Conversation

@GCSimba

@GCSimba GCSimba commented Oct 22, 2026

Copy link
Copy Markdown

get_tokenizer(multilingual=True).split_tokens_on_unicode([1041, 243, 230]) raises IndexError, although those tokens decode to �안. Checking only the first replacement character can flush an incomplete character too early. A literal U+FFFD split across byte tokens can also crash or silently lose subsequent tokens. This splitter is used by word-level timestamp alignment.

Use Python’s incremental UTF-8 decoder to distinguish incomplete bytes from actual replacement characters. Preserve the original token order, flush incomplete trailing bytes, and keep end-of-text and timestamp tokens separate from preceding text.

Validation:

  • Added regressions for both tokenizer vocabularies, the crashing sequences, split literal replacement characters, invalid and truncated UTF-8, and special-token boundaries.
  • pytest tests/test_tokenizer.py -q: 32 passed.
  • Black 25.1.0, isort 6.0.0, Flake8 7.1.1 with the repository’s hook arguments, and git diff --check pass.

Tested locally on Windows with Python 3.10. No GPU validation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant