Token Sugar:通过高效的token缩写使源代码更甜
Token Sugar: Making Source Code Sweeter for LLMs through Token-Efficient Shorthand
AI总结:
Token Sugar通过高效的token缩写减少源代码的token数量,提升LLM在代码生成中的效率和性能。
摘要:
大型语言模型(LLMs)在代码生成和理解任务中表现出色,但其高计算成本限制了更广泛的应用。一个重要因素是编程语言本身的冗长性,例如不必要的格式元素和冗长的样板代码。这导致输入和生成输出的token数量增加,增加了推理成本并减慢了生成过程。先前的工作通过简化编程语言语法来改进这一点,减少了代码理解和生成任务中的token使用量。然而,这些方法仅限于语法转换,留下了在语义层面实现token减少的巨大机会。在本工作中,我们提出了Token Sugar,一个概念,将频繁且冗长的代码模式替换为可逆的、高效的token缩写。为了在实践中实现这一概念,我们设计了一种系统性的解决方案,从代码语料库中挖掘高频、token密集的模式,将每个模式映射到一个独特的缩写,并通过代码转换将其整合到LLM预训练中。通过这一解决方案,我们获得了799(代码模式,缩写)对,这可以将源代码的token数量减少高达15.1%,并且与现有语法导向方法互补。我们进一步在Token Sugar增强的数据上训练了三个广泛使用的LLM。实验结果表明,这些模型不仅在生成过程中实现了显著的token节省(最高减少11.2%),而且与训练于未处理代码的基线模型相比,保持了几乎相同的Pass@1分数。
英文摘要:
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.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。