Multilingual Tokenization and Vocabulary Allocation › Bytes as an escape hatch
Language AI HandbookAll chapters A finite vocabulary can represent unfamiliar text by keeping a complete smaller alphabet beneath its learned pieces.
SentencePiece's byte_fallback=True includes 256 byte pieces and decomposes unknown normalized characters into UTF-8 bytes. Common text can still use learned pieces. Byte fallback preserves the remaining normalized text, so any distinctions that the normalizer removes stay lost. SentencePiece special symbols
A pure byte model encodes every UTF-8 byte directly. ByT5's paper describes 256 byte values with three additional IDs for padding, end-of-sentence, and an unused unknown marker. Its architecture dispenses with a learned subword vocabulary. It still has to process every byte in its input. ByT5
PythonIn [21]Expand
script_samples = {
"ASCII U+0061": "a",
"Latin U+00E9": "é",
"Cyrillic U+0434": "д",
"Arabic U+0642": "ق",
"Devanagari U+092C": "ब",
"Hangul U+D55C": "한",
"Han U+732B": "猫",
"Thai U+0E21": "ม",
"Emoji U+1F408": "🐈",
}
byte_lengths = {
label: len(sample.encode("utf-8"))
for label, sample in script_samples.items()
}The bars show byte lengths for nine selected Unicode scalar values, labeled by script or category and code-point number.
VisualizationOut [23]Expand

A Unicode scalar value uses one to four UTF-8 bytes. That range applies to one scalar at a time. Translations can contain different numbers of scalars, so their byte counts can differ by more than a factor of four. Petrov et al. (2023) report examples of this difference.
A byte-level model fixes the count for a given input to its byte length, apart from additional markers. Byte-level BPE starts from the same byte alphabet and learns merges that can reduce that count. SentencePiece byte fallback uses bytes for unsupported normalized characters and learned pieces elsewhere. All three designs can cover valid UTF-8, but the resulting sequence lengths differ.
A sentence of twenty Han code points that each occupy three bytes gives sixty pure-byte tokens before special tokens. With standard dense self-attention, the number of query-key interactions grows quadratically with sequence length. The actual runtime also depends on the model, kernel, and hardware. ByT5 reports both sequence-length costs and robustness gains on some noisy-text evaluations. ByT5
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!