Skip to main content
QUICK REVIEW

[Paper Review] Toward a Theory of Tokenization in LLMs

Nived Rajaraman, Jiantao Jiao|arXiv (Cornell University)|Apr 12, 2024
Natural Language Processing TechniquesComputer Science3 citations
TL;DR

This paper proposes a theoretical framework to explain why tokenization is essential for transformers to model Markovian language data effectively. By analyzing transformers trained on k-th order Markov processes, the authors show that without tokenization, models collapse to unigram predictions with high cross-entropy loss; with proper tokenization, they achieve near-optimal modeling of sequence probabilities, even though the model's internal behavior remains unigram-like.

ABSTRACT

While there has been a large body of research attempting to circumvent tokenization for language modeling (Clark et al., 2022; Xue et al., 2022), the current consensus is that it is a necessary initial step for designing state-of-the-art performant language models. In this paper, we investigate tokenization from a theoretical point of view by studying the behavior of transformers on simple data generating processes. When trained on data drawn from certain simple $k^{ ext{th}}$-order Markov processes for $k > 1$, transformers exhibit a surprising phenomenon - in the absence of tokenization, they empirically fail to learn the right distribution and predict characters according to a unigram model (Makkuva et al., 2024). With the addition of tokenization, however, we empirically observe that transformers break through this barrier and are able to model the probabilities of sequences drawn from the source near-optimally, achieving small cross-entropy loss. With this observation as starting point, we study the end-to-end cross-entropy loss achieved by transformers with and without tokenization. With the appropriate tokenization, we show that even the simplest unigram models (over tokens) learnt by transformers are able to model the probability of sequences drawn from $k^{ ext{th}}$-order Markov sources near optimally. Our analysis provides a justification for the use of tokenization in practice through studying the behavior of transformers on Markovian data.

Motivation & Objective

  • To understand why tokenization is necessary for state-of-the-art language models despite its complexity.
  • To investigate the end-to-end cross-entropy loss behavior of transformers on Markovian data sources with and without tokenization.
  • To provide a theoretical justification for tokenization by analyzing its impact on model capacity and loss minimization.
  • To demonstrate that even simple unigram models over tokens can achieve near-optimal performance when combined with effective tokenization.

Proposed method

  • The authors study transformers trained on data from k-th order Markov processes, using synthetic data to isolate the effect of tokenization.
  • They compare end-to-end cross-entropy loss between character-level modeling (no tokenization) and tokenized modeling using various standard tokenizers.
  • A toy tokenizer is introduced that includes all length-k sequences as tokens to analytically bound model performance.
  • Theoretical analysis derives asymptotic bounds on token frequency and entropy of the maximum likelihood estimate (MLE) of the unigram model over tokens.
  • The analysis uses almost-sure convergence of token counts and sequence lengths to derive lower bounds on entropy and cross-entropy loss.
  • Monte Carlo sampling and empirical estimation are used to approximate cross-entropy loss for k-gram models, especially for larger k.
((a)) The loss of the transformer fails to converge to the optimal cross-entropy loss (dashed line) and instead converges to that of the best i.i.d. model (dotted line). The shaded blue region captures how the test loss curves vary as hyperparameters (number of layers, embedding dimension etc.) are
((a)) The loss of the transformer fails to converge to the optimal cross-entropy loss (dashed line) and instead converges to that of the best i.i.d. model (dotted line). The shaded blue region captures how the test loss curves vary as hyperparameters (number of layers, embedding dimension etc.) are

Experimental results

Research questions

  • RQ1Why do transformers fail to model k-th order Markov processes without tokenization, even with optimal hyperparameters?
  • RQ2Can tokenization enable transformers to achieve near-optimal cross-entropy loss on Markovian data sources?
  • RQ3What is the theoretical relationship between tokenization strategy and the end-to-end performance of transformers on sequence modeling?
  • RQ4How does the entropy of the learned unigram model over tokens relate to the true entropy of the data-generating process?
  • RQ5To what extent do standard subword tokenizers (e.g., BPE, Unigram) enable transformers to approach the theoretical lower bound of cross-entropy loss?

Key findings

  • In the absence of tokenization, transformers trained on k-th order Markov processes empirically collapse to predicting characters according to the stationary distribution, resulting in high cross-entropy loss.
  • With tokenization, transformers achieve near-optimal cross-entropy loss, even though the model's internal prediction behavior remains unigram-like.
  • The MLE of the unigram model over tokens has entropy bounded away from zero, with a lower bound of at least (1−δ)/2 ⋅ log(4/(1−δ)) for δ ≤ 0.5.
  • The end-to-end loss is bounded below by a constant multiple of the true entropy H(π) of the source process, with the bound depending on the tokenization efficiency.
  • Theoretical analysis confirms that tokenization enables the model to break through the unigram barrier, even when the model’s internal behavior appears unchanged.
  • Empirical results show that standard subword tokenizers (BPE, Unigram, Wordpiece, LZW) all enable near-optimal performance, validating the theory across practical implementations.
((b)) In the presence of tokenization, the test loss of the model approaches the optimal bound (dashed line). It is worth noting that the models trained here are significantly smaller than those considered in Figure 2(a) , having up to $70\times$ fewer parameters and yet are able to achieve the opti
((b)) In the presence of tokenization, the test loss of the model approaches the optimal bound (dashed line). It is worth noting that the models trained here are significantly smaller than those considered in Figure 2(a) , having up to $70\times$ fewer parameters and yet are able to achieve the opti

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.