Tokenisation over Bounded Alphabets is Hard

Violeta Kastreva, Philip Whittington, Dennis Komm, Tiago Pimentel

Introduction

Tokenization—the process of breaking text into subword units—is a fundamental bottleneck in modern Natural Language Processing (NLP). Before a Large Language Model (LLM) can process text, a tokenizer must convert raw strings into a sequence of subwords or tokens. Ideally, this process maximizes compression: the fewer tokens needed to represent a dataset, the more efficiently a model can be trained and executed.

This paper proves that finding the mathematically optimal tokenization strategy is computationally intractable (NP-complete and APX-hard) even for the simplest possible alphabets, such as binary (bits) or unary (a single repeated character). These results demonstrate that the difficulty of tokenization is a fundamental mathematical barrier, rigorously explaining why the field must rely on heuristics like Byte Pair Encoding (BPE) and UnigramLM.

The Problem: Bounded vs. Unbounded Alphabets

Previous theoretical work established that finding the most "compressible" vocabulary is NP-complete. However, those proofs relied on an unrealistic assumption: an "unboundedly large alphabet," essentially assuming an infinite variety of unique characters. In practice, real-world tokenizers operate over fixed, small alphabets like bytes (256 values) or Unicode characters.

The formal optimization objective of tokenization

The authors set out to answer a critical question: Is tokenization actually computationally easy when the alphabet is small? If tokenization were efficient for binary or byte-level inputs, researchers might be able to replace current "good enough" heuristics with truly optimal algorithms.

Methodology

The paper employs the tools of computational complexity theory. To prove that a problem is "hard," the authors use mathematical reductions: demonstrating that if one could solve the tokenization problem efficiently, one could also solve other famously difficult combinatorial problems (like 3-SAT or Vertex Cover).

They analyze two primary flavors of tokenization:

  1. Direct Tokenization: Selecting a fixed-size vocabulary that minimizes the total number of tokens required to encode a dataset.
  2. Bottom-up Tokenization: Selecting a sequence of "merge" operations (similar to BPE) to build a vocabulary that maximizes compression.

Rather than using standard NLP corpora, the authors construct intricate synthetic datasets (strings of '0's and '1's, or repeating 'a's) where the most efficient way to compress the string corresponds exactly to finding the solution to a known hard problem.

Key Insights and Results

  • The Hardness is Inherent: The difficulty of tokenization isn't an artifact of complex Unicode characters or massive vocabularies. It exists at the most basic level of information—bits. Both direct and bottom-up tokenization over a binary alphabet are NP-complete.
  • No "Perfect" Approximations: The paper proves APX-hardness. This means that not only is it hard to find the perfect tokenizer, but it is also impossible to create an algorithm that gets arbitrarily close to the perfect solution in polynomial time (unless P=NP). For binary direct tokenization, the authors calculated an explicit hardness-of-approximation constant of 1.000002. While small, this mathematically forbids the existence of a Polynomial-Time Approximation Scheme (PTAS).
  • Unary Hardness and the "Change-Making" Connection: Direct tokenization remains strongly NP-complete even for unary alphabets (where the only character is, for example, 'a'). The authors highlight a fascinating link between unary tokenization and the "Optimal Denomination Problem" in economics (choosing the best coin values for a currency system). Both are mathematically equivalent and computationally hard.
  • Justifying Heuristics: This research provides a rigorous theoretical justification for why popular tools like BPE and UnigramLM are greedy and heuristic. They aren't just lazy designs; they are practical, necessary responses to a fundamentally intractable problem.

Limitations and Future Directions

The study focuses exclusively on compression as the objective function. While compression correlates with model performance, it isn't the only metric of success. Future work could investigate the complexity of tokenization when the goal is to maximize downstream accuracy directly.

Additionally, while the authors proved a variant of unary bottom-up tokenization (Optimal Pair Encoding) is hard, the "standard" BPE-style bottom-up case for unary alphabets remains an open question. Finally, because the paper proves we cannot get arbitrarily close to the optimum, the authors suggest the field should shift toward finding algorithms with provable approximation guarantees (e.g., an algorithm guaranteed to be within a specific factor of the optimum) rather than relying solely on unproven heuristics.

Summary updated

BibTeX
@inproceedings{kastreva2026tokenisation,
  author = {Violeta Kastreva and Philip Whittington and Dennis Komm and Tiago Pimentel},
  title = {{Tokenisation over Bounded Alphabets is Hard}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=Xhf9YqwlM4},
}
Figure