paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Token Sugar: Making Source Code Sweeter for LLMs through Token-Efficient Shorthand

Token Sugar:用 token 高效简写让源代码对 LLM 更「甜」
ASE 2025 40th IEEE/ACM International Conference on Automated Software Engineering (ASE)2025匹配度 2/10 · 该论文研究通过代码简写降低 LLM 的 token 开销,属于语言设计与 LLM 效率的交叉,但未涉及用户核心方向中的静态分析、Agentic 程序、浮点程序分析或贝叶斯程序分析。其目标更偏向提升 LLM 本身效率,而非将静态分析用于 AI 或用 LLM 改进程序分析。引用 0 inbox
Zhensu Sun, Chengran Yang, Xiaoning Du, Zhou Yang, Li Li, David Lo
crossref: 2026-09-12

AI 速览

一句话:提出 Token Sugar:将高频冗长代码模式替换为可逆简写,降低 LLM 代码任务的 token 开销并保持性能。

大语言模型在代码生成与理解上表现优异,但编程语言本身的冗长(格式化元素、样板代码)导致输入与输出的 token 数量膨胀,推高推理成本并拖慢生成。已有工作通过简化编程语言语法来减少 token,但局限于句法层面,语义层面的压缩空间未被挖掘。本文提出 Token Sugar 概念:把高频且冗长的代码模式替换为可逆、token 高效的简写形式。作者设计了系统化方案,从代码语料中挖掘高频、token 重的模式,为每个模式映射唯一简写,并通过代码变换将其融入 LLM 预训练。该方案得到 799 个(代码模式, 简写)对,可在源代码上减少最多 15.1% 的 token 数,且与既有的以语法为中心的方法互补。作者用 Token Sugar 增强的数据训练三个常用 LLM,实验显示生成阶段 token 最多减少 11.2%,同时 Pass@1 与在未处理代码上训练的基线几乎持平。

问题
编程语言的冗长(格式化与样板代码)使 LLM 在代码理解与生成中消耗过多 token,增加推理成本;已有语法简化方法仅停留在句法层面,未利用语义层面的压缩机会。
方法
提出 Token Sugar,从代码语料中挖掘高频、token 重的代码模式,为每个模式分配唯一的可逆简写,并通过代码变换把简写注入 LLM 预训练数据。
评估
构建了 799 个(代码模式, 简写)对并测量源代码 token 压缩率(最高 15.1%);在三个常用 LLM 上用 Token Sugar 增强数据训练,比较生成阶段的 token 节省(最高 11.2%)与 Pass@1 相对未处理代码基线的变化。
原文摘要(Abstract)

Large language models (LLMs) have shown exceptional performance in code generation and understanding tasks, yet their high computational costs hinder broader adoption. One important factor is the inherent verbosity of programming languages, such as unnecessary formatting elements and lengthy boilerplate code. This leads to inflated token counts in both input and generated outputs, which increases inference costs and slows down the generation process. Prior work improves this through simplifying programming language grammar, reducing token usage across both code understanding and generation tasks. However, it is confined to syntactic transformations, leaving significant opportunities for token reduction unrealized at the semantic level.In this work, we propose Token Sugar, a concept that replaces frequent and verbose code patterns with reversible, token-efficient shorthand in the source code. To realize this concept in practice, we designed a systematic solution that mines high-frequency, token-heavy patterns from a code corpus, maps each to a unique shorthand, and integrates them into LLM pretraining via code transformation. With this solution, we obtain 799 (code pattern, shorthand) pairs, which can reduce up to 15.1% token count in the source code and is complementary to existing syntax-focused methods. We further trained three widely used LLMs on Token Sugar-augmented data. Experimental results show that these models not only achieve significant token savings (up to 11.2% reduction) during generation but also maintain near-identical Pass@1 scores compared to baselines trained on unprocessed code.

链接与引用

DOI 原文 ·

BibTeX
@inproceedings{paperbot9398,
  title = {Token Sugar: Making Source Code Sweeter for LLMs through Token-Efficient Shorthand},
  author = {Zhensu Sun and Chengran Yang and Xiaoning Du and Zhou Yang and Li Li and David Lo},
  booktitle = {ASE},
  year = {2025},
  doi = {10.1109/ase63991.2025.00201}
}