arXiv:2610.32921cs.CLOct 2026

Manuscript Offprint

arXiv:2610.32921

Adaptive Frequency Threshold Byte Pair Encoding for Mixed Natural Language and Structured Symbolic Corpora

Pietro Di Nicco, Lucio La Cava, Andrea Tagarelli

Abstract

Modern language models rely on subwording tokenization to define the discrete units of input processing, typically using methods like Byte Pair Encoding (BPE) that treat whitespace as a fixed semantic boundary. This design is inherently limited, as many meaningful concepts—including multiword expressions and the structured environments of formal languages like LATEX—frequently span across whitespaces. While recent superword tokenization methods attempt to address this by relaxing whitespace constraints, they often rely on greedy frequency-driven merging that fails to account for token length or the specific needs of underrepresented domain-specific languages. In this paper, we introduce Adaptive Frequency Threshold Byte Pair Encoding (AdaBPE), a new tokenization method that leverages an adaptive frequent-pattern mining approach. AdaBPE features a twofold dynamicity: it adapts minimum frequency thresholds based on both the length of a candidate token, to prevent favoring frequent short patterns, and its type, to distinguish between general and formal language patterns, using LATEX as case in point. This allows the model to efficiently allocate vocabulary capacity to domain-specific notations, such as LATEX, even when they represent a small fraction of the training data. We evaluate AdaBPE across five datasets spanning LATEX and natural language, showing consistent gains in encoding efficiency and downstream language-model performance on domain-specific content without compromising general-language performance.

1 Introduction

In modern language models, the goal of tokenization is to construct a vocabulary of atomic units, called tokens, from a large text corpus. This vocabulary defines the discrete symbols that the model can process as input. The main approach for learning such a vocabulary is subword tokenization. Widely used algorithms, e.g., Byte Pair Encoding (BPE) (Gage, 1994), WordPiece (Schuster and Nakajima, 2012), and Unigram (Kudo, 2018), learn a vocabulary of subword units from the training corpus. These methods typically treat whitespace as a semantic boundary between words, using it to constrain how text is segmented into subword tokens.

This design however has an inherent limitation: whitespace is not, in general, a reliable indicator of semantic boundaries. Many concepts are expressed as multiword expressions, such as “Artificial Intelligence” or “state of the art”, where semantically meaningful units often span multiple whitespace-separated tokens. Ideally, such expressions should be represented as a single lexical unit during tokenization. A similar issue arises in formal languages including programming languages and markup, such as HTML, Markdown, or LATEX. For example, the expression \begin{equation} ... \end{equation} denotes a single mathematical environment, yet conventional subword tokenizers process each command, delimiter, and surrounding text separately.

Related work. Recent studies have revisited the objectives of conventional subword tokenization approaches, highlighting their inherent limitations. Lim et al. (2025) frame subword tokenization as an NP-hard problem, and propose a greedy alternative called GreedTok. Similarly, Asgari et al. (2026) propose MorphBPE to constrain BPE merge operations to respect morphene boundaries, improving morphological consistency. Phan et al. (2024) relate subword tokenization to a bias phenomenon, while (Zhang et al., 2025) investigated negative impacts on the LLM performance on reasoning tasks.

A complementary body of research has focused on vocabulary design. Tao et al. (2024) analyze the compute-optimal vocabulary size growing with the model scale, whereas Lai et al. (2021); Kumar and Thawani (2022); Zhang et al. (2021) explore incorporating larger linguistic units into the vocabulary; however, these approaches are limited to specific tasks (e.g., machine translation) or languages. More recently, a new trend of “superword” tokenization has emerged. Particularly, SuperBPE (Liu et al., 2025) and BoundlessBPE (Schmidt et al., 2025) adopt a variant of BPE that, after initialization like standard BPE, relaxes the pre-tokenization constraint allowing merge candidates that cross whitespace boundaries. The obtained results highlight the benefits of multiword tokens in improving compression, reducing training costs, and accelerating inference.

Motivations of this study. However, two further issues remain largely unaddressed, which are discussed as follows. (I1) Although methods like SuperBPE relaxes the constraint that token merges must respect whitespace boundaries, their vocabulary induction procedure remains based on greedy frequency-driven merging. This greedy merge criterion is based primarily on the frequency of adjacent token pairs rather than directly optimizing the reduction in encoding length. Consequently, it does not explicitly account for the length of candidate tokens or the compression benefit obtained from introducing longer tokens, potentially favoring frequent short patterns over less frequent candidates that could yield larger reductions in sequence length. (I2) The above issue is further exacerbated for domain-specific languages that, in the training data of modern LLMs, is relatively less represented than other sublanguages or formal languages. A particularly relevant example is the representation of mathematical notation through LATEX, which has been shown to improve the reasoning ability of LLMs on mathematical tasks (Taylor et al., 2022), (Lewkowycz et al., 2022), (Ahn et al., 2024). Unlike lightweight markup such as Markdown, LATEX encodes mathematical content through a rich hierarchy of commands and environments which preserves syntactic and semantic structure that is essential for mathematical reasoning, suggesting that LATEX constitutes a more informative training signal for mathematical language modeling than markup languages designed primarily for document formatting. LATEX commands and environments define structured semantic units that are largely independent of whitespace, highlighting the mismatch between whitespace-based tokenization and the underlying semantic structure of the document.

Contributions. In this paper, we aim to address the above issues (I1-I2) by introducing a new tokenization method, named AdaBPE, which leverages an adaptive frequent-pattern mining approach to identify multiword expressions and build an enhanced BPE-based vocabulary. AdaBPE is designed to explicitly distinguish general language patterns from formal language patterns, with emphasis on LATEX, in inducing supertokens. The key feature of AdaBPE is a twofold dynamicity in determining token merges, since it adapts the minimum frequency threshold of a token pattern to both its length (cf. I1) and its type—thus differently treating frequent multiword expressions belonging to either LATEX or general language (cf. I2). Yet, AdaBPE provides a single vocabulary-construction procedure, which allocates capacity differently to general natural language and to domain-specific notation, without requiring separate vocabularies. This leads to an efficient mechanism for capturing domain-specific languages like LATEX even if these languages account for only a small fraction of the training data.

Across five datasets spanning both LATEX and general-language domains, we compared AdaBPE against SuperBPE and BPE along four complementary axes—encoding efficiency, supertoken contribution, token-distribution statistics—showing that AdaBPE achieves consistent compression gains on domain-specific content without degrading performance on general language. Moreover, we trained small-scale language models using AdaBPE and SuperBPE tokenizers, and evaluated these models on five downstream benchmarks to assess the impact of AdaBPE's tokenization strategy on downstream performance.