Should you marginalize over possible tokenizations?

Nadezhda Chirkova, Germán Kruszewski, Jos Rozen, Marc Dymetman

Introduction: The Hidden Ambiguity of Tokenization

Autoregressive language models (LMs) do not process raw text; they operate on sequences of discrete tokens. For any given string, there are often multiple valid ways to segment it into tokens. For example, the word "cab" could be represented as [c, a, b], [ca, b], or a single token [cab].

Mathematically, the true probability of a string $S$ should be the sum of the probabilities of all possible token sequences $T$ that concatenate to $S$: $$P(S) = \sum_{T \in \text{tokens}(S)} P(T)$$ This process is known as marginalization. However, because the number of possible tokenizations grows exponentially with string length, standard practice in the AI community is to ignore this sum and simply calculate the probability of a single "default" tokenization provided by a heuristic tokenizer (like BPE). This paper investigates whether this "default-only" shortcut is a harmless approximation or a significant source of error that causes us to underestimate model performance.

Methodology: Importance Sampling for Marginalization

To calculate the marginalized probability without exhaustive summation, the authors developed a novel importance-sampling-based algorithm. The core challenge is that most tokenizations have near-zero probability, so random sampling is inefficient.

The proposed method uses the language model itself to create a proposal distribution ($Q$). To keep the computation tractable, the string is first divided into smaller "blocks" (typically at whitespace boundaries). For each block, the algorithm identifies all possible tokenizations and uses the LM to assign weights.

Overview of the importance-sampling algorithm. The model proposes multiple tokenizations for a block (e.g., 'Palestro'), scores them using the LM, and samples to estimate the marginalized probability.

By sampling $K$ tokenizations from this distribution, the researchers can estimate the total marginalized probability. This allows them to measure the BPC gap (Bits Per Character gap)—the difference between the "true" marginalized log-likelihood and the standard "default" log-likelihood.

Empirical Analysis across Domains and Languages

The researchers evaluated two prominent models—GPT-2 (126M) and BLOOM (1.7B)—across a wide array of datasets, including standard English (Wikipedia, News), informal text (Twitter), code (Python, C++), and various languages from the Flores-200 benchmark.

Key Findings

  1. The Default is Usually Sufficient: For high-resource, standard English text, the "default" tokenization typically captures the vast majority of the probability mass. In these cases, the relative gap in log-likelihood is often less than 0.5%.
  2. Complexity and Out-of-Distribution Data: The gap widens significantly when the model encounters "unfamiliar" territory. On informal Twitter data, the gap increases to 1.3%–1.5%. Transcribed speech data saw gaps as high as 2%.
  3. Low-Resource Languages: Languages like Basque (Eus) showed a gap of 1.31%, suggesting that models are more "uncertain" about how to segment text in languages where they have seen less training data.
BPC gaps across different models and datasets. The gap between the marginalized probability and the default tokenization probability is more pronounced in informal text (Twitter) and low-resource languages (Basque).

Discussion and Implications

The results suggest that modern sub-word tokenizers are remarkably robust for general-purpose English. The fact that the gap is usually minimal confirms that the "default" sequence is a strong proxy for the entire distribution.

However, the widening gap in "hard" cases—complex words, technical jargon, and low-resource languages—indicates that our current evaluation metrics might be slightly penalizing models in these domains. When a model is "confused" by tokenization, it spreads its probability mass across multiple valid paths; by only looking at one path, we miss the full extent of the model's predictive power.

Limitations

While this importance-sampling approach provides a valuable analysis tool, it is not yet a practical replacement for standard inference. The method requires multiple passes through the LM per sequence, making it significantly more computationally expensive than the standard one-pass approach. Furthermore, the block-based sequential processing is more difficult to parallelize than standard teacher-forcing.

Conclusion

Should you marginalize over possible tokenizations? For most standard applications, the answer is no; the default tokenization is a safe and efficient shortcut. However, for researchers working on low-resource languages or highly specialized domains, marginalization offers a way to "stress-test" tokenizers and obtain a more accurate measure of a model's true understanding of text.

Summary updated

BibTeX
@inproceedings{chirkova2023should,
  author = {Nadezhda Chirkova and Germán Kruszewski and Jos Rozen and Marc Dymetman},
  title = {{Should you marginalize over possible tokenizations?}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.acl-short.1},
}
Figure