Repository navigation
Tokenizer: NFKC/NFKD normalization, and normalized added tokens decode as declared - #1931
Conversation
|
Thanks @laudney. We checked what commit 2 would change for the models we serve. Across the tokenizers of the 27B, 9B and 2B, Flash Next (MLX and FP4-Local), GLM-5.3-Flash, DeepSeek-V4.1, Gemma 4 (12B and 31B), Nemotron Lightning and Bolt, Ornith, Spark-X and drama3, only DeepSeek-V4.1 has normalized added tokens (47), and its normalizer leaves every one unchanged. So no model we ship decodes differently, and it matches Hugging Face's tokenizers for the ones that would. It's in our gate and lands in the next cycles, with #1929 and #1930. |
Some checkpoints, such as Nemotron Parse, declare NFKC normalization, which the native tokenizer could not apply. Add Unicode 9 NFKC and NFKD forms, generated from the Unicode tables the tokenizers library uses, while NFC and NFD stay unchanged for every existing model. A small fixture, a curated sample that nfkc_fixtures.py selects by its rule from Rust tokenizers goldens, checks all four forms, and a Zig test checks that every compatibility mapping changes its code point under NFKC and NFKD and that both forms are idempotent.
A normalized added token was decoded by its normalized match key, but the tokenizers library decodes it by the content the checkpoint declares. The match key stays normalized and decoding returns the original spelling. This changes decoded text, and so the tokenizer identity digest, for any model whose normalizer rewrites one of its normalized added tokens.
0742a4c to
52c2012
Compare
|
Thank you @laudney. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
|
Thanks @laudney! This is in TensorFold 1.2.2, out now: https://github.com/ashhart/TensorFold/releases/tag/v1.2.2 |
Part of #1927.
Nemotron Parse's tokenizer declares an NFKC normalizer, which the tokenizer does not implement today. Its added tokens are also
normalized, and that shows a second difference from the Rust tokenizers library: we decode a normalized added token by its normalized match key, but tokenizers decodes it by the content the checkpoint declares. The two commits fix these two problems separately, so that the second commit, which changes behaviour, can be reviewed on its own.NFKCorNFKDnormalizer (e.g. Nemotron Parse)UnsupportedNormalizer1.
fix(tokenizer): Unicode 9 NFKC and NFKDunicode_data.ziggains the compatibility decomposition table. It is generated bytools/zig/unicode_tables.pyfrom the same Unicode 9 tables that tokenizers uses, and--checkconfirms that the committed file matches its generator.unicode.zigadds compatibility decomposition (recursive), Hangul decomposition and composition, and canonical ordering and composition for.nfkcand.nfkd.steps.zigmaps theNFKCandNFKDnormalizer types.fixtures/nfkc.jsonholds 198 curated cases from Rust tokenizers 0.22.2: for each compatibility tag, evenly spaced cases plus the first, the last and the longest; compatibility and half-width jamo; half-width voiced sound marks; and hand-made composition-boundary strings. Each case checks NFC, NFD, NFKC and NFKD.tools/zig/nfkc_fixtures.pyregenerates exactly this sample.2.
fix(tokenizer): decode normalized added tokens by their spellingcontent, as tokenizers'added_tokens_map_rdoes. A WordLevel test with an NFKC normalizer checks both spellings: they encode to the same ID and decode to the declared text.Gates
zig test zig/src/core/tokenizer/tokenizer.zig: 42/42 after commit 1, and 43/43 after commit 2.unicode_tables.py --checkpasses.zig build testwith this PR on the prompt-cache PR: 465/465 steps, 6,177/6,222 tests (45 skipped).