arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2509.25243cs.SEcs.AI
收藏

强化学习引导的草稿链:实现 Token 高效的代码生成

Reinforcement Learning-Guided Chain-of-Draft for Token-Efficient Code Generation

University of Luxembourg(卢森堡大学)

Xunzhu Tang, Iyiola Emmanuel Olatunji, Tiezhu Sun, Jacques Klein, Tegawende F. Bissyande

AI总结:

本文提出 MultiCoD 强化学习框架,将 CoD 多候选代码方案选择建模为上下文赌博机,并依据正确性、效率和清晰性优化可解释特征,在多个基准上提升质量且降低用户成本逾 50%。

摘要:

LLM 在代码生成中表现出表层流畅性,但在需要正确性和语义对齐的结构化推理任务上仍存在困难。虽然 Chain-of-Thought(CoT,思维链)提示通过中间步骤增强推理,却存在冗长且效率低下的问题。Chain-of-Draft(CoD,草稿链)提示提供了更简洁的推理,但 LLM 的随机性会产生质量不一的解决方案,使最优选择具有挑战性。我们提出 MultiCoD,这是一个强化学习框架,用于学习从 CoD 生成的解决方案中选择最有前景的候选。该方法采用策略引导提示以鼓励多样化推理风格,并将解决方案选择建模为上下文赌博机问题。框架通过平衡正确性、效率和清晰性的奖励函数,优化代码复杂度、推理结构和策略元数据等可解释特征。在 MBPP、BigCodeBench、SWE-bench Verified 和 Defects4J 上的实验表明,MultiCoD 优于标准提示、CoT 和 CoD 基线,在部分情况下与其表现相当;同时,从用户视角通过多候选设计实现成本和 token 效率,即仅对所选输出收费,使用户账单降低超过 50%,并提升 LLM 响应质量,使 MultiCoD 在真实部署中更具可持续性和可扩展性。代码位于 https://anonymous.4open.science/r/MultiCoD。

英文摘要:

LLMs demonstrate surface-level fluency in code generation but struggle with structured reasoning tasks requiring correctness and semantic alignment. While Chain-of-Thought (CoT) prompting enhances reasoning through intermediate steps, it suffers from verbosity and inefficiency. Chain-of-Draft (CoD) prompting offers more concise reasoning, but the stochastic nature of LLMs produces varying solution quality, making optimal selection challenging. We propose \multicod, a reinforcement learning framework that learns to select the most promising candidate from CoD-generated solutions. Our approach uses strategy-guided prompting to encourage diverse reasoning styles and models solution selection as a contextual bandit problem. The framework optimizes interpretable features including code complexity, reasoning structure, and strategic metadata through a reward function balancing correctness, efficiency, and clarity. Experiments on MBPP, BigCodeBench, SWE-bench Verified, and Defects4J show \multicod~outperforms and in some cases, on par with standard prompting, CoT, and CoD baselines while achieving cost and token efficiency from the user's perspective through a multi-candidate design that charges only for the selected output, reducing user billing by over 50\% and improving LLM response quality, making \multicod~more sustainable and scalable for real-world deployment. Our code is available: https://anonymous.4open.science/r/MultiCoD.

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

↑