The BPE and Unigram algorithms above both assume a base alphabet of Unicode characters.
Character-based BPE and Unigram algorithms can use a base alphabet of Unicode characters. That assumption has a hidden cost: the set of assigned Unicode codepoints spans well over 100,000 characters once every script, symbol block, and emoji range is counted, and no training corpus, however large, is guaranteed to contain every character a model might encounter in the wild — an emoji combination, a rare CJK ideograph, a mathematical symbol, a character from a script underrepresented in training data. A character-level BPE vocabulary trained on a corpus that happens to omit some character still needs a fallback for it, reintroducing exactly the <UNK> problem the companion book example identified for word-level vocabularies, just at a smaller scale and lower frequency.
Byte-level BPE, introduced for language modeling by GPT-2 (Radford et al., 2019) and retained, with refinements, through GPT-3 and GPT-4, sidesteps this entirely by choosing a base alphabet that is guaranteed complete by construction: the possible values of a single byte. Any Unicode string has a unique, lossless encoding as a sequence of UTF-8 bytes — this is a property of the UTF-8 encoding itself, not an assumption about the training corpus — so a vocabulary containing all 256 base byte values plus BPE merges learned over byte sequences can represent literally any input that can be expressed as bytes at all: any language, any script, any emoji, malformed or mixed encodings, and non-text byte content pasted into a prompt. The base alphabet size is fixed at regardless of how many languages or scripts the model is ultimately trained to handle, in sharp contrast to a Unicode-codepoint character alphabet, whose base size would itself grow substantially with every additional script or symbol range the training data covers. The <UNK> token, present in essentially every tokenizer built on a closed word or character vocabulary, has no reason to exist in a byte-level BPE tokenizer: the merge algorithm from the companion book example applies unchanged, operating on byte values instead of characters, and any byte sequence with no learned merge simply falls back to individual bytes, exactly as any unmerged character sequence falls back to individual characters in classical BPE.
Two implementation details, both present in GPT-2’s public tokenizer and carried forward by its successors, are worth making explicit because they address problems specific to the byte-level setting rather than being generic BPE machinery. First, many of the 256 raw byte values correspond to unprintable control characters or to whitespace variants that are visually indistinguishable from one another, which is awkward for training and debugging tooling built around printable text; GPT-2’s implementation applies a fixed, reversible lookup table mapping each of the 256 byte values to a distinct printable Unicode character before running BPE, purely so the training and merge-inspection code can treat its input as ordinary printable text, and inverts the mapping when decoding token IDs back to bytes. This is a bookkeeping convenience and changes nothing about the underlying algorithm from the companion book example — it operates on a relabeled version of the same 256-symbol alphabet.
Second, and more consequential, GPT-2 does not run BPE merges over an entire raw text stream unrestricted; it first splits text using a fixed regular expression that separates runs of letters, runs of digits, and individual punctuation characters into distinct chunks, and restricts BPE merges to occur only within a chunk, never across a chunk boundary. Without this pre-tokenization step, greedy frequency-based merging would happily learn merges spanning a word and its trailing punctuation or a word and the following space — for instance treating “dog.” and “dog” (followed by a space) as forcing different, punctuation-entangled token sequences purely because those exact substrings happened to be frequent, rather than because the underlying word “dog” is frequent. Restricting merges to within pre-tokenizer chunks keeps punctuation, whitespace, and word-internal characters from contaminating one another’s merge statistics, at some cost in flexibility (a merge that legitimately spans what the regex considers a boundary is never learned) that has been judged worthwhile in practice by every major byte-level BPE tokenizer since.
The practical engineering case for byte-level BPE in production LLMs rests on four points, all downstream of the completeness guarantee. It provides a hard robustness guarantee against any input a model might be asked to process — source code (with its dense, non-natural-language symbol usage), mixed-script multilingual text, emoji, and malformed or adversarial input all remain representable without a reserved fallback symbol that silently destroys information. It decouples the base vocabulary size from the number of languages and scripts a model is trained on, which matters increasingly as LLMs are trained on ever more linguistically diverse corpora rather than English-only text. It gives a single, uniform preprocessing pipeline — bytes in, merges applied, integers out — with no language-specific normalization or word-segmentation logic required upstream, other than the coarse punctuation/whitespace pre-tokenization regex described above, which is itself language-agnostic. And it composes cleanly with the vocabulary-size tradeoffs the companion book example quantifies: because the base alphabet is fixed at 256 regardless of , every dollar of vocabulary budget beyond that floor goes toward learned merges that improve compression, rather than toward covering more of a character space that grows with corpus diversity. The one real cost, worth flagging as an empirical caveat rather than a law, is that byte-level tokenization is not uniformly efficient across scripts: a script whose characters require multiple UTF-8 bytes each (three bytes per common Chinese character, for instance) starts from a byte-level representation several times longer than an equivalent character-level one, and while BPE merges do learn to re-assemble common multi-byte characters into single tokens over enough training data, rarer characters and underrepresented scripts fragment into more tokens per unit of text than English does under the same tokenizer — a documented asymmetry in effective context length and inference cost across languages that later vocabulary-size choices (larger vocabularies, more merge budget spent on non-English scripts) partially, but do not completely, correct.
Continue with the book
Explore the full treatment, worked examples, and exercises in LLMs Derived.
Companion article for LLMs Derived, published by Choral Software. Article text and original examples © 2026 Choral Software. All rights reserved.
