Byte-Level Tokenization
A tokenizer design that starts from bytes so models can represent arbitrary text without unknown-character gaps.
Byte-level tokenization is a tokenizer design that starts from raw UTF-8 bytes instead of assuming text already fits a word or character inventory, so unusual characters, punctuation-heavy text, code-like strings, emoji, and mixed-script input can still be represented without unknown-character gaps; the tradeoff is that token pieces are often less readable, sequences can grow longer for messy strings, and token counts may not line up with word counts.
At a glance
Released
February 2019
Authors
Alec Radford, Jeffrey Wu, Rewon Child, et al.
Optimizes
- Arbitrary Text Coverage
- Open Vocabulary Text
Example models
What It Is
Byte-level tokenization is a tokenizer design that treats text as byte data first. Instead of beginning with whole words or a fixed list of visible characters, it can fall back to the UTF-8 bytes that make up any string. That means text like "cafe", "cafe with an accent", emoji, punctuation-heavy code, or mixed-script text can still be represented even when the exact visible piece was not memorized as one vocabulary item.Why It Exists
Byte-level tokenization optimizes for coverage. A tokenizer built on bytes does not need an unknown token just because an unusual character sequence appears in the input. It also keeps the base inventory small, because the fallback alphabet is the byte range rather than a huge list of pre-listed words.How It Works
A byte-level tokenizer first converts the input string into UTF-8 bytes. Those bytes act as the guaranteed fallback pieces. Many systems then learn frequent merges on top of those byte pieces, often with byte pair encoding (BPE), so common patterns become larger subword tokens. In practice, the tokenizer does not stay at one byte per token forever. It starts from bytes so coverage is guaranteed, then merges common byte sequences when that makes the vocabulary more efficient.Raw textUTF-8 bytesGuaranteed byte piecesLearned merge passFinal token IDsAny string can fall back to bytes, so coverage does not depend on pre-listed whole wordsUnusual text may stay split into many small pieces, which raises token count and hurts readabilityRaw text to UTF-8 bytesUTF-8 bytes to Guaranteed byte piecesGuaranteed byte pieces to Learned merge passLearned merge pass to Final token IDs
Math Or Compute Schema
The two formulas below separate coverage from compression. Byte-level handling provides the fallback alphabet: any string can be reduced to UTF-8 bytes that always represent the input. A BPE-style merge stage then sits on top of those byte pieces and repeatedly combines common neighboring symbols into larger reusable subword tokens.- Input text string before tokenization.
- The i-th UTF-8 byte emitted from the input string.
- Number of bytes needed to encode the string.
Compared To Nearby Modules
Compared with word-level tokenization, byte-level tokenization does not assume the tokenizer already knows each full word in advance. That is the practical answer to the common question of why some tokenizers use bytes instead of words: bytes keep working even when the next input string is messy, misspelled, code-heavy, or mixed across scripts. Compared with character-only tokenization, it usually does not stop at tiny pieces, because learned merges can build larger subwords on top of the byte fallback. That is why byte-level tokenization often appears together with BPE rather than replacing BPE. Bytes provide guaranteed coverage; BPE provides compression into more reusable chunks.| Comparison dimension | Byte-Level Tokenization | BPE | WordPiece |
|---|---|---|---|
| Primary role in tokenization | Guarantees coverage by falling back to UTF-8 bytes for any input string | Compresses frequent neighboring symbols into larger reusable subword tokens | Builds a vocabulary of scored subword pieces around word-like candidates |
| Starting unit | UTF-8 byte pieces that can always represent the text | Small symbols such as bytes or byte-derived pieces | Word or subword candidates after upstream text splitting |
| Relationship to byte fallback | Provides the fallback alphabet that later merge stages build on | Often layered on top of byte fallback in GPT-style tokenizers instead of replacing it | Usually assumes word-like pre-tokenization rather than a byte-first fallback alphabet |
| Main tradeoff | Robust on messy text, but unusual strings can stay split into many small pieces | Simple and reusable merges, but learned pieces can look unnatural to readers | Works well for many text models, but depends more on the upstream text split |