Tracing accent stripping before WordPiece lookup
Use composed and decomposed accented strings, inspect tokens and offsets, and explain why display spans cannot be reconstructed from normalized text alone
An accent can be gone before WordPiece makes its first vocabulary decision. That is the path to inspect in google-bert/bert-base-uncased@86b5e0934494bd15c9632b12f734a8a67f723594: its pinned normalizer lowercases and strips accents, so the expected lookup input for composed café and its decomposed spelling is cafe for both. If their token IDs match, that describes lookup after normalization, not the spelling of the source. This guide applies only to that pin and google-bert/bert-base-multilingual-cased@3f076fdb1ab68d5b2880cb87a0886f315b8146f8, using transformers==4.56.2. The comparison is deliberate: the multilingual-cased pin is configured not to strip accents.
Keep normalization separate from lookup
The pinned tokenizer files expose four ordered stages: normalizer, BERT pre-tokenizer, WordPiece model, and post-processor. Normalization can be many-to-one; the pre-tokenizer selects spans; WordPiece performs greedy subword lookup; and the post-processor adds [CLS] and [SEP]. An [UNK] is therefore a later lookup result, not direct evidence that an accent was removed. For these probes, the uncased pin collapses both spellings before lookup, while the multilingual-cased control preserves the distinction.
Keep the exact source string and inspect each boundary:
- Preserve the received text, including its original Unicode representation.
- Run the normalizer alone and print both source and normalized code points.
- Encode the original source with the fast tokenizer, requesting offsets and the special-token mask.
- Print every model-input row, then derive content tokens by excluding special tokens.
- Label unknown tokens and multi-piece words separately.
Run a paired trace
Run this in a clean environment with transformers==4.56.2. It needs network access or an existing Transformers cache for the pinned tokenizer files. The assertions encode configuration derived from the pinned artifacts; they are not a captured output transcript.
from importlib.metadata import version
from transformers import AutoTokenizer
assert version("transformers") == "4.56.2"
CASES = (
("composed", "caf\u00e9"), # café
("decomposed", "cafe\N{COMBINING ACUTE ACCENT}"),
)
PINS = (
(
"google-bert/bert-base-uncased",
"86b5e0934494bd15c9632b12f734a8a67f723594",
True,
),
(
"google-bert/bert-base-multilingual-cased",
"3f076fdb1ab68d5b2880cb87a0886f315b8146f8",
False,
),
)
for MODEL_ID, commit, strips_accents in PINS:
FULL_COMMIT = commit
tokenizer = AutoTokenizer.from_pretrained(
MODEL_ID,
revision=FULL_COMMIT,
use_fast=True,
)
assert tokenizer.is_fast
normalizer = tokenizer.backend_tokenizer.normalizer
print(f"\n{MODEL_ID}@{FULL_COMMIT}")
print(
f"versions: transformers={version('transformers')}, "
f"tokenizers={version('tokenizers')}"
)
print(f"normalizer: {type(normalizer).__name__}")
observed = {}
for label, source in CASES:
normalized = normalizer.normalize_str(source)
expected_normalized = "cafe" if strips_accents else source
assert normalized == expected_normalized
batch = tokenizer(
source,
add_special_tokens=True,
padding=False,
truncation=False,
return_offsets_mapping=True,
return_special_tokens_mask=True,
return_token_type_ids=True,
)
ids = batch["input_ids"]
tokens = tokenizer.convert_ids_to_tokens(ids)
offsets = batch["offset_mapping"]
special = batch["special_tokens_mask"]
assert len(ids) == len(tokens) == len(offsets) == len(special)
assert special[0] == special[-1] == 1
assert tokens[0] == tokenizer.cls_token
assert tokens[-1] == tokenizer.sep_token
print(f"\n {label}")
print(f" source={source!r}")
print(
" source_codepoints="
+ " ".join(f"U+{ord(char):04X}" for char in source)
)
print(f" normalized={normalized!r}")
print(
" normalized_codepoints="
+ " ".join(f"U+{ord(char):04X}" for char in normalized)
)
print(" rows:")
for index, (token_id, token, offset, is_special) in enumerate(
zip(ids, tokens, offsets, special)
):
start, end = offset
role = "special" if is_special else "content"
source_slice = "" if is_special else source[start:end]
print(
f" {index}: id={token_id} token={token!r} "
f"offset=({start},{end}) role={role} "
f"source_slice={source_slice!r}"
)
content_tokens = [
token for token, is_special in zip(tokens, special)
if not is_special
]
if (
len(content_tokens) == 1
and content_tokens[0] == tokenizer.unk_token
):
content_shape = "one unknown"
elif len(content_tokens) > 1 and all(
token != tokenizer.unk_token for token in content_tokens
):
content_shape = "fragmentation into multiple known pieces"
elif any(token == tokenizer.unk_token for token in content_tokens):
content_shape = "multiple pieces containing an unknown"
else:
content_shape = "one known piece"
print(f" token_type_ids={batch['token_type_ids']}")
print(f" content_count={len(content_tokens)} of {len(ids)} input IDs")
print(f" content_shape={content_shape}")
observed[label] = normalized, ids
if strips_accents:
assert observed["composed"][0] == observed["decomposed"][0]
assert observed["composed"][1] == observed["decomposed"][1]
Interpret the trace by row
The normalized line answers whether the two forms meet WordPiece identically. For the uncased pin, the assertion requires both forms to become cafe; the composed and decomposed inputs must consequently have matching input_ids. For the multilingual-cased pin, the assertions require the normalizer to leave each source form unchanged. If that model’s final token IDs happen to match, inspect the tokens: both forms could have become [UNK]. A shared unknown ID does not erase the earlier normalization distinction.
Every printed row corresponds to one input_ids entry, but not every such entry is a content token. With special tokens enabled, BERT’s model-input sequence also contains [CLS] and [SEP]. The content-only count comes from entries whose special_tokens_mask value is zero. token_type_ids are auxiliary input features, not additional tokens. This run disables padding and truncation so the printed sequence remains a direct diagnostic rather than a batching demonstration.
For these single-word probes, one [UNK] content token means that the downstream representation is unknown. Multiple non-[UNK] content tokens indicate fragmentation into known WordPiece or subword pieces. Multiple pieces containing [UNK] form a mixed result. The absence of whitespace or punctuation makes that classification especially direct here. Accent stripping can change which lookup occurs, but accent stripping and an unknown result are separate observations.
Preserve display spans separately
Fast-tokenizer offsets align each resulting piece with the original source; they are not indexes into the normalized string. The composed sample’s accented vowel and the decomposed sample’s vowel-plus-mark sequence do not share the same source extent. Consequently, the same normalized token must not be assigned source coordinates by counting positions in cafe. The script prints source[start:end] beside every content row so the alignment supplied by this exact tokenizer and dependency can be inspected directly. Do not assume the two offset pairs are interchangeable merely because their token IDs match.
Normalized text and token IDs cannot reconstruct a display span by themselves. Multiple original strings can normalize to the same characters, and neither cafe nor its vocabulary ID records whether the source contained a precomposed accent or a combining sequence. Retain the original string together with its token IDs, offsets, options, model revision, and library version. Treat offsets as tokenizer-reported alignment rather than a general grapheme-segmentation service. If a returned slice looks surprising around a combining mark, do not repair it by guessing from the normalized token; preserve the source and investigate the pinned implementation.
Limitations and re-check procedure
This trace covers two short words, one input sequence, and the fast API at the two stated revisions. It does not establish behavior for every Unicode character, another BERT checkpoint, or a slow tokenizer. It also does not evaluate padding, truncation, paired inputs, or production batches. The printed tokenizers version matters because offset alignment is implemented below the Transformers wrapper.
Verified: 2026-10-05. The normalization and WordPiece claims were checked against the pinned uncased tokenizer.json and multilingual-cased tokenizer.json. Encoding options and fast-tokenizer alignment behavior were checked against the Transformers v4.56.2 tokenizer documentation.
When either pinned file or dependency changes, create a fresh environment, select the new full commit, run the same paired cases, and compare normalized text, IDs, tokens, special-token masks, and offsets. Inspect the new file’s normalizer, post-processor, and WordPiece settings rather than merely updating assertions. If tokenizer JSON is unchanged but offsets differ, compare the installed tokenizers version first. Keep the old and new results until the behavioral difference is explained, and do not carry these conclusions to an unpinned revision.
Sources
- google-bert/bert-base-uncased tokenizer.json at 86b5e093
Pinned WordPiece vocabulary and normalization settings for the English uncased model.
- google-bert/bert-base-multilingual-cased tokenizer.json at 3f076fdb
Pinned WordPiece vocabulary and normalization settings for the multilingual cased model.
- Hugging Face Transformers v4.56.2 tokenizer API
Versioned reference for encoding options, output fields, and fast-tokenizer alignment methods.
Token counts in this article were produced by the tokenizers pinned on the sources page and are checked by the site's test suite. If a count ever stops matching the pinned vocabulary, the build fails.