---
title: Tokenization with Split Trees (ToaST)
url: https://www.emergentmind.com/topics/tokenization-with-split-trees-toast
type: topic
---

# Tokenization with Split Trees (ToaST)

Tokenization with Split Trees (ToaST) is a subword tokenization method that combines a vocabulary-agnostic binary decomposition of each pretoken with a deterministic recursive inference rule and a global vocabulary-selection objective. Introduced in "Tokenization with Split Trees" [2605.22705], it builds a full binary split tree for every pretoken from byte \(n\)-gram counts, then tokenizes by recursively descending each tree and emitting the first in-vocabulary node reached on each path. Vocabulary learning is posed as an Integer Program that minimizes total corpus token count under this inference procedure. In the reported English-language experiments, ToaST reduces token counts by more than \(11\%\) relative to BPE, WordPiece, and UnigramLM at vocabulary sizes \(40{,}960\) and above, substantially reduces the use of common single-byte tokens, and yields the highest CORE score in \(1.5\)B-parameter language-model experiments [2605.22705].

## 1. Methodological position and core abstraction

ToaST was proposed as an alternative to two established design patterns in subword tokenization. BPE and WordPiece are bottom-up and merge-based, while UnigramLM is top-down, begins with a large vocabulary, and prunes by likelihood-based scoring. ToaST instead separates three components: tree construction, inference, and vocabulary optimization. The split trees are constructed first, using only byte \(n\)-gram frequency counts and no knowledge of the eventual vocabulary; inference is then defined for any vocabulary \(V \subseteq T\) that contains all valid single-byte UTF-8 tokens; and vocabulary learning is finally cast as an explicit optimization problem over that fixed candidate set [2605.22705].

The central object is the per-pretoken full binary split tree. A pretoken is the byte substring produced by regex-based pretokenization, and each pretoken type is weighted by its aggregate corpus count. Every node in a tree corresponds to a byte substring, leaves correspond to bytes, and internal nodes correspond to recursively chosen binary splits. The global candidate-token set is
\[
T=\left(\bigcup_{j\in J,\;k\in K_j} t_{jk}\right)\cup B,
\]
where \(B\) is the set of \(243\) single-byte tokens that must always remain available [2605.22705].

This decomposition yields several structural consequences. Tree construction is vocabulary-independent, so the candidate token set does not depend on which tokens are later selected. Any vocabulary containing the \(243\) valid single-byte UTF-8 tokens is valid, so no merge-rule list is required. Removing a token from the vocabulary does not trigger global resegmentation; it only forces recursive descent below that node. The paper presents this as a key distinction from merge-based inference and shortest-path-like segmentation schemes [2605.22705].

## 2. Split-tree construction from byte \(n\)-gram statistics

The reported implementation begins by pretokenizing a \(175\)GB English corpus from CulturaX with a length-limited variant of the GPT-4o regex. Pretokens are aggregated with counts, and the top \(700{,}000\) pretokens cover \(99.01\%\) of all pretoken occurrences. Each selected pretoken is then converted into a full binary split tree [2605.22705].

Tree construction depends on corpus-wide byte \(n\)-gram counts computed within pretoken boundaries. Only \(n\)-grams with count at least \(c_{\min}=250\) are stored. Under this threshold, the reported system contains \(5{,}991{,}872\) unique \(n\)-grams, stored as a `dict[bytes, int]` requiring about \(708\)MB. These counts are the only statistics used to define the tree structure [2605.22705].

For a pretoken \(s\), every split point \(i\) with \(1 \le i < |s|\) defines a left substring \(s[:i]\) and right substring \(s[i:]\). Let their stored counts be \(c_p\) and \(c_{p'}\); if absent from the dictionary, a default low value such as \(-10\) is used. The split score is
\[
\mathrm{score}(i)=\min(c_p,c_{p'}).
\]
The chosen split is the one maximizing \(\min(c_p,c_{p'})\), with ties broken by the leftmost split. If no split has both sides present in the count dictionary, the implementation falls back to splitting at the longest prefix that is in the dictionary. Recursing until single bytes produces a full binary tree [2605.22705].

The paper’s worked example is the pretoken “␣Kentucky”. Among candidate splits, the best root split is “␣Kent”\(|\)“ucky”, whose \(\min(c_p,c_{p'})\) value is \(15{,}944\). Recursive application of the same rule generates internal nodes such as “␣Kent”, “Kent”, and “ent”, with byte leaves at the bottom of the tree [2605.22705].

Although the main experiments operate at the byte level, the construction is explicitly modular. The appendix proposes a split-preference hierarchy of superwords, morphemes, characters, and bytes, with the same \(\max \min(c_p,c_{p'})\) scoring applied inside the highest available level. In the reported experiments, only the multi-byte-character constraint is enforced: splits never occur inside a multi-byte Unicode character [2605.22705].

## 3. Recursive inference and segmentation semantics

Given a fixed split tree and a vocabulary \(V\), ToaST tokenization is defined by recursive descent. If the current substring is in the vocabulary, or if its length is \(1\), tokenization emits that substring and stops descending on that branch. Otherwise the algorithm follows the precomputed split and recurses on the left and right children. In code form, the core logic is
```python
def tokenize(s: bytes, vocab: set[bytes]):
    if len(s) == 0:
        return []

    if len(s) == 1 or s in vocab:
        return [s]

    best_i = best_split(s)
    return tokenize(s[:best_i], vocab) + \
           tokenize(s[best_i:], vocab)
```
where `best_split(s)` is fixed by the training-time tree construction [2605.22705].

Operationally, the inference rule can be described as follows: for each root-to-leaf path, emit the highest node on that path whose string is in the vocabulary. Because each byte position lies on a unique path and each leaf byte is guaranteed to be in the vocabulary, every path emits exactly one token. The resulting tokenization is therefore unique and deterministic [2605.22705].

This semantics induces a precise coverage property. Let \(L_j\) be the leaves of split tree \(j\), and let \(A_{jk}\) be the ancestors of leaf \(k \in L_j\). Then exactly one node on each root-to-leaf path must be selected:
\[
z_{jk}+\sum_{k'\in A_{jk}} z_{jk'} = 1
\qquad \forall j\in J,\; k\in L_j.
\]
This equality is both the combinatorial meaning of inference and one of the optimization constraints used during vocabulary learning [2605.22705].

Several consequences follow immediately. Because trees are independent of the vocabulary, ToaST does not require merge rules. Because tokenization always stops at the first in-vocabulary node on a path, removing a vocabulary item forces refinement only below that node. The paper characterizes this as the absence of global cascading effects. A common misconception is therefore to treat ToaST as a BPE variant with a different merge criterion; in fact, its inference model is tree-based and path-local rather than merge-sequence-based [2605.22705].

The empirical analysis also classifies output tokens by role: **Root**, **Unavoidable Leaf**, **Leaf**, and **Non-Leaf Subword**. This typology is later used to compare ToaST with BPE, WordPiece, and UnigramLM, especially in the treatment of single-byte leaf tokens [2605.22705].

## 4. Vocabulary selection as an Integer Program

Vocabulary learning in ToaST is formulated as an Integer Program over global vocabulary variables and per-tree usage variables. Let \(x_i \in \{0,1\}\) indicate whether candidate token \(i\) is selected, and \(z_{jk} \in \{0,1\}\) indicate whether node \(k\) in tree \(j\) is used in tokenization. If \(c_j\) is the aggregate count of pretoken \(j\), the objective is
\[
\min \sum_{j\in J} c_j \sum_{k\in K_j} z_{jk},
\]
which is exactly the total token count over the corpus under split-tree inference [2605.22705].

The optimization is subject to four main constraints. First, the vocabulary has prescribed size:
\[
\sum_{i\in I} x_i = m.
\]
Second, all valid UTF-8 single bytes are mandatory:
\[
x_i = 1 \qquad \forall i\in I_B.
\]
Third, each root-to-leaf path must be covered exactly once:
\[
z_{jk}+\sum_{k'\in A_{jk}} z_{jk'} = 1
\qquad \forall j\in J,\; k\in L_j.
\]
Fourth, a node can be used only if its string is in the vocabulary:
\[
z_{jk}\le x_{i_{jk}}
\qquad \forall j\in J,\; k\in K_j.
\]
Together with binary constraints on \(x_i\) and \(z_{jk}\), these equations define the training problem [2605.22705].

The LP relaxation replaces integrality by
\[
0\le x_i \le 1, \qquad 0\le z_{jk}\le 1.
\]
Empirically, this relaxation is exceptionally tight. Across \(128\) instances obtained from \(400\)k, \(500\)k, \(600\)k, and \(700\)k split trees and \(32\) vocabulary sizes from \(8{,}192\) to \(262{,}144\), the worst case has only \(66\) fractional \(x_i\) variables and \(285\) fractional \(z_{jk}\) variables, i.e. less than \(0.012\%\) and less than \(0.004\%\) respectively. The maximum absolute gap between the integer-rounded solution \(\hat f\) and the LP optimum \(f^*_{\mathrm{LP}}\) is \(21{,}500\) tokens out of \(37\) billion tokens,
\[
\frac{\hat f-f^*_{\mathrm{LP}}}{\hat f} \le 5.76\times 10^{-7},
\]
and in \(44\) of \(128\) cases the LP solution is entirely integral [2605.22705].

The paper presents this near-integrality as an empirical finding rather than a proved theorem. It conjectures that the tree structure is responsible, because higher nodes dominate lower nodes in token-count reduction along a path. This suggests that the LP’s tightness is structural, but a general integrality characterization is not stated [2605.22705].

A simple rounding heuristic is used for the remaining fractional cases. With a tolerance \(\varepsilon=10^{-5}\), variables with \(x_i^* \ge 1-\varepsilon\) are fixed to \(1\), those with \(x_i^* \le \varepsilon\) are fixed to \(0\), and the remaining budget is allocated to the fractional tokens with largest
\[
C_i^*=\sum_{\substack{j\in J,\;k\in K_j:\\ i_{jk}=i}} c_j z_{jk}^*.
\]
The resulting binary vocabulary is then re-evaluated by re-running split-tree inference [2605.22705].

Model size is linear in total byte length. Each full binary tree satisfies \(|K_j|=2|L_j|-1\), so the LP has \(|I|\) global \(x\)-variables, \(\sum_j (2|L_j|-1)\) \(z\)-variables, and \(1+\sum_j (3|L_j|-1)\) constraints. Empirically, total build-plus-solve time scales quadratically in the number of split trees over the range \(400\)k–\(700\)k. With HiGHS dual simplex on an AWS `r7i.48xlarge`, solving the largest vocabulary size \(m=262{,}144\) takes \(12\)–\(23\) hours depending on the number of trees; subsequent warm-started re-solves for smaller \(m\) take less than one hour each [2605.22705].

## 5. Empirical behavior: compression, token usage, and language modeling

Compression is evaluated on a \(37.5\)GB English validation set from CulturaX using bytes per token, equivalently corpus byte length divided by total token count. Under this metric, ToaST improves compression by \(7.5\%\) over the best baseline at vocabulary size \(8{,}192\), by \(10.5\%\) at \(24{,}576\), and by more than \(11\%\) over BPE, WordPiece, and UnigramLM at vocabulary sizes \(40{,}960\) and larger. The paper also reports a theoretical upper bound induced by the fixed pretokenization: if each pretoken were represented by a single token, validation compression would be \(5.01\) bytes per token. ToaST approaches this bound more closely than the baselines [2605.22705].

The token-category analysis highlights the reduction of single-byte usage. At vocabulary size \(65{,}536\), ToaST uses \(14\)–\(19\times\) fewer **Leaf** tokens than all baselines and correspondingly uses substantially more **Root** tokens. The reported interpretation is that ToaST does not need to preserve as many intermediate subwords as “stepping stones” toward frequent words; since the objective directly minimizes token count under the tree inference rule, allocating vocabulary mass to whole pretokens is often preferable [2605.22705].

The paper further evaluates Rényi efficiency with \(\alpha=2.5\), following prior work cited there. Because ToaST dramatically reduces high-frequency leaf tokens, it achieves substantially higher Rényi efficiency than BPE, WordPiece, and UnigramLM; Shannon efficiency is also higher. In a Zipf analysis at vocabulary size \(128\)k, ToaST has fewer very high-frequency tokens and fewer extremely rare tokens. The minimum token count on validation is \(103\) for ToaST, compared with \(4\) for UnigramLM and \(1\) for BPE and WordPiece. Only \(6\) ToaST tokens are unused over the \(37.5\)GB validation set, versus \(24\)–\(92\) unused tokens for the baselines; the unused ToaST tokens are rare single bytes included for completeness [2605.22705].

Inference speed is reported at about \(600\)k tokens/s in Python on a MacBook Pro. For comparison, BPE in the Hugging Face Rust implementation achieves about \(1\)M tokens/s, so ToaST is about \(1.6\times\) slower in that comparison. The paper notes that performance benefits from the frequent case in which the pretoken root itself is in the vocabulary, eliminating recursion [2605.22705].

Downstream evaluation uses four \(1.56\)B-parameter nanochat depth-24 language models that differ only in tokenizer and are pretrained on ClimbMix-400B with a matched budget of \(5.9\)B tokens. Because ToaST uses about \(11\%\) fewer tokens to represent text, its model sees roughly \(11\%\) more raw text under the same token budget. On CORE, the reported base-model means are \(0.2632 \pm 0.0076\) for ToaST, \(0.2446 \pm 0.0055\) for BPE, \(0.2500 \pm 0.0044\) for Unigram, and \(0.2566 \pm 0.0079\) for WordPiece. Relative to each baseline, ToaST is \(+7.6\%\) versus BPE, \(+5.3\%\) versus Unigram, and \(+2.6\%\) versus WordPiece; Welch’s \(t\)-tests over four seeds give \(p=0.009\) for ToaST versus BPE and \(p=0.032\) for ToaST versus Unigram, while the difference versus WordPiece is not significant. ToaST has the highest mean on \(13\) of the \(22\) CORE base tasks [2605.22705].

The supervised fine-tuning results are more mixed. The paper reports that ToaST’s SFT CORE is slightly below Unigram but similar to BPE and WordPiece, and attributes part of this outcome to the experimental protocol: SFT is not token-matched, so a more compressive tokenizer receives fewer gradient steps on SFT data. This frames one of the paper’s main trade-offs: under a fixed token budget, ToaST benefits in pretraining exposure but may be disadvantaged in later phases that are not normalized by tokens [2605.22705].

## 6. Relation to split-tree theory, conceptual background, and limitations

The term *split tree* predates ToaST and has an established meaning in probabilistic combinatorics. In that literature, split trees are random trees of logarithmic height introduced by Devroye in \(1998\), generated by a trickle-down process of balls through buckets on an infinite \(b\)-ary skeleton. They include binary search trees, \(m\)-ary search trees, quad trees, and related structures. In "Embedding small digraphs and permutations in binary trees and split trees" [1901.02328], split trees are used to study permutation occurrences, generalized path-length parameters, and embeddings of fixed DAGs, while "Fringe subtrees of split trees and fractional split trees" [2603.21780] studies additive functionals such as numbers of nodes, leaves, and fringe trees. ToaST uses the same phrase for a different object: a deterministic full binary decomposition of a pretoken obtained from byte \(n\)-gram counts [2605.22705].

This suggests a structural rather than model-identical relationship. The older split-tree literature supplies a vocabulary for local tree patterns, fringe subtrees, additive counts, and logarithmic-depth recursions [1901.02328; 2603.21780]. A plausible implication is that these concepts are useful for formalizing statistics of tree-based tokenizers, but the ToaST paper’s optimization framework, recursive “first in-vocabulary” inference rule, and LP near-integrality are specific to the tokenizer construction rather than inherited from the random-tree results [2605.22705].

The current ToaST formulation has several stated limitations. All reported experiments are English-only. Training uses only the top \(K\) most frequent pretokens, such as \(700\)k pretokens in the main experiments, and the coverage behavior of this truncation may differ in languages with more uniform distributions or larger character sets. Training requires solving large LPs or near-MIPs with millions of variables and constraints, which is substantially heavier than BPE training. The paper also notes that although the LP relaxation is exceptionally tight in practice, this is an empirical observation rather than a proved general property [2605.22705].

Future extensions are framed mainly through tree construction and weighting. The appendix proposes richer split hierarchies involving superwords, morphemes, characters, and bytes. Multilingual tokenization can be incorporated by rescaling the linear objective weights \(c_j\) so that different languages contribute differently to vocabulary selection. More generally, any vocabulary-independent binary splitting rule could replace the current \(\max \min(c_p,c_{p'})\) heuristic without changing the downstream IP/LP formulation [2605.22705].

Within the tokenization literature, ToaST therefore occupies a distinct design point: fixed vocabulary-agnostic trees, deterministic path-local inference, and explicit global minimization of token count over that structure. Its empirical claims are strongest on compression and token-usage balance, while its theoretical distinctiveness lies in recasting vocabulary learning as a nearly integral linear optimization problem over a tree-constrained segmentation space [2605.22705].

Source: https://www.emergentmind.com/topics/tokenization-with-split-trees-toast