Byte BPE Tokenization as an Inverse string Homomorphism
Saibo Geng, Sankalp Gambhir, Chris Wendler, Robert West
TL;DR
This work formalizes tokenization as an inverse-homomorphism from the character space to the token-ID space, with detokenization acting as a homomorphism back to the character space. It shows that, for context-free and regular languages, extended tokenization preserves the original language structure, and that Unicode can be accommodated via byte-level tokenization without breaking this property. The authors construct a PDA-based framework to recognize token languages and introduce the notions of proper versus extended tokenization, highlighting how the latter suffices for neural model expressiveness while addressing practical issues like BPE and leading-space effects. Overall, the paper provides a rigorous, language-theoretic lens on tokenization, offering insights for tokenizer design and the interpretability of LLMs with respect to formal-language processing.
Abstract
Tokenization is an important preprocessing step in the training and inference of large language models (LLMs). While there has been extensive research on the expressive power of the neural achitectures used in LLMs, the impact of tokenization has not been well understood. In this work, we demonstrate that tokenization, irrespective of the algorithm used, acts as an inverse homomorphism between strings and tokens. This suggests that the character space of the source language and the token space of the tokenized language are homomorphic, preserving the structural properties of the source language. Additionally, we explore the concept of proper tokenization, which refers to an unambiguous tokenization returned from the tokenizer. Our analysis reveals that the expressiveness of neural architectures in recognizing context-free languages is not affected by tokenization.
