Tokenization as Finite-State Transduction

Marco Cognetta, Naoaki Okazaki
10/21/2024
cs.CLcs.FL

No official code found. Best implementation: mcognetta/tokenization-as-finite-state-transduction (6 stars, MIT, last commit 2025-09-14).

Abstract

Tokenization is the first step in modern neural language model pipelines where an input text is converted to a sequence of subword tokens. We introduce from first principles a finite-state transduction framework which can efficiently encode all possible tokenizations of a regular language. We then constructively show that Byte-Pair Encoding (BPE) and MaxMatch (WordPiece), two popular tokenization schemes, fit within this framework. For BPE, this is particularly surprising given its resemblance to context-free grammar and the fact that it does not tokenize strings from left to right. An application of this is to guided generation, where the outputs of a language model are constrained to match some pattern. Here, patterns are encoded at the character level, which creates a mismatch between the constraints and the model's subword vocabulary. While past work has focused only on constraining outputs without regard to the underlying tokenization algorithm, our framework allows for simultaneously constraining the model outputs to match a specified pattern while also adhering to the underlying tokenizer's canonical tokenization.

View on arXivView PDF

Code Implementations(1)

MIT

The reference implementation for Tokenization as Finite-State Transduction, which will appear in Computational Linguistics.

60PythonAug 19, 20251 years agoMIT

Cite this paper

@article{cognetta2024tokenization,
  title  = {Tokenization as Finite-State Transduction},
  author = {Marco Cognetta and Naoaki Okazaki},
  year   = {2024},
  eprint = {2410.15696},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2410.15696v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2410.15696.svg)](https://codeofpaper.com/paper/2410.15696)

Discussion