CODEPROMPTZIP:用于编码任务中基于检索的生成的代码特定提示压缩
CODEPROMPTZIP: Code-specific Prompt Compression for Retrieval-Augmented Generation in Coding Tasks with LMs
AI总结:
本文提出CodePromptZip框架,通过程序分析识别代码token类型并进行消融分析,训练小型LM实现灵活压缩,提升编码任务性能。
摘要:
检索增强生成(RAG)通过整合检索到的代码示例增强编码任务,但长提示导致上下文窗口限制和高计算成本。本文提出CodePromptZip框架,在整合到RAG工作流前压缩代码示例。框架采用类型感知、优先级驱动策略构建训练样本,通过程序分析识别token类型(如标识符)并进行消融分析以确定其移除优先级。然后在这些样本上训练小型LM作为压缩器,实现灵活压缩并最小化性能损失。特别地,压缩器配备复制机制,允许直接复制原始代码片段。评估结果表明,CodePromptZip在断言生成、Bugs2Fix和代码建议任务中分别比最佳基线提升23.4%、28.7%和8.7%。
英文摘要:
Retrieval-Augmented Generation (RAG) enhances coding tasks by incorporating retrieved code examples into prompts. However, lengthy prompts, often exceeding tens of thousands of tokens, introduce challenges related to limited context windows of language models (LMs) and high computational costs. Existing prompt compression techniques focus on natural language, lacking tailored solutions for code. To address the gap, we propose CodePromptZip, a framework that compresses code examples before integrating into RAG workflows. Our framework employs a type-aware, priority-driven strategy to construct training samples for training code compression model. By using program analysis, we identify token types (e.g., Identifier) and perform ablation analysis to rank their removal priorities based on their impact on task performance. We then train a small LM as the compressor on these samples, enabling flexible compression conditioned on specified ratios while minimizing performance degradation. Specially, the compressor is augmented with a copy mechanism, allowing tokens to be directly copied from the original code snippets. Evaluation results show that CodePromptZip surpasses SOTA entropy-based and distillation-based baselines, improving by 23.4%, 28.7%, and 8.7% over the best baseline for Assertion Generation, Bugs2Fix, and Code Suggestion, respectively.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。