cs.CLNov 25, 2026
SaveTokenisation is not in APX
Organizations: Department of Computer Science, ETH Zürich
Abstract
In this paper, we prove that, unless P=NP, no polynomial-time algorithm can find a tokeniser whose objective is within any constant factor of the optimum, meaning that tokenisation is not in the APX complexity class. We prove this for direct and bottom-up tokenisation, under both a compression or unigram log-likelihood objectives, and for binary or larger alphabets. We further show that, even over unary alphabets, direct tokenisation is APX-hard, and thus admits no polynomial-time approximation scheme.
Figures & tables
Figure 1: Approximation ratios ruled out for tokenisation, assuming . A ratio of means exact solutions ( -hardness), some constant ( -hardness), and “any ” every constant (not in ). Under compression, is achieved by character-level tokenisation.
Appendix figures & tables7 assets
Supplementary material from the paper’s appendix.
Appendix
Figure 2: (a) Each symbol becomes blocks {\color[rgb]{0.9961,0.3789,0}\texttt{enc}}_{j}({\color[rgb]{0.3281,0.4961,0.9375}c}) , each a start marker {\color[rgb]{0.3281,0.4961,0.9375}1}{\color[rgb]{0.3281,0.4961,0.9375}1} followed by an identifier of ({\color[rgb]{0.3281,0.4961,0.9375}c},j) . (b) Each boundary cuts at most one block, so fewer than boundaries leave some index uncut; the -blocks of each token spell a word, and these words generate .
Figure 3: The -blow-up of a triangle ( Definition 3 ). Each edge becomes a complete bipartite graph between two clusters, drawn in the edge’s colour.
Figure 4: The source string of Eq. 58 , for the path – – and {\color[rgb]{0,0,0}\lambda}=1 (for illustration only, as this graph is not cubic). (a) The graph has four arcs and six walks, {\color[rgb]{0.3281,0.4961,0.9375}aba} , {\color[rgb]{0.3281,0.4961,0.9375}abc} , {\color[rgb]{0.3281,0.4961,0.9375}cba} , {\color[rgb]{0.3281,0.4961,0.9375}cbc} , {\color[rgb]{0.3281,0.4961,0.9375}bab} , and {\color[rgb]{0.3281,0.4961,0.9375}bcb} ; with distinct separators, its source string is {\color[rgb]{0.3281,0.4961,0.9375}\mathbf{w}}={\color[rgb]{0.3281,0.4961,0.9375}aba}{\color[rgb]{0.3281,0.4961,0.9375}\diamond_{1}}{\color[rgb]{0.3281,0.4961,0.9375}abc}{\color[rgb]{0.3281,0.4961,0.9375}\diamond_{2}}{\color[rgb]{0.3281,0.4961,0.9375}cba}{\color[rgb]{0.3281,0.4961,0.9375}\diamond_{3}}{\color[rgb]{0.3281,0.4961,0.9375}cbc}{\color[rgb]{0.3281,0.4961,0.9375}\diamond_{4}}{\color[rgb]{0.3281,0.4961,0.9375}bab}{\color[rgb]{0.3281,0.4961,0.9375}\diamond_{5}}{\color[rgb]{0.3281,0.4961,0.9375}bcb}{\color[rgb]{0.3281,0.4961,0.9375}\diamond_{6}}{\color[rgb]{0.3281,0.4961,0.9375}\#} , of length 4{\color[rgb]{0,0,0}M}+1=25 . (b) A maximum cut, with coloured {\color[rgb]{0,0,0}B} and coloured {\color[rgb]{0,0,0}W} . The two arcs from {\color[rgb]{0,0,0}B} to {\color[rgb]{0,0,0}W} are kept (solid); the other two arcs, and , are merged (dashed) and form the covering set {\color[rgb]{0,0,0}\mathcal{U}}^{\star} of Lemma 6 . (c) Merging these two bigrams shortens every walk by one token (phase 1 of Lemma 7 ). The remaining 3{\color[rgb]{0,0,0}M}+1=19 tokens are then joined by merges (phase 2), so collapsing {\color[rgb]{0.3281,0.4961,0.9375}\mathbf{w}} takes {\color[rgb]{0,0,0}\nu}=2+18=20 merges, as given by Eq. 61 . (d) Keeping arcs which enter and leave the same vertex (here, and at ) leaves a walk with no merged bigram (here, {\color[rgb]{0.3281,0.4961,0.9375}abc} ): the kept arcs of a covering set must form a cut.
Figure 5: The binary encoding of Eq. 59 . (a) The pattern {\color[rgb]{0.3281,0.4961,0.9375}1}{\color[rgb]{0.3281,0.4961,0.9375}1} starts each half-word, and the centre (shaded) starts the second one. (b) Between two consecutive centres (dots) lies {\color[rgb]{0.3281,0.4961,0.9375}\langle a\rangle}\circ{\color[rgb]{0.3281,0.4961,0.9375}0}\circ{\color[rgb]{0.3281,0.4961,0.9375}\langle b\rangle} , so a token containing both reveals both symbols ( Lemma 10 ).
Figure 6: Markers {\color[rgb]{0.3281,0.4961,0.9375}1}{\color[rgb]{0.3281,0.4961,0.9375}1} (tinted) start every half-word, at phases and {\color[rgb]{0,0,0}r} , and centres (shaded, with dots) lie at phase {\color[rgb]{0,0,0}r} ; here {\color[rgb]{0,0,0}r}=7 and {\color[rgb]{0,0,0}q}=15 . The gap to the next marker is {\color[rgb]{0,0,0}r} after a phase- marker and {\color[rgb]{0,0,0}r}+1 after a phase- {\color[rgb]{0,0,0}r} one. The first two markers inside {\color[rgb]{0.8633,0.1484,0.4961}s} are {\color[rgb]{0,0,0}r}+1 apart, so the first of them is a centre ( Lemma 10 ).
Figure 7: A merge forest on the encoding of a source string , with codewords drawn schematically as five characters each and centres in black. Shaded triangles abbreviate subtrees which build a whole codeword; they contain no join, as every codeword contains a single centre. The forest has one join (highlighted), which combines two tokens that each contain a centre. The other two roots have only one child containing a centre each; in particular, the middle root spans codeword {\color[rgb]{0.3281,0.4961,0.9375}\widetilde{a_{3}}} together with the first two characters of {\color[rgb]{0.3281,0.4961,0.9375}\widetilde{a_{4}}} , ignoring codeword boundaries. The forest has {\color[rgb]{0,0,0}Z}=3 roots containing a centre and join, as in the first step of the proof of Lemma 11 .
| Length | c_{{\color[rgb]{0,0,0}B}} | c_{{\color[rgb]{0,0,0}W}} | (c_{i})_{i\in{\color[rgb]{0,0,0}{\color[rgb]{0,0,0}\mathcal{V}}_{{\color[rgb]{0,0,0}J}}}} | |
|---|---|---|---|---|
| {\color[rgb]{0,0,0}B} | ||||
| {\color[rgb]{0,0,0}W} | ||||
| \ell^{{\color[rgb]{0,0,0}B}}_{i} | ||||
| \ell^{{\color[rgb]{0,0,0}W}}_{i} |
Table 1: Formal coefficients of the lengths in Reduction 4 .
Tokenisers such as Byte-Pair Encoding (BPE) shorten text by repeatedly merging an adjacent pair of symbols into a new one; fewer tokens mean less computation. We ask whether an efficient algorithm can choose merges that leave a string of length almost as short as possible; doing nothing is already within a factor . We prove that, unless P = NP, no polynomial-time algorithm comes within a factor , for some constant , already for one binary string and for BPE-style merges that replace every occurrence. The key idea is that merges form a grammar with rules: a vertex-cover gap becomes a grammar-size gap, which we amplify with relabelled copies, encode in binary and realise with explicit merges. For merges that may skip occurrences, a simple algorithm achieves , and no Karp reduction can prove hardness beyond order unless coNP NP/poly. Over a one-letter alphabet, both tokenisation problems left open by Kastreva et al. are strongly NP-complete on datasets with repeated strings.
Tokenization: Hardness and Bicriteria Approximation Algorithms
We study Binary Tokenization: given a corpus of binary strings over and a vocabulary budget , select at most substrings (called vocabulary) to minimize the total number of tokens needed to represent the corpus. The primitive symbols and are always available, and each document must be segmented separately. Letting denote the total corpus length and for the maximum document length, we prove that, for every fixed , Binary Tokenization problem does not have polynomial-time -approximation algorithms unless . To complement the hardness result, we give a polynomial-time -bicriteria algorithm, with : The algorithm outputs a vocabulary of size at most with number of tokens at most , where is the optimal number of tokens under the original budget . We also study a storage-budget variant, in which the sum of the selected substrings' lengths is bounded by . For , we obtain an -bicriteria approximation algorithm.
Tokenisation via Convex Relaxations
Tokenisation is an integral part of the current NLP pipeline. Current tokenisation algorithms such as BPE and Unigram are greedy algorithms -- they make locally optimal decisions without considering the resulting vocabulary as a whole. We instead formulate tokeniser construction as a linear program and solve it using convex optimisation tools, yielding a new algorithm we call ConvexTok. We find ConvexTok consistently improves intrinsic tokenisation metrics and the bits-per-byte (BpB) achieved by language models; it also improves downstream task performance, but less consistently. Furthermore, ConvexTok allows the user to certify how far their tokeniser is from optimal, with respect to a certain objective, via a lower bound, and we empirically find it to be within 1% of optimal at common vocabulary sizes.