arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2410.05605cs.SE
收藏

CodeDPO:利用自生成与验证的源代码对齐代码模型

CodeDPO: Aligning Code Models with Self Generated and Verified Source Code

Kechi Zhang, Ge Li, Yihong Dong, Jingjing Xu, Jun Zhang, Jing Su, Yongfei Liu, Zhi Jin

AI总结:

CodeDPO 提出将偏好学习融入代码生成,通过自生成与验证机制和 PageRank 启发式算法构建基于正确性与效率的偏好数据集,在多个基准上显著提升代码模型的正确性和运行效率。

摘要:

代码生成模型在编程任务中已展现出显著潜力。然而,现有的训练方法(如监督微调)面临关键局限:它们既不能有效教会模型在模糊情境下优先选择正确而非错误的解决方案,也不能有效优化所生成代码的运行时效率。为应对这些挑战,我们提出了 CodeDPO,一个将偏好学习融入代码生成的框架,以改进两个关键代码偏好因素:代码正确性与效率。CodeDPO 采用一种新颖的数据集构建方法,利用自生成与验证机制同时生成并评估代码和测试用例。其基本假设是:能被多个代码片段执行的测试用例能提供更可靠的验证,而通过更多测试的代码更可能是正确的。通过这一自验证过程,我们受 PageRank 启发的算法迭代更新每个代码片段的排名分数,最终基于正确性和效率构建代码偏好优化数据集。CodeDPO 灵活且可扩展,能在不依赖外部资源的情况下生成多样化的偏好优化数据。通过对五个广泛使用的基准进行全面评估,CodeDPO 在正确性和效率方面相较现有方法均展现出显著提升。我们的实验证明,CodeDPO 增强了 LLM 在代码生成方面的能力,并为在更复杂、更具挑战性的现实场景中开展代码偏好优化提供了坚实基础。

英文摘要:

Code generation models have shown significant potential for programming tasks. However, existing training methods like supervised fine-tuning face key limitations: they do not effectively teach models to prioritize correct over incorrect solutions in ambiguous situations, nor do they effectively optimize the runtime efficiency of the generated code. To address these challenges, we propose CodeDPO, a framework that integrates preference learning into code generation to improve two key code preference factors: code correctness and efficiency. CodeDPO employs a novel dataset construction method, utilizing a self-generation-and-validation mechanism that simultaneously generates and evaluates code and test cases. The underlying assumption is that test cases executable by multiple code snippets provide more reliable validation, and code that passes more tests is more likely to be correct. Through this self-validation process, our PageRank-inspired algorithm iteratively updates the ranking score of each code snippet, ultimately creating a code preference optimization dataset based on correctness and efficiency. CodeDPO is flexible and scalable, generating diverse preference optimization data without depending on external resources. Through comprehensive evaluations of five widely used benchmarks, CodeDPO demonstrates significant improvements in correctness and efficiency compared to existing methods. Our experiments prove that CodeDPO enhances the capabilities of LLMs in code generation and provides a robust foundation for conducting code preference optimization in more complex and challenging real-world scenarios.

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

↑