arXiv:2609.06898cs.CLSep 2026

Manuscript Offprint

arXiv:2609.06898

Dynamic-Programming-Guided Hierarchical BPE and Empirical Analysis of Vocabulary Pruning

Kenny Shao

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Byte Pair Encoding (BPE) constructs vocabularies through greedy pair merging, but the resulting merge order does not necessarily allocate a fixed model-visible vocabulary optimally for compression. We propose Dynamic-Programming-Guided Hierarchical BPE (DH-BPE), a vocabulary-construction method that combines token exposure under exact minimum-token segmentation with the hierarchical dependencies induced by BPE training. Starting from a modestly overshot BPE candidate vocabulary, DH-BPE uses dynamic programming to measure candidate utility and applies exposure-guided, dependency-aware pruning to select a fixed-size model-visible vocabulary. We compare DH-BPE against Standard BPE and recent vocabulary-optimization baselines, including Pruned BPE, MinGram, and MinGram-PP, in primary evaluations at 12K and 16K target vocabulary sizes, with an additional 18K evaluation against MinGram only. Across the primary 12K and 16K comparisons, DH-BPE consistently improves aggregate compression over Standard BPE, Pruned BPE, and MinGram under a shared exact minimum-token DP encoder. MinGram-PP achieves stronger aggregate compression in the primary comparisons, but DH-BPE outperforms it at overshoot factors f=2.0f = 2.0 and f=3.0f = 3.0 in cross-corpus evaluation; at 12K, MinGram-PP reverses this ordering only with the substantially larger candidate pools at f=4.0f = 4.0 and f=5.0f = 5.0. Qualitative analysis further shows that DH-BPE balances later, more complete BPE merges with reusable subword components, providing a practical approach to improving vocabulary allocation under a fixed model-visible vocabulary budget.

1 Introduction

Byte Pair Encoding (BPE) has become one of the most widely used subword tokenization approaches for large language models (LLMs) [1]. Its greedy merge procedure is simple, efficient, and capable of constructing compact vocabularies from raw text, but the vocabulary produced during training is not necessarily optimal for final model-visible use. In our previous work on Pruned BPE [2], we showed that some tokens created during BPE training are useful primarily as intermediate components of later merges while appearing only rarely in the final encoded corpus. Pruned BPE addresses this mismatch through post-training visibility pruning and token reallocation, allowing low-exposure tokens to remain internally available when required by later merges while reallocating visible vocabulary slots to more useful tokens. This naturally raises a further question: can the usefulness of BPE tokens be evaluated more directly when deciding which learned tokens should remain model-visible?

A useful perspective comes from minimum-token segmentation [3, 4]. Given a fixed vocabulary, dynamic programming can determine an exact segmentation of a sequence that minimizes the number of tokens required to represent it. Such a segmentation provides more than an encoding result: it also reveals which vocabulary entries are actually selected when candidate tokens compete under the objective of minimizing encoded length. Tokens that repeatedly appear in these minimum-token segmentations can therefore provide a direct signal of their utility to compression. At the same time, the sequential merge process of standard BPE naturally creates a hierarchical dependency structure among learned tokens. Each merged token is formed from two previously available components and can therefore be recursively traced to lower-level tokens. This structure provides additional information that can be exploited during vocabulary pruning, allowing pruning decisions to account for the dependencies among learned tokens rather than treating them independently.

Motivated by these observations, we propose Dynamic-Programming-Guided Hierarchical BPE (DH-BPE). DH-BPE uses token exposure under exact minimum-token segmentation together with the hierarchical structure created by BPE merges to select the final model-visible vocabulary. Starting from a BPE vocabulary trained beyond the desired final size according to a specified overshoot factor, the method applies minimum-token dynamic programming to the training corpus, measures how frequently candidate tokens are selected in the resulting segmentations, and uses these exposure statistics to guide hierarchical vocabulary pruning. During the pruning process, lower-level tokens required to preserve the BPE dependency structure of retained higher-level candidates are protected from premature removal, even if they are not ultimately selected for the final model-visible vocabulary. After pruning is complete, only the selected model-visible vocabulary is retained for encoding. DH-BPE therefore leaves the standard BPE merge-learning procedure unchanged and instead introduces a post-training mechanism for reducing the learned vocabulary to a fixed target size.

The contributions of this work are threefold. First, we introduce DH-BPE, a vocabulary-pruning framework that combines exposure measured under exact minimum-token segmentation with dependency-aware pruning of a BPE-derived vocabulary. Second, we systematically investigate important design choices of the proposed method, including two-space token protection, the BPE vocabulary overshoot factor, and the pruning ratio, and evaluate how these choices affect tokenizer compression. Third, we conduct controlled same-corpus and cross-corpus evaluations together with qualitative analysis of retained vocabulary entries, providing insight into how DH-BPE distributes limited vocabulary capacity between longer corpus-specific tokens and shorter reusable components and how these choices affect generalization across corpora.

References (21)