﻿# BPE tokenization: merge rules turn strings into model units

Byte-pair encoding learns ranked merge rules over symbol sequences. Follow a toy merge to understand vocabulary construction, segmentation and unseen words.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/bpe-merge-rules-segmentation/
Language: en

A tokenizer must represent text as entries from a finite vocabulary. Byte-pair encoding builds reusable pieces by learning which adjacent symbols to merge. The resulting algorithm is easier to understand as a ranked transformation of a symbol sequence than as an intelligent word splitter that independently decides the meaning of each term.

## Training counts adjacent pairs in a representation

A basic BPE training procedure starts from an initial symbol inventory and repeatedly chooses frequent adjacent pairs under its defined corpus and boundary rules. Merging a pair creates a new reusable symbol and changes subsequent pair counts. The initial symbols may be characters or a byte-derived representation depending on the tokenizer family. Pre-tokenization and normalization can constrain what pairs are available. These surrounding stages are part of the tokenizer contract; the phrase BPE alone does not establish every possible segmentation boundary or text transformation.

## A toy merge sequence makes ranks concrete

Imagine an allowed segment containing the symbols l, o and w. A learned rule merges l with o, and a later rule merges the resulting piece with w. The segment can become a single vocabulary piece through those ranked operations. Another learned ordering could lead to different intermediate pieces. This is a deliberately small teaching example, not the actual vocabulary of a named model. It demonstrates why saving only visible token strings without the merge information can be insufficient to reproduce a tokenizer’s segmentation decisions.

## Unseen words can use familiar pieces

A term absent as a whole vocabulary entry may still be encoded as a sequence of known pieces. This supports open-ended text representation within the capabilities of the initial alphabet and fallback policy. It does not guarantee that the model understands an unfamiliar term or that every language uses an equal number of tokens per word. A programming identifier and a common prose word can split differently because the learned statistics and boundary rules differ. Tokenization describes representation; semantic competence is a separate property of the trained model.

## Preserve the entire pipeline when comparing counts

Store the normalizer, pre-tokenizer, vocabulary, merge ranks and special-token processing together. Compare token identifiers and round-trip decoding on representative strings, including whitespace and technical terms. Two tokenizers called BPE can disagree without either being broken. An unexplained count change can result from preprocessing rather than model behavior. Making the ranked merge process explicit helps diagnose such differences while avoiding unsupported claims that a shorter segmentation necessarily implies better reasoning or lower error on every downstream task.

## Primary research and implementation references

- [Neural Machine Translation of Rare Words with Subword Units](https://arxiv.org/abs/1508.07909).

- [SentencePiece: A Simple and Language Independent Subword Tokenizer](https://arxiv.org/abs/1808.06226).

- [Hugging Face: The Tokenization Pipeline](https://huggingface.co/docs/tokenizers/pipeline).

## Related engineering context

[Reproducible inference stacks: preserving a GPU pilot’s result](/journal/software-stack-reproducibility/); [A GPU inference benchmark you can trust](/journal/inference-benchmark-method/).
