The Foundations of Tokenization: Statistical and Computational Concerns

Juan Luis Gastaldi, John Terilla, Luca Malagutti, Brian DuSell, Tim Vieira, Ryan Cotterell

Introduction

Tokenization is the "hidden" preprocessing step in nearly every Natural Language Processing (NLP) pipeline. Despite its ubiquity and the massive leaps in Large Language Model (LLM) performance it enables, tokenization lacks a rigorous mathematical foundation. Algorithms like Byte-Pair Encoding (BPE), WordPiece, or Unigram remain largely empirical.

This paper introduces a formal framework using stochastic maps to prove exactly when a tokenizer is "safe"—meaning it preserves the statistical consistency of a language model. It also identifies the specific computational properties that make tokenizers tractable in practice.

The Problem with Empirical Tokenization

We know tokenization causes headaches: it can introduce "spurious ambiguity" (where the model is confused by multiple ways to represent the same string), alignment issues, and inconsistent scoring.

Until now, the field lacked a unified mathematical language to ask a critical question: Does training a model on these tokens actually allow us to recover the true probability of the original text? The authors bridge this gap by moving away from heuristics and toward a formal theory of how information flows from characters to tokens and back again.

Formalizing Tokenization with Stochastic Maps

The authors build their framework on the category of stochastic maps. Instead of viewing an encoder as a simple deterministic function, they treat it as a map that assigns a probability distribution over token sequences to every input string. This generalizes everything from standard BPE to the "stochastic" tokenization often used for regularization.

Encoder-decoder mappings between character and token sequences

In this framework, a tokenizer $\mathcal{T}$ is defined as an encoder-decoder pair $(\tau, \kappa)$:

  • $\tau$ (the encoder): Maps character strings (from set $\Sigma^*$) to token sequences (in set $\Delta^*$).
  • $\kappa$ (the decoder): Maps token sequences back to character strings.

Consistency & Exactness

A tokenizer is defined as consistent if the decoded version of the token-level distribution perfectly matches the original character-level distribution (expressed mathematically as $ \kappa \tau p^\star = p^\star $). A tokenizer is considered exact if this consistency holds for any possible target distribution.

Key Insights and Theoretical Guarantees

The Fundamental Principle of Consistency

The paper's cornerstone result (Theorem 3.1) proves that a tokenizer preserves the consistency of statistical estimators if and only if the composition of the decoder and encoder acts as the identity on the target distribution. If this condition fails, the resulting language model is mathematically guaranteed to be biased, regardless of how much training data is used.

An illustration of statistical inconsistency where the decoded distribution fails to match the original

The Trap of Normalization and <unk> Tokens

Common preprocessing steps—such as lowercasing, stripping accents, or removing punctuation—make the encoder non-injective. This "lossy" encoding is identified as a primary source of statistical inconsistency. Similarly, mapping out-of-vocabulary characters to a special <unk> token violates the injectivity required for consistency, effectively breaking the model's ability to accurately represent those strings in the limit.

Tractability via Multiplicativity

Most popular tokenizers are multiplicative, meaning the decoding of a sequence is simply the concatenation of the decoding of its individual parts. The authors prove (Proposition 5.1) that if a multiplicative tokenizer has a "trivial kernel" (it doesn't delete tokens during decoding), the length of any token sequence $\delta$ is less than or equal to the length of the decoded text $\sigma$ ($|\delta| \leq |\sigma|$). This guarantees that the number of ways to tokenize a string is finite and bounded by the string's length, ensuring computational finiteness.

Sequentiality and Bounded Variation

By introducing the concept of bounded variation, the authors provide the conditions under which a tokenizer can be implemented efficiently. Proposition 5.2 proves that all multiplicative functions have bounded variation, successfully linking modern subword tokenization to the classical theory of subsequential finite-state transducers (FSTs).

Limitations and Future Work

While this paper provides robust theoretical foundations, it does not propose a new "optimal" tokenizer algorithm. It successfully identifies why current methods can be inconsistent, but notes that rigorously handling spurious ambiguity remains a practical challenge.

The authors suggest that future research should leverage this framework to develop algorithms capable of converting token-level language models back into character-level ones without losing statistical guarantees. This process requires "prefix monotonicity," a property briefly explored in the text. Ultimately, this work sets the stage for provably correct representation learning in NLP, moving tokenization from a dark art to a rigorous science.

Summary updated

BibTeX
@inproceedings{gastaldi2025foundations,
  author = {Juan Luis Gastaldi and John Terilla and Luca Malagutti and Brian DuSell and Tim Vieira and Ryan Cotterell},
  title = {{The Foundations of Tokenization: Statistical and Computational Concerns}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=B5iOSxM2I0},
}
Figure