NLP Educational Reference

Tokenization:
From words
to subwords

How machines learned to read — from rigid word dictionaries to subwords

01 What Is Tokenization & Why Does It Matter?

Tokenization is the bridge between raw text and numerical representation. Since machines process numbers, not strings, text must be converted into a sequence of integer IDs drawn from a vocabulary before any model can process it. Each unit in that sequence is a token.

"The model is tokenizing." →
The model is token izing .
→ [464, 2746, 318, 11241, 1710, 13]  ·  integer IDs into an embedding matrix

What, How, and Why

❓
What

Translation from text strings to integer IDs. The model never sees letters — only numbers that index into a learned embedding matrix.

⚙️
How

Modern systems use Subword Tokenization. Algorithms like BPE start with individual characters and iteratively merge the most frequent adjacent pairs into common subwords.

💡
Why

Reduces input complexity and vocabulary size. Without it, a model would need to learn every possible character sequence from scratch — computationally intractable.

Role in LLMs

LLMs have a fixed context window (e.g., 128k tokens). Efficient tokenization directly determines how much text fits within that window — more efficient tokenization means more context, better reasoning.

By sharing subword representations, models also generalize across related words: run, running, runner all share the subword run. This improves accuracy and reduces the parameters needed to learn language.

02 The Evolution of Tokenization

Research moved from rigid dictionary lookup to flexible learned subwords, driven entirely by one recurring failure: the Out-of-Vocabulary (OOV) problem — any word absent from the lexicon silently collapsed into a meaningless <UNK> token.

📚 Word Tokenization + Lexicons Pre-2016
↓ problem emerges
⚠️ OOV Crisis → <UNK> tokens destroy meaning
↓ first attempted fix
🔤 Character-Level Tokenization ~2015
↓ creates a new problem
⚡ Sequences too long · Characters carry no semantics
↓ the breakthrough
✅ Subword Tokenization — BPE, WordPiece, SentencePiece 2016–Now
↓ enables
🧠 Modern LLM Era — GPT, BERT, LLaMA, Claude 2018–Now
↓ emerging frontier
🚀 Tokenization-Free — CANINE, ByT5 2021 → Future
PRE-2016 · ERA 1
Word-Based + Lexicons

Text was split at word boundaries (spaces and punctuation). A lexicon mapped each known word to an integer ID. English has 170K+ words; Turkish and Finnish have millions of inflected forms — complete coverage was impossible.

A new word enters the language:
Covid → <UNK> all meaning lost
The OOV Crisis: "Bitcoiners" in 2010? <UNK>. "Covid" in 2019? <UNK>. Any neologism, brand name, or rare proper noun silently collapsed to a single meaningless token. The model was blind to vocabulary evolution.
~2015 · ERA 2
Character-Level Tokenization

Splitting text into individual characters eliminated OOV entirely — only 26–256 token types are ever needed. But it introduced a worse trade-off.

"unhappiness" — 11 tokens, no semantic meaning per token:
unhappiness
New problem: Sequences become 4× longer than word-based tokenization. The attention mechanism must span hundreds of individual characters to capture any word-level meaning. Context windows fill up instantly on normal documents.
2016–PRESENT · ERA 3
The Subword Revolution

BPE (Sennrich et al., 2016) introduced the decisive insight: learn token boundaries from data itself. Frequent words become single tokens; rare words decompose into meaningful morphological parts. No fixed dictionary is required — the vocabulary is learned.

"unhappiness" — 3 tokens, meaningful morphological units:
unhappiness
What this solved: No OOV. No lexicons. "unfriendable" tokenizes automatically — because un-, friend, and -able are already known subwords. The model generalizes to any unseen word through decomposition.
2021 – FUTURE · ERA 4
Tokenization-Free Models

Google's CANINE (2021) was the first pre-trained model with zero tokenization. It processes raw Unicode characters directly — no vocabulary, no fixed token set, 104 languages without any language-specific rules. The tokenizer component is eliminated entirely. See §05 for the full picture.

03 BPE — The Algorithm That Changed NLP

Byte Pair Encoding was originally a data compression algorithm from the 1990s. Sennrich et al. (2016) adapted it for neural machine translation with a simple insight: frequently co-occurring character pairs should become their own tokens.

The Algorithm

1
INIT — Split every word in the training corpus into individual characters. These characters are the starting vocabulary.
2
COUNT — Find the single most frequently occurring adjacent pair of tokens across the entire corpus.
3
MERGE — Combine that pair into one new token everywhere it appears. Add it to the vocabulary.
4
REPEAT — Return to step 2 until the vocabulary reaches the target size (typically 32K–100K tokens).

Worked Example

// Corpus: "lower" "lowest" "newest" // Step 0: Every word split to characters Initial: l o w e r · l o w e s t · n e w e s t Step 1: Most frequent pair: (e, s) → merge → "es" l o w e r · l o w es t · n e w es t Step 2: Most frequent pair: (es, t) → merge → "est" l o w e r · l o w est · n e w est Step 3: Most frequent pair: (l, o) → merge → "lo" lo w e r · lo w est · n e w est Step 4: Most frequent: (lo, w) → merge → "low" low e r · low est · n e w est // Vocabulary now includes: low, er, est, new, n, e, w... // Any unknown word decomposes from these known subwords automatically.

How the Three Major Variants Differ

All three algorithms share BPE's philosophy but differ in merge strategy and output format:

BPE (GPT-family) — merges by raw frequency · plain concatenation
unhappiness
WordPiece (BERT) — merges by corpus likelihood · ## marks continuation subwords
un##believ##able
SentencePiece (T5, ALBERT) — whitespace treated as a character ▁ · no pre-tokenization step needed
▁Hello▁world
Why decomposition works: Even without seeing "unfriendable" in training, a BPE model already knows un- (negation), friend (root concept), and -able (capability suffix). Morphological meaning is recovered through decomposition, not dictionary lookup.
04 Methods & Which Models Use Them

Today's tokenizers all share the subword philosophy but differ in merge strategy, output format, and architectural assumptions. Each co-evolved with a specific family of models.

MethodMerge StrategyDistinctive FeatureUsed In
BPE Raw frequency Simple; plain concatenation; language-agnostic GPT-2GPT-4LLaMA
WordPiece Maximizes corpus likelihood ## prefix marks continuation tokens BERTDistilBERT
SentencePiece Treats whitespace as a character No pre-tokenization; multilingual by default T5ALBERTXLNet
Unigram Starts large, prunes by loss Probabilistic; retains tokens minimizing perplexity Often paired with SentencePiece
Tiktoken Byte-level BPE on raw bytes Zero encoding failures — every byte value is valid GPT-4Claude

What Subword Tokenization Fixed

ProblemWord-Based EraSubword Era
Unknown words<UNK> — meaning destroyedDecomposed into subwords; no UNK ever
LexiconsRequired; always incompleteNot needed; vocabulary learned from data
New languagesCustom rules per languageOne tokenizer handles 100+ languages
Vocabulary size100K–1M+ word forms needed32K–100K subwords covers all of it
Morphologyrun / running treated as unrelatedShared subwords encode morphological links
05 The Future — From Tokenization-Free to Raw Text

Tokenization isn't being improved — it's being eliminated. In parallel, the preprocessing pipelines that preceded tokenization have also been abandoned. Both shifts are part of the same underlying pattern: deep learning learns better representations than human-engineered ones.

Why Subwords Are Still Falling Short

Language inequity: Non-Latin scripts and morphologically rich languages suffer 3–5× higher tokenization costs than English — a real computational and economic barrier to multilingual AI.

Fragmentation: BPE over-segments in multilingual settings, hurting cross-lingual transfer learning.

Static vocabularies: A fixed token set cannot adapt to new domains, code-switching, or emerging language.

Tokenization-Free Models

Google's CANINE (2021) was the first pre-trained encoder with zero tokenization. It processes raw Unicode characters using hash-based embeddings and strided convolutions for downsampling — no vocabulary required at any stage.

🔢
No Vocabulary

Character embeddings via hashing. Emojis, typos, code-switching, any Unicode — all handled identically without special cases.

📉
Fewer Params, Better Results

Outperforms mBERT by +5.7 F1 on TyDi QA with 28% fewer parameters and no fixed vocabulary.

🌍
104 Languages

No language-specific rules, dictionaries, or model variants — one architecture handles them all natively.

Active Research Directions (2024–2026)

DirectionDescriptionStatus
Byte-Level ModelsOperate on raw bytes (256 values). Eliminates all encoding edge-cases entirely.Active research
Neural TokenizationToken boundaries learned via RL or gradient descent — replaces frequency heuristics.2026 papers, promising
Hybrid ArchitecturesByte-level encoder + token-level transformer connected via cross-attention.Being explored
Adaptive DownsamplingDynamic sequence compression that varies with local text complexity.Research ongoing
Edge OptimizationCompressed learned codebooks for mobile and low-resource deployment.Critical open gap

Open Challenges

Sequence length: Characters are 4× longer than subwords; attention complexity is quadratic. Downsampling only partially compensates.

Text generation: Tokenization-free models excel at encoding (BERT-style) but character-level autoregressive generation (GPT-style) remains significantly harder.

Rare entity memorization: Character models sometimes struggle to retain rare proper nouns and specific facts.

The Bigger Shift: The Entire Preprocessing Pipeline Eliminated

Tokenization was only the last step in a longer pipeline that deep learning has now made obsolete. Every cleaning step once considered mandatory has been shown to hurt model performance — because each one encoded a human assumption the model is better off learning itself.

Classical NLP — every step was mandatory
Lowercase→ Remove punctuation→ Remove stopwords→ Stem / Lemmatize→ Tokenize→ Lexicon lookup→ Model
Modern deep learning — almost nothing required
Raw Text→ [Optional: Unicode normalization]→ Model
Old StepWhy It HurtWhat Replaced It
LowercasingErased "Apple" (company) vs "apple" (fruit)Model learns case sensitivity as a feature
Stopword removalDeleted "not" in "not good" — flipped sentimentAttention learns importance weighting dynamically
Stemmingrun / running / ran collapsed → tense information lostSubwords preserve morphology and conjugation
Punctuation stripping"!" "?" "." carry sentiment, emphasis, and syntaxModel treats punctuation as semantic signals
Lexicon lookupOOV = silent failureSubwords / bytes = unbounded effective vocabulary
The core insight: Every preprocessing step encoded a human bias. Neural networks trained on raw, unmodified text consistently outperform those trained on carefully cleaned text — because they learn better, unbiased representations directly from signal.

The Same Inversion Across All of AI

This is not unique to NLP. Every field in deep learning has undergone the same transition — away from hand-engineered intermediate representations and toward learning from raw signals.

Computer Vision
SIFT / HOG features
↓
raw pixels
↓
CNNs learn features
Speech
Phoneme extraction
↓
raw waveforms
↓
wav2vec learns repr.
NLP
POS tags / parse trees
↓
raw text
↓
Transformers learn all
06 Live Tokenization Demo

Type any word or phrase and switch between strategies to see how the same input is tokenized differently across eras.

07 References