[论文解读] Toward a Theory of Tokenization in LLMs
本文提出一个理论框架,用以解释为何分词对Transformer模型有效建模马尔可夫语言数据至关重要。通过分析在k阶马尔可夫过程中训练的Transformer模型,作者表明:若无分词,模型会退化为单频预测,导致交叉熵损失极高;而通过适当的分词,即使模型内部行为仍保持单频特性,其对序列概率的建模也能接近最优。
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.
研究动机与目标
- 理解为何尽管分词过程复杂,它对最先进语言模型仍是必要的。
- 研究在有无分词的情况下,Transformer模型在马尔可夫语言数据源上的端到端交叉熵损失行为。
- 通过分析分词对模型容量和损失最小化的影响,为分词提供理论依据。
- 证明即使使用简单的基于分词的单频模型,只要分词策略有效,也能实现近乎最优的性能。
提出的方法
- 作者研究在k阶马尔可夫过程生成的数据上训练的Transformer模型,使用合成数据以隔离分词的影响。
- 比较字符级建模(无分词)与使用各种标准分词器的分词建模之间的端到端交叉熵损失。
- 引入一个简化分词器,将所有长度为k的序列作为分词,以解析地界定模型性能。
- 理论分析推导出在分词上单频模型的最大似然估计(MLE)的分词频率和熵的渐近界。
- 利用分词计数和序列长度的几乎必然收敛性,推导出熵和交叉熵损失的下界。
- 使用蒙特卡洛采样和经验估计方法,近似计算k-gram模型的交叉熵损失,特别是针对较大的k值。

实验结果
研究问题
- RQ1为何在最优超参数下,Transformer模型在无分词时仍无法有效建模k阶马尔可夫过程?
- RQ2分词是否能使Transformer在马尔可夫语言数据源上实现近乎最优的交叉熵损失?
- RQ3分词策略与Transformer在序列建模中端到端性能之间的理论关系是什么?
- RQ4学习到的分词上单频模型的熵与数据生成过程的真实熵之间有何关系?
- RQ5标准子词分词器(如BPE、Unigram)在多大程度上能使Transformer接近交叉熵损失的理论下界?
主要发现
- 在无分词的情况下,训练于k阶马尔可夫过程的Transformer模型在经验上会退化为根据平稳分布预测字符,导致交叉熵损失极高。
- 通过分词,即使模型内部预测行为仍保持单频特性,Transformer也能实现近乎最优的交叉熵损失。
- 在分词上单频模型的MLE其熵被严格下界约束,下界至少为(1−δ)/2 ⋅ log(4/(1−δ)),其中δ ≤ 0.5。
- 端到端损失被下界约束为真实源过程熵H(π)的常数倍,该下界取决于分词效率。
- 理论分析证实,即使模型内部行为未变,分词仍能使模型突破单频限制。
- 实证结果表明,标准子词分词器(BPE、Unigram、Wordpiece、LZW)均能实现近乎最优性能,验证了理论在实际实现中的普适性。

阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。