Formalizing BPE Tokenization

Martin Berglund
(UmeƄ University)
Brink van der Merwe
(Stellenbosch University)

In this paper, we formalize practical byte pair encoding tokenization as it is used in large language models and other NLP systems, in particular we formally define and investigate the semantics of the SentencePiece and HuggingFace tokenizers, in particular how they relate to each other, depending on how the tokenization rules are constructed. Beyond this we consider how tokenization can be performed in an incremental fashion, as well as doing it left-to-right using an amount of memory constant in the length of the string, enabling e.g. using a finite state string-to-string transducer.

In Benedek Nagy and Rudolf Freund: Proceedings of the 13th International Workshop on Non-Classical Models of Automata and Applications (NCMA 2023), Famagusta, North Cyprus, 18th-19th September, 2023, Electronic Proceedings in Theoretical Computer Science 388, pp. 16–27.
Published: 15th September 2023.

ArXived at: https://dx.doi.org/10.4204/EPTCS.388.4 bibtex PDF
References in reconstructed bibtex, XML and HTML format (approximated).
Comments and questions to: eptcs@eptcs.org
For website issues: webmaster@eptcs.org