arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2601.09703cs.SEcs.AIcs.CL
收藏

ShortCoder: 用于令牌高效代码生成的知识增强语法优化

ShortCoder: Knowledge-Augmented Syntax Optimization for Token-Efficient Code Generation

Sun Yat-sen University, China(中山大学);Huawei Cloud Computing Technologies Co., Ltd., China(华为云计算技术有限公司);Chongqing University, China(重庆大学);University of Electronic Science and Technology of China, China(电子科技大学)

Sicong Liu, Yanxian Huang, Mingwei Liu, Jiachi Chen, Ensheng Shi, Yuchi Ma, Hongyu Zhang, Yin Zhang, Yanlin Wang

AI总结:

ShortCoder通过语法优化和知识增强提升代码生成效率,实现18.1%-37.8%的效率提升。

摘要:

代码生成任务旨在自动化将用户需求转换为可执行代码,显著减少手动开发的工作量并提高软件生产率。大型语言模型(LLMs)的出现显著推动了代码生成的发展,但其效率仍然受到某些固有架构限制的影响。每个令牌生成都需要完整的推理过程,要求在内存中持续保留上下文信息,从而增加资源消耗。尽管现有研究优先考虑推理阶段的优化,如提示压缩和模型量化,但生成阶段仍被忽视。为解决这些挑战,我们提出了一种名为ShortCoder的知识融合框架,旨在优化代码生成效率的同时保持语义等价性和可读性。特别地,我们引入了:(1)从保持AST转换派生出的十条语法级简化规则,用于Python,实现18.1%的令牌减少,而无需功能妥协;(2)一个混合数据合成管道,结合基于规则的重写与LLM引导的细化,生成ShorterCodeBench,一个包含原始代码和简化代码的验证元组的语义一致的语料库;(3)一种微调策略,将简洁性意识注入基础LLMs中。广泛的实验结果表明,ShortCoder在HumanEval上始终优于最先进的方法,实现比先前方法在生成效率上提高18.1%-37.8%的同时,确保代码生成的性能。

英文摘要:

Code generation tasks aim to automate the conversion of user requirements into executable code, significantly reducing manual development efforts and enhancing software productivity. The emergence of large language models (LLMs) has significantly advanced code generation, though their efficiency is still impacted by certain inherent architectural constraints. Each token generation necessitates a complete inference pass, requiring persistent retention of contextual information in memory and escalating resource consumption. While existing research prioritizes inference-phase optimizations such as prompt compression and model quantization, the generation phase remains underexplored. To tackle these challenges, we propose a knowledge-infused framework named ShortCoder, which optimizes code generation efficiency while preserving semantic equivalence and readability. In particular, we introduce: (1) ten syntax-level simplification rules for Python, derived from AST-preserving transformations, achieving 18.1% token reduction without functional compromise; (2) a hybrid data synthesis pipeline integrating rule-based rewriting with LLM-guided refinement, producing ShorterCodeBench, a corpus of validated tuples of original code and simplified code with semantic consistency; (3) a fine-tuning strategy that injects conciseness awareness into the base LLMs. Extensive experimental results demonstrate that ShortCoder consistently outperforms state-of-the-art methods on HumanEval, achieving an improvement of 18.1%-37.8% in generation efficiency over previous methods while ensuring the performance of code generation.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑