Tokenization is the computational process of dissecting a continuous sequence of text into discrete units, or tokens. These tokens—which can be words, subwords, or individual characters—transform unstructured strings into a structured sequence that a machine learning model can digest. This step is mandatory because language models operate on numerical vectors, not raw text; the tokenizer's vocabulary defines the model's fundamental linguistic building blocks.
Glossary
Tokenization

What is Tokenization?
Tokenization is the foundational process of segmenting a raw string of text into discrete, meaningful units called tokens, which serve as the primary input for downstream natural language processing models.
Modern architectures predominantly use subword tokenization algorithms like Byte-Pair Encoding (BPE) or WordPiece to balance vocabulary size against out-of-vocabulary issues. Unlike simple whitespace splitting, subword methods decompose rare words into frequent morphological fragments (e.g., 'tokenization' into 'token' and 'ization'), allowing the model to generalize morphological patterns. The output is a sequence of integer IDs mapped from the tokenizer's vocabulary, ready for the embedding layer.
Key Features of Modern Tokenization
Modern tokenization has evolved beyond simple whitespace splitting into a critical preprocessing step that balances vocabulary size, out-of-vocabulary handling, and semantic granularity for downstream models.
Subword Segmentation
Modern tokenizers decompose text into subword units rather than whole words, striking a balance between character-level and word-level representations. This approach handles morphologically rich languages and rare terms by breaking them into known fragments. For example, the word 'unhappiness' might be segmented into 'un', 'happiness', or further into 'un', 'happi', 'ness'. This ensures the model never encounters a true out-of-vocabulary token, as any unknown word can be constructed from its constituent subword pieces.
WordPiece Tokenization
WordPiece, used by BERT and its derivatives, selects subword units based on a likelihood maximization objective rather than raw frequency. The algorithm evaluates all possible merges and chooses the one that maximizes the training data's likelihood under a unigram language model. This produces a vocabulary where each token contributes meaningfully to the probability of the sequence. Unlike BPE, WordPiece uses a special '##' prefix to denote tokens that are continuations of a word, such as 'play' and '##ing' for the word 'playing'.
Special Tokens & Control Codes
Tokenizers inject reserved tokens into the vocabulary to control model behavior and structure input sequences. Common examples include:
- [CLS]: A classification token prepended to sequences in BERT, whose final hidden state represents the aggregate sequence meaning.
- [SEP]: A separator token used to delineate sentence boundaries in pair-input tasks.
- [PAD]: A padding token ensuring all sequences in a batch have uniform length.
- [MASK]: A placeholder token for masked language modeling objectives.
- <|endoftext|>: A document boundary token used in GPT models to signal the end of a text segment.
Tokenization Mismatch & Glitch Tokens
A critical failure mode occurs when a model's tokenizer is mismatched from its training data distribution, leading to glitch tokens or degraded performance. For example, a tokenizer trained on English text may fragment a programming language's syntax into nonsensical subword units, destroying structural meaning. Similarly, anomalous token sequences can trigger undefined model behavior. SolidGoldMagikarp is a notorious example of a glitch token in GPT-2's vocabulary that caused nonsensical completions. Robust systems must ensure strict tokenizer-model alignment and monitor for anomalous token activations.
Frequently Asked Questions
Clear, technical answers to the most common questions about the foundational NLP process of breaking text into discrete units for machine learning models.
Tokenization is the foundational natural language processing (NLP) step of segmenting a raw string of text into a sequence of discrete units called tokens. These tokens—which can be words, subwords, or individual characters—serve as the atomic input for downstream models. The process works by applying a specific algorithm, such as Byte-Pair Encoding (BPE) or WordPiece, to split text based on a pre-built vocabulary. For example, the sentence "The quick brown fox" might be tokenized into ["The", "quick", "brown", "fox"] in a word-level scheme, or ["The", "quick", "brown", "fox"] with a subword algorithm splitting an unknown word like "unhappiness" into ["un", "happiness"]. This conversion from human-readable text to machine-readable integer IDs is non-negotiable; a language model cannot process raw text directly. The tokenizer's vocabulary size and splitting rules directly control the model's ability to handle out-of-vocabulary (OOV) words and the overall sequence length, making it a critical architectural decision.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Tokenization is the critical first step in any NLP pipeline. The choice of tokenization strategy directly impacts vocabulary size, handling of out-of-vocabulary words, and downstream model performance.

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us