Sub topic 13
Pitfalls: multilingual text, numbers, and train/inference mismatch
This chapter assumes you understand tokens, subword vocabularies, BPE merges, WordPiece matching, and SentencePiece models. The focus here is operational: how tokenizer choices fail on real data and how to detect those failures.
Multilingual text needs representative training data
A tokenizer learns its vocabulary from its training corpus. If the corpus contains mostly English, the tokenizer will allocate many tokens to common English words and word pieces. Text in other languages may then split into much longer sequences.
Longer sequences increase memory use and reduce the amount of context a model can process. They can also make multilingual training less balanced. A sentence with the same meaning may require very different numbers of tokens in different languages.
Writing systems create different challenges:
- Chinese, Japanese, and Thai do not use spaces in the same way as English.
- Arabic has multiple Unicode forms and can include combining marks.
- Hindi and other Indic scripts use sequences of base characters and marks.
- Cyrillic and Latin text may look similar but use different code points.
- Emojis can contain several code points joined by special characters.
Byte-level BPE avoids unknown characters because every input can be represented as bytes. However, rare characters may still become several byte-level tokens. “No unknown token” does not mean “short or semantically useful tokenisation.”
A tokenizer trained on balanced multilingual data usually gives more consistent coverage. You may also reserve vocabulary capacity for scripts that are important to the application, rather than allowing the largest language to consume most entries.
Numbers are not ordinary words
Numbers appear in many forms:
42,42.5, and-171,000and1 0002026-11-2910%,$19.99, and3.14e8- product codes such as
AB-1200-X
A word-level tokenizer treats each unseen number as an unknown word. A subword tokenizer can represent it, but may split each digit or punctuation mark separately. This increases sequence length and can make numerical reasoning harder.
Do not automatically normalise every number to a placeholder such as <NUM>. That can help classification when the exact value does not matter, but it destroys information needed for arithmetic, dates, prices, and identifiers. Decide based on the task.
Unicode normalisation can also change numeric text and other symbols. Apply it consistently and test it explicitly:
import unicodedata
def normalise(text):
text = unicodedata.normalize("NFKC", text)
return text.casefold()
examples = ["123", "123", "Straße", "STRASSE"]
for value in examples:
print(repr(value), "->", repr(normalise(value)))NFKC converts some compatibility characters, such as full-width digits, into common forms. Case folding handles more Unicode case variants than simple ASCII lowercasing. Neither operation is universally correct, so validate the result against your domain.
Train and inference preprocessing must match
The tokenizer used during model training and the tokenizer used in production must have the same:
- normalisation rules
- pre-tokenisation rules
- vocabulary
- merge or segmentation model
- special-token definitions
- whitespace handling
- unknown-token behavior
A small difference can change every token after the mismatch. For example, training on lowercased text but serving original case may produce many rare pieces. Training with NFKC but serving without it can distinguish 123 from 123.
Treat the tokenizer files as part of the model artifact. Version them together, and run a round-trip test:
- Encode a fixed set of representative strings.
- Compare the token IDs with a stored reference.
- Decode them and check the expected text.
- Include multilingual text, numbers, whitespace, punctuation, and special tokens.
A practical review checklist
| Area | Check |
|---|---|
| Languages | Token counts and unknown rates by language |
| Numbers | Dates, decimals, currencies, and identifiers |
| Unicode | Normalisation and combining-character behavior |
| Reproducibility | Identical tokenizer files and preprocessing settings |
| Special tokens | Reserved IDs and literal-text collisions |
Exercise
A model was trained after lowercasing and NFKC normalisation, but production tokenises original text. Name two likely symptoms and one useful test.
Show answer
Symptoms include more rare or longer token sequences and different token IDs for equivalent text. Encode a fixed multilingual and numeric test set with both pipelines and compare the IDs and decoded text.