Byte Pair Encoding

A subword tokenizer that learns frequent text pieces by repeatedly merging common neighboring symbols.

Byte pair encoding (BPE) is a tokenizer that builds a vocabulary from reusable text pieces instead of whole words, which helps models cover rare spellings and new words without exploding vocabulary size.

At a glance

Released

June 2016

Authors

Rico Sennrich, Barry Haddow, Alexandra Birch

Optimizes

  • Open Vocabulary Coverage
  • Vocabulary Size Efficiency

Example models

What It Is

Byte pair encoding (BPE) is a subword tokenizer. Instead of treating every whole word as one fixed unit, it starts from smaller symbols and learns which neighboring pieces appear together often enough to be merged into a larger reusable token.

Why It Exists

BPE balances two pressures at once: the vocabulary should stay small enough to manage, but the tokenizer should still cover messy real text. Reusing common pieces like `ing`, `tion`, or `low` lets one vocabulary handle many rare or unseen words.

How It Works

BPE begins with very small symbols, then repeatedly merges the most frequent adjacent pair in the training text. A simple example starts with pieces like `l` `o` `w`, `l` `o` `w` `e` `r`, and `n` `e` `w` `e` `s` `t`. If `l` + `o` appears often, the tokenizer adds `lo`. If `lo` + `w` is still common, it adds `low`. After enough rounds, words such as `lower` can be tokenized as pieces like `low` + `er` instead of six separate characters.

Math Or Compute Schema

The notation below compresses one training step into a single rule: take the current inventory of pieces, find the most useful neighboring pair, and merge that pair into a new subword unit.
One byte pair encoding merge step
τt+1=merge⁡(τt,pt)\tau_{t+1} = \operatorname{merge}(\tau_t, p_t)
τt\tau_t
Current token-piece inventory after merge step t.
ptp_t
Most useful neighboring pair chosen at step t.
τt+1\tau_{t+1}
Updated inventory after that pair becomes one new subword piece.
tt
Merge-step index.

Compared To Nearby Modules

BPE is one of several common subword tokenizers. WordPiece uses a similar piece-building idea but chooses merges with a different scoring rule, while SentencePiece is often trained directly on raw text and can avoid pre-tokenization assumptions about spaces or words.
Comparison dimensionBPEWordPieceSentencePiece
Starting view of textStarts from small symbols and merges common neighborsStarts from subword candidates and grows a vocabularyTrains directly on raw text without fixed word boundaries
How new pieces are chosenUsually picks the most frequent adjacent pairUses a scoring rule instead of raw pair frequency aloneCan learn pieces with BPE-style or unigram-style training
Handling of spaces and bytesOften paired with byte-level handling in GPT-style tokenizersUsually assumes a word-like pre-tokenization step firstTreats spaces as regular symbols so boundaries stay explicit
Main tradeoffSimple and reusable, but learned pieces can look unnaturalWorks well for many text models, but depends more on the upstream text splitFlexible across languages, but its learned pieces may differ more from reader intuition

Example Architectures

Readers run into BPE most often in GPT-style language models and their descendants. Those systems need a tokenizer that can survive code, punctuation, names, and invented words without requiring a separate vocabulary entry for every full string.

Limitations And Tradeoffs

BPE pieces can look awkward to humans because the merge boundaries are chosen for frequency, not readability. Tokenizer mismatch also matters: if a model was trained with one BPE vocabulary and you feed text through another tokenizer, token counts and meaning-bearing pieces can shift in ways the model did not learn.

Why It Still Matters

BPE remains a foundation concept because it sits on the path between raw text and model input. Once you understand how it builds subword units, it becomes much easier to compare tokenizers, estimate context usage, and understand why the same sentence can occupy different numbers of tokens across model families.

Tags

References

  1. Sennrich, Rico, Barry Haddow, and Alexandra Birch. "Neural Machine Translation of Rare Words with Subword Units." arXiv, 10 June 2016, arxiv.org/abs/1508.07909.