Introduction
Tokenization is the foundational preprocessing step for Large Language Models (LLMs), transforming raw text into a sequence of subword units from a finite vocabulary. A primary objective in designing these vocabularies is to maximize compression: the more efficiently a dataset is represented, the more information can be packed into a model's fixed context window. While empirical heuristics like Byte Pair Encoding (BPE) and UnigramLM are industry standards, the theoretical limits of optimal tokenization have remained an area of active research. This paper demonstrates that finding a truly optimal tokenizer is NP-complete, even under the most restrictive conditions, such as binary or unary alphabets.
The Problem of Bounded Alphabets
Previous theoretical work established that finding the most efficient tokenizer is an NP-complete problem. However, those proofs relied on the assumption of an unbounded alphabet—essentially allowing for an infinite variety of unique characters. In practical NLP, we operate within strictly bounded alphabets, such as the 256 possible values of a byte or the defined range of Unicode characters.
The central question addressed by this research is whether the tokenization problem becomes computationally tractable when the alphabet size is small and fixed. The authors provide a definitive negative answer, proving that the inherent complexity of the task persists even in the simplest possible character sets.
Methodology: Reductions and Mathematical Gadgets
The authors analyze two primary paradigms of tokenization:
- Direct Tokenization: Selecting a vocabulary of size $K$ that minimizes the total token count for a given dataset.
- Bottom-up Tokenization: An iterative process, exemplified by BPE, where the most frequent adjacent pairs are merged to form new tokens.
To establish NP-completeness, the researchers employ gap-preserving reductions from established hard problems. For binary alphabets (size $n=2$), they reduce from 3-occurrence MAX2SAT. For unary alphabets (size $n=1$), they reduce from the Vertex Cover problem. These reductions involve the construction of "gadgets"—mathematically engineered strings that force any potential "optimal" tokenizer to solve the underlying hard logical or graph-based problem.
Key Insights
The Binary and Unary Cases
The paper proves that even with an alphabet consisting only of 0s and 1s, finding the optimal tokenizer is NP-complete. This suggests that the difficulty of tokenization is not a byproduct of character diversity but is fundamental to the combinatorial nature of string matching and substitution.
More surprisingly, the problem remains "strongly NP-complete" even for a unary alphabet (a single repeated character). In this context, the task is mathematically equivalent to the Change-Making Problem (or the Optimal Denomination Problem), which asks for the best set of coin denominations to represent a specific set of values using the fewest coins.
Hardness of Approximation
Beyond proving that finding the exact optimum is hard, the authors demonstrate that these problems lack a Polynomial-Time Approximation Scheme (PTAS). This means it is mathematically impossible to create an algorithm that efficiently finds a solution within an arbitrary margin of error (e.g., within 0.01% of the optimum) unless P = NP. The authors establish specific lower bounds for the approximation ratio, proving that even "almost perfect" solutions are out of reach.
The Hierarchy of Hardness
The research establishes a hierarchy: if tokenization is hard for an alphabet of size $n$, it is necessarily hard for any alphabet of size $> n$. By proving hardness for $n=1$ and $n=2$, the authors effectively extend these results to all practical alphabets used in computing, including ASCII, UTF-8, and beyond.
Results and Implications
The study provides formal proofs for several variants of the problem:
- Binary Tokenization: Both direct and bottom-up variants are NP-complete and hard to approximate.
- Unary Tokenization: Direct tokenization is strongly NP-complete.
- Optimal Pair Encoding (OPE): A variant of bottom-up tokenization is shown to be at least weakly NP-complete via a reduction from the Addition Chain problem.
These results explain why the NLP community relies on greedy heuristics. Since a perfect solution is computationally impossible, the focus shifts from finding the "best" tokenizer to finding "good enough" solutions that balance compression with computational efficiency.
Limitations and Future Outlook
The study focuses exclusively on compression as the optimization metric. While compression is a strong proxy for model performance, other factors—such as morphological preservation, subword alignment, and vocabulary balance—also play critical roles in LLM efficacy.
Future research directions include:
- Tightening Approximation Bounds: While the current lower bounds are theoretically significant, they are numerically small. Larger constants would provide a clearer picture of the practical gap between heuristics and the theoretical optimum.
- Unary Bottom-up Complexity: The complexity of standard bottom-up tokenization over a unary alphabet remains an open mathematical question.
- Provable Approximations: The authors advocate for the development of new algorithms that offer provable approximation guarantees, moving the field toward more robust alternatives to current greedy methods.
Summary updated