Inferensys

Glossary

Tokenization

The fundamental preprocessing step of segmenting raw text into atomic units called tokens, which are the numerical input IDs consumed by embedding models and language models.
ML engineer running AI model benchmarks, performance charts on multiple screens, late night home office setup.
FUNDAMENTAL PREPROCESSING

What is Tokenization?

Tokenization is the foundational preprocessing step that segments raw text into atomic units called tokens, which are the numerical input IDs consumed by embedding models and language models.

Tokenization is the algorithmic process of dissecting a raw string of text into a sequence of discrete, atomic units known as tokens. These tokens serve as the fundamental bridge between human-readable language and machine computation, as every modern language model requires input to be converted from a string into a list of integer IDs before processing. The tokenizer's vocabulary defines the complete set of known sub-word units, and any text fed into a model must be mapped to this predefined set of numerical identifiers.

Modern tokenization relies on sub-word algorithms like Byte-Pair Encoding (BPE) or WordPiece, which strike a balance between character-level and word-level representations. These methods allow models to handle an open vocabulary by decomposing rare or unseen words into known, frequent sub-word fragments. The resulting token count directly impacts a model's context window limit and inference latency, making the choice of tokenizer a critical architectural decision that affects downstream chunking strategies and embedding quality.

SUBSET OF TOKENIZATION ALGORITHMS

Tokenization Methods Compared

A technical comparison of the most common subword tokenization algorithms used in modern embedding models and large language models, evaluating their handling of rare words, vocabulary efficiency, and impact on downstream semantic retrieval.

FeatureBPEWordPieceUnigram LMSentencePiece

Core Mechanism

Iteratively merges the most frequent pair of bytes or characters

Merges pairs that maximize training data likelihood

Starts with a large vocabulary and prunes tokens that least improve likelihood

Language-agnostic framework implementing BPE or Unigram with lossless normalization

Vocabulary Basis

Subword units from frequent byte pairs

Subword units selected by probabilistic gain

Probabilistic subword units from a pruned inventory

Raw byte or character sequences, configurable algorithm

Handles Rare/Unknown Words

Lossless Tokenization

Whitespace Agnostic

Training Speed

Fast

Moderate

Slow

Configurable (depends on underlying algorithm)

Vocabulary Efficiency

Moderate

High

Very High

Configurable

Primary Use Case

GPT-series models, RoBERTa, LLaMA

BERT, DistilBERT

T5, XLNet, ALBERT

Multilingual models, T5, LLaMA, PaLM

FUNDAMENTAL MECHANICS

Key Properties of Tokenization

Tokenization is the critical preprocessing step that bridges raw text and numerical computation. The choice of algorithm directly impacts vocabulary size, handling of out-of-vocabulary terms, and the semantic granularity available to downstream models.

01

Subword Segmentation

Modern tokenizers use subword algorithms like Byte-Pair Encoding (BPE) or WordPiece to balance vocabulary size and coverage. Instead of storing every word, they decompose rare terms into frequent subword units.

  • Example: The word 'tokenization' might split into ['token', 'ization']
  • Benefit: Eliminates out-of-vocabulary (OOV) tokens entirely
  • Mechanism: Iteratively merges the most frequent adjacent byte pairs in a training corpus
02

Vocabulary Construction

The tokenizer's vocabulary is a fixed lookup table mapping subword units to unique integer IDs. This vocabulary is built during a training phase on a representative corpus and remains frozen during inference.

  • Size: Typically 30,000 to 250,000 tokens for large language models
  • Impact: A larger vocabulary encodes more information per token but increases embedding matrix size
  • Special Tokens: Includes control tokens like [CLS], [SEP], [PAD], and [UNK]
03

Context Window Constraints

The token count of input text directly consumes the model's fixed context window. Tokenization efficiency varies by language and domain, creating a hidden performance multiplier.

  • English: ~1.3 tokens per word on average
  • Code: Often more token-efficient due to repetitive syntax
  • Non-English: Languages like Thai or Japanese can require 3-5x more tokens per semantic unit
  • Strategy: Token-aware chunking prevents mid-thought truncation
04

Byte-Level Encoding

Byte-level tokenizers like those used in GPT models operate directly on UTF-8 bytes rather than Unicode characters. This provides a universal foundation that can represent any text without a separate pre-tokenization step.

  • Advantage: Robust handling of emoji, code, and malformed text
  • Base Vocabulary: 256 byte values serve as the atomic units
  • Result: A truly language-agnostic tokenization scheme
05

Tokenization Drift

Mismatched tokenization between the embedding model and the generative model causes silent performance degradation. The same text can produce different token sequences depending on the tokenizer.

  • Symptom: Poor retrieval quality despite correct semantic indexing
  • Cause: Embedding model uses WordPiece, but LLM uses BPE
  • Mitigation: Always pair models with their canonical tokenizer; never mix tokenizer artifacts across model families
06

Pre-tokenization Normalization

Before subword splitting, text undergoes normalization steps that permanently alter the input. These transformations are lossy and irreversible.

  • Lowercasing: Destroys case information (BERT uncased)
  • Unicode Normalization: NFKC/NFKD forms standardize characters
  • Whitespace Splitting: Many tokenizers split on whitespace first, making them blind to languages without spaces
  • Critical Rule: Apply identical normalization at both indexing and query time
TOKENIZATION DEEP DIVE

Frequently Asked Questions

Explore the fundamental mechanics of tokenization, the critical preprocessing step that converts raw text into the numerical inputs consumed by embedding models and language models.

Tokenization is the fundamental preprocessing step that segments a raw string of text into a sequence of discrete atomic units called tokens, which are then mapped to unique integer IDs from a fixed vocabulary. Unlike simple whitespace splitting, modern tokenization uses subword algorithms like Byte-Pair Encoding (BPE) or WordPiece to balance vocabulary size against out-of-vocabulary rates. The process works by iteratively merging the most frequent adjacent pairs of characters or bytes in a training corpus to build a mergeable vocabulary. During inference, an input string is decomposed by applying these learned merges greedily, converting the text into a list of integer IDs that can be consumed by a neural network's embedding layer. This mechanism allows a model with a vocabulary of 32,000 tokens to represent virtually any word by composing it from smaller, reusable subword fragments.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.