[论文解读] ShortCoder: Knowledge-Augmented Syntax Optimization for Token-Efficient Code Generation
ShortCoder 使用 10 条 Python 语法简化规则、基于规则的方法结合 LLM 指导的数据合成流水线,以及 LoRA 微调,生成简洁且语义正确的代码,在 HumanEval 上实现约 18.1% 的 token 减少并具备有竞争力的性能。
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.
研究动机与目标
- 在不牺牲正确性或可读性的前提下,降低 token 使用量并提升代码生成效率。
- 利用保持 AST 的语法简化规则,创建高质量的简洁码语料库。
- 通过高效微调将领域知识注入到大模型,支持零-shot 的简洁代码生成。
提出的方法
- 设计十条保持 AST 的 Python 语法简化规则(表 I),在不功能损失的前提下将 token 减少 18.1%。
- 通过基于规则的和 LLM 指导的合成搭建 ShorterCodeBench,创建 <原始代码, 简化代码> 对(828 对经验证)。
- 使用 LoRA 对代码 LLM 进行微调以注入简洁性知识,实现零-shot 的简洁代码生成。
- 进行基于规则的数据构建和 LLM 辅助的数据构造,以生成知识注入的训练对。
- 使用 HumanEval 的 pass@k 指标和效率指标(tokens、延迟)进行评估。
- 与基线模型(CodeLlama-Instruct、CodeGen、DeepSeek-Coder)进行对比,以评估效率和性能。
实验结果
研究问题
- RQ1RQ1:与基线代码生成模型相比,ShortCoder 在功能正确性和效率方面的表现如何?
- RQ2RQ2:ShortCoder 的效率与基于提示的效率提升技术相比如何?
- RQ3RQ3:与基线相比,ShortCoder 生成的代码的可读性和简洁性如何(人类评估)?
主要发现
| Model | Pass@1 | Pass@10 | Pass@100 | GenTokens |
|---|---|---|---|---|
| CodeGen | 0.429 | 0.538 | 0.620 | 260.34 |
| CodeLlama-7B-Instruct-hf | 0.474 | 0.579 | 0.650 | 197.80 |
| DeepSeek-Coder-1.3B-Base | 0.324 | 0.457 | 0.690 | 171.35 |
| DeepSeek-Coder-6.7B-Instruct | 0.791 | 0.884 | 0.920 | 186.69 |
| ShortCoder | 0.612 | 0.764 | 0.967 | 162.02 |
- ShortCoder 相对于基线在生成 token 上实现 18.1% 至 37.8% 的减少。
- 在 HumanEval 上,ShortCoder 的 Pass@1=0.612,Pass@10=0.764,Pass@100=0.967,同时平均生成 162.02 个 token(GenTokens)。
- ShortCoder 在效率指标上超越基线并接近最前沿的性能,且 token 成本更低。
- 使用 LoRA 微调实现对简洁性知识的注入,参数量显著下降。
- 基于规则的微调在效率上始终优于基于提示的方法,平均问题延迟降低 25%-64%。
- ShortCoder 的方法在保持或提升功能正确性的同时,生成的代码更短、可读性更高。
更好的研究,从现在开始
从论文设计到论文写作,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。