From Where Words Come: Efficient Regularization of Code Tokenizers Through Source Attribution

📄 arXiv: 2604.14053v1 📥 PDF

作者: Pavel Chizhov, Egor Bogomolov, Ivan P. Yamshchikov

分类: cs.CL

发布日期: 2026-04-15


💡 一句话要点

提出SA-BPE,通过源属性正则化代码Tokenizer,减少低训练token。

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 代码Tokenization BPE算法 源属性正则化 低资源Token 大型语言模型 代码生成 模型泛化

📋 核心要点

  1. 代码Tokenizer易受训练数据源不平衡的影响,导致产生大量未充分训练的token。
  2. 提出Source-Attributed BPE (SA-BPE),通过源属性正则化BPE训练,减少过拟合。
  3. SA-BPE通过修改BPE目标和引入merge skipping,有效减少了低训练token的数量。

📝 摘要(中文)

大型语言模型(LLM)的效率和安全性在很大程度上取决于tokenization的质量。一个好的tokenizer不仅能提高推理速度和语言理解能力,还能提供额外的防御,防止jailbreak攻击,并降低幻觉风险。本文研究了代码tokenization的效率,特别是从数据源多样性的角度。我们证明,由于训练数据中存储库和语言多样性的不平衡,以及源特定的、重复的token的支配地位,代码tokenizer容易产生未使用的、因此训练不足的token,这些token在未来的推理中通常是不可用的。通过修改BPE目标并引入merge skipping,我们实现了名为Source-Attributed BPE(SA-BPE)的不同技术来正则化BPE训练并最小化过拟合,从而在保持与常规BPE相同推理过程的同时,大幅减少了训练不足的token数量。这提供了一个适用于生产使用的有效工具。

🔬 方法详解

问题定义:代码Tokenizer在训练时,由于训练数据中代码仓库和编程语言的多样性不平衡,以及某些代码源中重复token的过度出现,导致产生大量未被充分训练的token。这些token在实际推理过程中很少使用,降低了Tokenizer的效率和LLM的性能。现有的BPE算法没有充分考虑数据来源,容易过拟合特定来源的代码模式。

核心思路:SA-BPE的核心思路是通过引入源属性信息来正则化BPE的训练过程,从而减少对特定数据源的过拟合。具体来说,SA-BPE通过修改BPE的目标函数,并引入merge skipping机制,使得Tokenizer在合并token时,会考虑token的来源信息,避免过度合并来自单一来源的token。这样可以鼓励Tokenizer学习更通用的token表示,提高其泛化能力。

技术框架:SA-BPE的技术框架主要包括以下几个步骤:1. 数据预处理:对训练数据进行清洗和标记,区分不同来源的代码。2. BPE训练:使用改进的BPE算法进行训练,其中目标函数和merge过程考虑了源属性信息。3. Tokenizer构建:根据训练结果构建Tokenizer,包括token词表和merge规则。4. 推理:使用构建好的Tokenizer对代码进行tokenization,用于后续的LLM训练或推理。

关键创新:SA-BPE的关键创新在于引入了源属性信息来正则化BPE训练。传统的BPE算法只关注token的频率,而忽略了token的来源。SA-BPE通过修改BPE的目标函数和merge过程,使得Tokenizer在合并token时会考虑token的来源信息,从而避免过度合并来自单一来源的token。这有助于提高Tokenizer的泛化能力,减少低训练token的数量。

关键设计:SA-BPE的关键设计包括:1. 修改BPE目标函数:在BPE的目标函数中引入源属性相关的惩罚项,使得Tokenizer更倾向于合并来自不同来源的token。2. Merge skipping:引入merge skipping机制,允许Tokenizer跳过某些merge操作,避免过度合并来自单一来源的token。3. 超参数调整:需要根据具体的训练数据调整源属性相关的惩罚项和merge skipping的阈值,以达到最佳的正则化效果。

🖼️ 关键图片

fig_0
fig_1
fig_2

📊 实验亮点

论文提出的SA-BPE方法,通过源属性正则化,有效减少了代码Tokenizer中低训练token的数量,在保持推理速度不变的情况下,提高了Tokenizer的泛化能力。具体实验数据未知,但论文强调SA-BPE在减少过拟合方面有显著效果,并适用于生产环境。

🎯 应用场景

SA-BPE可应用于各种代码相关的LLM训练和推理任务,例如代码生成、代码补全、代码搜索和代码分析。通过提高Tokenizer的效率和泛化能力,SA-BPE可以提升LLM的性能,并降低其对特定代码风格的依赖。此外,SA-BPE还可以用于提高代码Tokenizer的安全性,降低jailbreak攻击的风险。

📄 摘要(原文)

Efficiency and safety of Large Language Models (LLMs), among other factors, rely on the quality of tokenization. A good tokenizer not only improves inference speed and language understanding but also provides extra defense against jailbreak attacks and lowers the risk of hallucinations. In this work, we investigate the efficiency of code tokenization, in particular from the perspective of data source diversity. We demonstrate that code tokenizers are prone to producing unused, and thus under-trained, tokens due to the imbalance in repository and language diversity in the training data, as well as the dominance of source-specific, repetitive tokens that are often unusable in future inference. By modifying the BPE objective and introducing merge skipping, we implement different techniques under the name Source-Attributed BPE (SA-BPE) to regularize BPE training and minimize overfitting, thereby substantially reducing the number of under-trained tokens while maintaining the same inference procedure as with regular BPE. This provides an effective tool suitable for production use.