2025-10-17 · 进阶 · 计算机视觉 · 机器学习

TokDrift: When LLM Speaks in Subwords but Code Speaks in Grammar

该论文提出了TOKDRIFT框架,用于量化大型语言模型对语义保持性代码重写的敏感性,揭示了子词分词与编程语言语法不匹配对代码理解和生成的影响。

更新于 2025-10-17。作者:Yinxi Li、Yuntian Deng、Pengyu Nie。

中文摘要

大型代码语言模型(LLMs)依赖于从混合自然语言文本和编程语言代码中学习到的子词分词器,如字节对编码(BPE),其驱动因素是统计而非语法。因此,语义相同的代码片段可能会因为诸如空白或标识符命名等表面因素而以不同的方式进行分词。为了衡量这种不匹配的影响,我们引入了TokDrift框架,该框架通过应用语义保留的重写规则来创建仅在分词上有所不同的代码变体。在九个代码LLMs中,包括参数超过30亿的LLMs,即使是微小的格式变化也可能导致模型行为的重大变化。分层分析表明,问题起源于早期嵌入层,其中子词分割未能捕捉到语法标记边界。我们的研究结果表明,不匹配的分词是可靠代码理解和生成的潜在障碍,突显了未来代码LLMs需要语法感知分词的必要性。

英文摘要

Large language models (LLMs) for code rely on subword tokenizers, such as byte-pair encoding (BPE), learned from mixed natural language text and programming language code but driven by statistics rather than grammar. As a result, semantically identical code snippets can be tokenized differently depending on superficial factors such as whitespace or identifier naming. To measure the impact of this misalignment, we introduce TokDrift, a framework that applies semantic-preserving rewrite rules to create code variants differing only in tokenization. Across nine code LLMs, including large ones with over 30B parameters, even minor formatting changes can cause substantial shifts in model behavior. Layer-wise analysis shows that the issue originates in early embeddings, where subword segmentation fails to capture grammar token boundaries. Our findings identify misaligned tokenization as a hidden obstacle to reliable code understanding and generation, highlighting the need for grammar-aware tokenization for future code LLMs.

解读

一句话总结

该论文提出了TOKDRIFT框架,用于量化大型语言模型对语义保持性代码重写的敏感性,揭示了子词分词与编程语言语法不匹配对代码理解和生成的影响。

问题1:这篇论文想要解决什么具体问题?

问题2:论文的核心创新点是什么?

问题3:实验结果如何验证了方法的有效性?

问题4:这个研究的实际应用价值是什么?

来源

机器可读索引:llms.txt