Manuscript Offprint

arXiv:2610.01127

Counting and Min-Cost Encoding for Tokenization in Large Language Models

Shuming Shi, Xiang Zhang, Hao Yu, Wenbo Fei, Changjian Wang, Zhan Wang, Guoqing Pang, Guangye Yu, Quan Lu, Ning Jiang

Abstract

Mainstream large language models (LLMs) rely on a tokenizer to encode text into a token sequence. Different tokenizers may yield token sequences of substantially different lengths for the same text. With a fixed model architecture, shorter token sequences correspond to lower inference time. We propose a tokenizer training approach named Counting and Filtering (CNF) and a text encoding algorithm called Min-Cost Encoding (MCE). MCE defines a cost function over a text segment, and determines the best segmentation by globally minimizing the overall segmentation cost. CNF builds a raw vocabulary by directly counting valid substrings, and then constructs the final vocabulary through a filtering step based on actual token usage when segmenting the training corpus with MCE. The CNF-MCE combination offers several advantages over BPE (the most widely used tokenizer algorithm for LLMs so far), including higher token efficiency, greater scalability, and lower dependency. Across six text categories and two vocabulary-size groups, CNF-MCE consistently achieves better compression than the evaluated BPE tokenizers. With a 250K vocabulary, CNF-MCE increases compression rate by 26% and 30% on English web text over the o200k_base and qwen250k tokenizers. Experiments scaling the vocabulary to 1M entries on English web text demonstrate sustained improvements over BPE, with a token efficiency improvement of over 60% and vocabulary utilization rising from 52.9% to 96.9%. The MCE algorithm does not depend on a merge list (as in BPE) or token probability (as in UnigramLM), making it applicable to a wide range of vocabularies, including those built from BPE, UnigramLM, CNF, and others. Language models trained from scratch at the 1.8B and 8B scales achieve comparable average performance to models using the BPE tokenizers across 11 benchmarks. These results demonstrate that CNF-MCE can improve token efficiency significantly while maintaining competitive downstream performance.

1 Introduction

Transformer-based large language models (LLMs) cannot process raw text directly. They rely on a tokenizer to convert input text to a sequence of tokens, a process referred to as text encoding, tokenization, or segmentation. Similarly, the output token IDs produced by LLMs are converted back into text through a decoding process. A tokenizer is primarily defined by a vocabulary, an encoding algorithm, and a decoding algorithm. The choice of tokenizers directly affects both the efficiency and performance of LLMs. For the same text, different tokenizers may produce token sequences of substantially different lengths. With a fixed model architecture, shorter token sequences correspond to lower inference time. Token efficiency is commonly quantified by the compression rate, expressed as the average amount of raw text (e.g., UTF-8 bytes) encoded per token; a higher rate therefore indicates a shorter token sequence (Meister, 2026; Liu et al., 2025a). An important objective in tokenizer design is therefore to improve compression rate under a fixed vocabulary budget while preserving or improving downstream model performance.

Widely used tokenizer training methods face structural limitations in optimizing compression under a fixed vocabulary budget. Byte Pair Encoding (BPE) constructs its vocabulary through a sequence of order-dependent merges (Sennrich et al., 2016). Forming a long token requires introducing intermediate merge products, some of which may remain underutilized while continuing to consume vocabulary capacity (Chizhov et al., 2024). Hard pretokenization boundaries further prevent tokens from spanning multiple pretokens. Recent methods such as SuperBPE (Liu et al., 2025a) relax this boundary constraint but retain sequential merge-based construction. UnigramLM avoids merge ancestry, but it requires probability estimation over a segmentation lattice and iterative likelihood-based pruning (Kudo, 2018; Land, 2026). These approaches therefore tie vocabulary construction to either sequential merge operations or iterative refinement. This raises a natural question: can we significantly improve token efficiency under a fixed vocabulary budget without relying on merges or repeated vocabulary refinement?

To address this question, we propose a tokenizer training approach named Counting and Filtering (CNF) and a text encoding algorithm called Min-Cost Encoding (MCE). In MCE, a cost function is defined for a segment in a piece of text, and the best segmentation is determined by globally minimizing the overall segmentation cost. Our cost function does not rely on merge information (as in BPE) or token probability estimation (as in UnigramLM), making MCE applicable to a wide range of vocabularies. CNF consists of two phases. In the counting phase, a raw vocabulary is built by calculating the occurrences of valid substring candidates in the training corpus and selecting the m most frequent ones. In the filtering phase, the training corpus is first segmented by MCE based on the raw vocabulary. Then the segmentation frequency of each token is calculated and the final vocabulary is constructed by filtering out from the raw vocabulary the tokens with low segmentation frequencies. Note that CNF encodes the training corpus only once, which makes the filtering step very efficient. This non-iterative CNF procedure shifts vocabulary selection from raw occurrence frequency to realized usage under MCE, yielding a vocabulary aligned with actual token usage.

We evaluate our method using intrinsic tokenizer metrics across multiple text domains and vocabulary sizes, as well as downstream task performance. Our method achieves consistently better compression than the evaluated BPE tokenizers. Particularly, the MCE encoding algorithm on our mix250k vocabulary achieves 26.7% and 32.4% higher token efficiency than the o200k_base and qwen250k tokenizers respectively. Experiments scaling the vocabulary to 1M entries on English web text demonstrate sustained improvements over BPE, with a token efficiency improvement of over 60% and vocabulary utilization rising from 52.9% to 96.9%. Language models trained with our tokenizers at the 1.8B and 8B scales achieve comparable average downstream performance across 11 English benchmarks to models trained with the BPE tokenizers.

Our main contributions are as follows:

  • We introduce CNF, a merge-free vocabulary construction method that builds a raw vocabulary by counting valid substring occurrences and selects the final vocabulary through a single filtering step based on realized token usage under MCE.

  • We propose MCE, a segmentation algorithm that globally minimizes an encoding cost that combines token count with penalties for partial-word boundary crossings. MCE can be applied to a wide range of vocabularies, including those built from BPE, UnigramLM, CNF, and other methods.

  • We demonstrate improved compression and a range of intrinsic tokenizer properties, sustained compression gains with high vocabulary utilization as vocabulary size increases, and comparable average downstream performance to the evaluated baselines.

References (45)