Tokenization
Splitting text into the units a language model reads and writes, each mapped to an integer ID.
Tokenization turns raw text into a sequence of tokens, the units a language model actually reads and writes. Each token is an integer ID from a fixed vocabulary, typically somewhere between about 30,000 and 200,000 entries. The model never sees letters or words directly; it sees IDs, looks each one up as a vector, and predicts the ID of the next token.
The tokenizer is trained once, before the model, and then frozen with it. That means a model and its tokenizer are a matched pair: you cannot swap one without retraining the other. It also means quirks of the tokenizer become quirks of the model. A word split into odd pieces is harder to spell backwards, numbers may be split inconsistently, and languages that were rare in the tokenizer's training data need more tokens for the same sentence.
Tokens are the unit of account for almost everything practical. Context windows, rate limits, latency, and price are all measured in tokens, not characters. A rough rule for English prose is about four characters, or three quarters of a word, per token, but code, other languages, and unusual formatting can be much denser. When cost or context length matters, count with the model's own tokenizer rather than guessing.
Most modern tokenizers work at the subword level, so common words stay whole while rare words are built from smaller familiar pieces. That design keeps the vocabulary small enough to train while guaranteeing that any input can be encoded.
Subword tokenization
Splitting text into pieces between characters and words, so common words stay whole and rare ones are built from parts.
Subword tokenization splits text into pieces that are usually larger than single characters but often smaller than whole words, each mapped to an integer ID. Frequent words such as "the" or "function" get one token, while a rare word such as "tokenizable" is assembled from familiar pieces like "token," "iz," and "able." Exact splits depend on the tokenizer.
It is a compromise between two bad extremes. Whole-word vocabularies would need millions of entries and still fail on new words, typos, and names. Character-level input never fails but makes sequences several times longer, which is expensive for attention. Subwords keep the vocabulary manageable, keep sequences reasonably short, and ensure no input hits a dead end. The common algorithms are byte-pair encoding, WordPiece, and Unigram.
Byte-pair encoding
A method for building a subword vocabulary by repeatedly merging the most frequent adjacent pair of symbols.
Byte-pair encoding, or BPE, builds a subword vocabulary from training text. It starts with single symbols, counts every adjacent pair, merges the most frequent pair into a new symbol, and repeats until the vocabulary reaches a target size. The ordered list of merges becomes the tokenizer: new text is split into symbols and the same merges are applied in order. The idea began as a data compression method and was adapted for machine translation in 2016.
Byte-level BPE starts from the 256 possible byte values instead of characters, so any string, including emoji, accented letters, and binary-looking data, can be encoded without an unknown token. Most modern language model tokenizers use some form of byte-level BPE. Because merges reflect the training text, text unlike it, such as rare languages or unusual code, splits into more tokens and costs more to process.