Comparing numbers, decimals, and version strings under WordPiece
Probe numeric strings and separators without inventing stable counts; discuss why token counts cannot be inferred from digit length
A version string like 1.2.3 is not a number to WordPiece. It is a sequence of characters that a greedy longest-match algorithm may keep whole, split at separators, or fragment into digit and punctuation subwords. The same is true for decimals, dates, and numeric IDs. The practical consequence is that you cannot infer the token count from digit length, decimal places, or the number of characters in a version string. The only reliable method is to run the pinned tokenizer and inspect the tokens it returns.
WordPiece does not treat a numeric string as a single semantic unit. It sees characters and subwords. A decimal point is a character. A version prefix is a character. A date separator is a character. The greedy algorithm tries the longest matching piece first, so a longer numeric string may be one token if that exact string is in the vocabulary, or it may be fragmented into smaller subwords, depending on what the pinned vocabulary contains. The ## prefix in WordPiece marks a continuation subword, which is how the model knows that a fragment is not at the start of a word. None of this can be predicted from the number of digits.
The problem: WordPiece is not a number parser
WordPiece builds a vocabulary of subword units. For each input string, the tokenizer applies the normalization settings in the pinned tokenizer.json, then performs greedy longest-match over the normalized text. If a full substring exists in the vocabulary, it can become one token. If not, the algorithm falls back to smaller pieces. If no piece matches, the result is [UNK]. This is why 1.0 and 1.2.3 can produce different segmentation patterns even though they contain similar digits. The separator . and the letters in a version prefix like v are independent characters that may or may not be part of a longer token. The pinned uncased vocabulary has 30,522 entries; the pinned multilingual cased vocabulary has 119,547. Those sizes tell you the capacity of the vocabulary, not how any particular numeric string will be segmented.
Diagnostic procedure
The following script is self-contained. It loads google-bert/bert-base-uncased at the full commit 86b5e0934494bd15c9632b12f734a8a67f723594 with use_fast=True, then prints the content tokens, model-input tokens, and offset mappings for a set of numeric and version-like probes. Run it with transformers==4.56.2. The printed values are the diagnostic; do not treat them as universal token counts for other models or revisions.
import transformers
from transformers import AutoTokenizer
MODEL = "google-bert/bert-base-uncased"
REVISION = "86b5e0934494bd15c9632b12f734a8a67f723594"
print(f"transformers_version={transformers.__version__}")
tokenizer = AutoTokenizer.from_pretrained(
MODEL,
revision=REVISION,
use_fast=True,
)
probes = [
"1",
"12",
"1.0",
"1.2.3",
"v1.2.3",
"2026-10-05",
]
print(f"model={MODEL}")
print(f"revision={REVISION}")
print(f"tokenizer_class={type(tokenizer).__name__}")
print(f"vocab_size={tokenizer.vocab_size}")
print(f"len_tokenizer={len(tokenizer)}")
print()
for text in probes:
content_ids = tokenizer.encode(text, add_special_tokens=False)
model_input_ids = tokenizer(text, add_special_tokens=True)["input_ids"]
content_tokens = tokenizer.convert_ids_to_tokens(content_ids)
model_input_tokens = tokenizer.convert_ids_to_tokens(model_input_ids)
encoded = tokenizer(
text,
add_special_tokens=False,
return_offsets_mapping=True,
)
offsets = encoded["offset_mapping"]
print(f"text={text!r}")
print(f" content_tokens={content_tokens}")
print(f" content_token_count={len(content_tokens)}")
print(f" model_input_tokens={model_input_tokens}")
print(f" model_input_token_count={len(model_input_tokens)}")
print(f" offsets={offsets}")
print()
Interpreting the output
The script separates two counts that are often conflated. content_token_count is the number of tokens produced by encode(..., add_special_tokens=False). These are the tokens that represent the text itself. model_input_token_count is the length of the sequence the model actually receives for a single unpadded, untruncated input. For BERT, that includes the [CLS] and [SEP] special tokens, so it is normally content_token_count + 2 in that simple case. If you enable padding or truncation, the model-input length becomes the padded or truncated length, not the raw content length. The diagnostic prints both so you can see the difference.
The token list is the segmentation record. If a probe appears as one token, that exact normalized string is in the pinned vocabulary. If it appears as multiple tokens, it is fragmented. Fragmentation is not an error; it is how WordPiece represents a string that is not a single vocabulary entry. An [UNK] token is different: it means the tokenizer could not match a subword at all. For ASCII digits and common punctuation under the pinned uncased model, you may see fragmentation, but you should not assume [UNK] without running the check. For the multilingual cased revision, casing and script coverage differ, so the same probe can produce a different token list.
The offset mapping answers a different question: which character span in the original string produced each content token. That is useful when you need to align a token count back to a numeric field in a log or API payload. Offsets are only returned by fast tokenizers, which is why the script uses use_fast=True.
Limitations
This diagnostic is scoped to google-bert/bert-base-uncased at revision 86b5e0934494bd15c9632b12f734a8a67f723594 and Transformers 4.56.2. It does not predict tokenization for other models, other revisions, other vocabularies, or unrelated LLMs. It also does not predict how a downstream model will interpret a number; it only reports WordPiece segmentation. If you change add_special_tokens, padding, truncation, or the tokenizer class, the model-input token count can change. The pinned vocab sizes 30,522 and 119,547 are fixed for those two revisions, but the token count for a specific string is not derivable from vocabulary size alone. The fast tokenizer implementation and the tokenizers dependency can also change between Transformers releases, so the version pin matters.
This diagnostic is not a substitute for a tokenizer-specific contract test. If your application passes numeric fields to a model, you still need to decide whether you are counting content tokens, model-input tokens, or padded batch tokens. Those are different quantities and they change with encoding options.
Re-check procedure
When the pinned tokenizer.json changes, or when you upgrade Transformers, re-run the script with the new full commit and the new version. Compare the printed content_tokens, model_input_tokens, and offsets for the same probes. If the tokens differ, the segmentation changed for your pinned artifact. If you need the multilingual cased model, replace MODEL with google-bert/bert-base-multilingual-cased and REVISION with 3f076fdb1ab68d5b2880cb87a0886f315b8146f8, then re-run. In production, pin both the model revision and the Transformers version, and keep this diagnostic as a small regression check. The check is cheap to run and tells you exactly which strings fragmented, which stayed whole, and where an [UNK] appeared.
Verified: 2026-10-05. This article and the diagnostic above are scoped to google-bert/bert-base-uncased at revision 86b5e0934494bd15c9632b12f734a8a67f723594 and Transformers 4.56.2. The multilingual cased alternative is google-bert/bert-base-multilingual-cased at revision 3f076fdb1ab68d5b2880cb87a0886f315b8146f8. Re-check by re-running the script against the pinned files when either the tokenizer artifact or the dependency changes.
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.