# A first measured note for tokenizers, with a runnable check

> Source: <https://discuss.huggingface.co/t/a-first-measured-note-for-tokenizers-with-a-runnable-check/192472#post_2>
> Published: 2026-11-25 06:06:39+00:00

**Key takeaway:** Retaining PR #2747's standalone `\w` definitions while using bracket-context-specific replacements matched Oniguruma on all 420 tested pattern/input combinations, whereas a uniform replacement diverges on six Latin-1 scalars (², ³, ¹, ¼, ½, ¾) inside brackets.

I did a bit of digging on my end as well:

I reproduced the original eight changes with released Python packages and tested [PR #2747](https://github.com/huggingface/tokenizers/pull/2747). There is an additional detail relevant to [#2742](https://github.com/huggingface/tokenizers/issues/2742): the old engine uses different word-character sets for standalone `\w` and `\w` inside a bracketed character class.

The tested PR restores all eight original `\w+` cases and the old standalone `\w` membership across all valid Unicode scalar values. Inside brackets, however, the same replacement changes the previously compatible behavior of six Latin-1 numbers (`²`, `³`, `¹`, `¼`, `½`, `¾`). Both contexts need the adjustment for U+200C and U+200D.

Using the issue’s tiny WordLevel tokenizer, `Split(behavior="Removed", invert=False)` on `a²a` produced:

| Pattern | Tokenizers 0.23.3 | PR merge base | PR head | 
|---|---|---|---|
| `\w+` | `[]` | `[0]` | `[]` | 
| `[^\w\s]+` | `[1, 1]` | `[1, 1]` | `[0]` | 
| `[\s\w]+` | `[0]` | `[0]` | `[]` | 

Here `0` is `[UNK]` and `1` is `a`. These IDs represent the parts **left after removal**, not the matches. The first row is restored; the other two newly differ from old.

Without the tokenizer, Oniguruma itself reproduces the distinction: `\w+` matches all of `a²a`, while `[\w]+` matches the two `a` s separately. Two Unicode lookup paths explain this.

Single-scalar membership comparison for the pinned engines:

| Comparison | Different scalar values out of 1,112,064 | 
|---|---|
| Old standalone `\w` vs old bracketed`[\w]` | 6 | 
| Old standalone `\w` vs unmodified fancy-regex`\w` | 8 | 
| Old bracketed `[\w]` vs unmodified fancy-regex`\w` | 2 | 
| Old standalone `\w` vs PR standalone replacement | 0 | 
| Old bracketed `[\w]` vs PR bracket-context replacement | 6 | 
| Old bracketed `[\w]` vs bracket-specific alternative | 0 | 

**If 0.23 behavioral compatibility is the goal**, I would retain the PR’s standalone definitions and distinguish replacements inside brackets. Explicit context-specific expressions matched Oniguruma on all 420 tested pattern/input combinations. These are starting points for a compatibility change, not a validated general-purpose rewriter or integrated Tokenizers patch. The minimal tests below need no model download or GPU.

Adopting a uniform new-engine Unicode word definition instead is a separate policy choice. Documenting the differences would help users whose serialized tokenizers depend on historical pattern semantics.

1. What was actually run, and which comparisons answer which questions?
The original standalone fix works on the tested head. The explicit bracket alternatives retain that success while recovering historical bracket membership and targeted spans. Whether to preserve or deliberately change that context dependence remains a policy choice. Thanks for making the original observation easy to replay.
