Tokenization
Also known as: Tokenisation
The process of splitting text into smaller units called tokens, such as words, subwords or characters, that a language model can process as numbers.
Tokenization converts raw text into a sequence of discrete units that a model can work with. Each token is mapped to an integer ID from a fixed vocabulary, and each ID is then mapped to a vector, or embedding, that the model processes. Tokens can be whole words, pieces of words, single characters or bytes. In English, a common rule of thumb is that one token corresponds to roughly three quarters of a word, but the ratio depends on the tokenizer, the language and the kind of text being processed.
Most large language models use subword tokenizers, which balance vocabulary size against sequence length. Byte pair encoding, originally a data compression method, was adapted for neural machine translation in the mid-2010s: it starts from individual characters or bytes and repeatedly merges the most frequent adjacent pairs into larger tokens. Related schemes include WordPiece, used by Google's BERT, and the unigram language model approach available in the SentencePiece library. Frequent words become single tokens, while rare words are assembled from several pieces.
Tokenization has practical consequences. Usage limits, pricing and the size of a context window are counted in tokens, and languages that are poorly represented in a tokenizer's training data often need more tokens for the same content, making them costlier and slower to process. Token boundaries also help explain why models can struggle with tasks like counting letters or reversing words. Outside AI the word has other meanings: in data security, tokenization replaces sensitive values such as card numbers with surrogate tokens.
Key points
- Tokens can be words, subword fragments, characters or bytes, depending on the tokenizer.
- Byte pair encoding and related subword methods are standard in large language models.
- Context limits and API pricing for language models are measured in tokens.
- Languages underrepresented in tokenizer training data typically require more tokens per sentence in language processing systems.
From the source
AI tokenization is the process of converting text into smaller, standardized units called tokens that language models can mathematically process. Depending on the tokenization method used, these tokens can represent whole words, parts of words (subwords), or even individual characters.
Related entries
Embedding
A learned numerical vector that represents an item such as a word, document, image or user so that similar items have nearby vectors.
The maximum amount of input, measured in tokens, that a language model can take into account at once, including the text it is generating.
Neural network trained on very large amounts of text to predict the next token, able to generate language and perform many tasks from prompts.
Field of AI and linguistics concerned with enabling computers to analyze, understand and generate human language in text and speech.
Neural network architecture based on self-attention, introduced in 2017, that underlies most large language models and many vision and audio models.
Inference
The stage at which a trained machine learning model is run on fresh inputs to produce predictions or generated outputs, as distinct from training.
Featured in guides
Referenced by
Other entries that discuss or point to Tokenization.