LeDex: Training LLMs to Better Self-Debug and Explain Code
Nan Jiang, Xiaopeng Li, Shiqi Wang, Qiang Zhou, Soneya Binta Hossain, Baishakhi Ray, Varun Kumar, Xiaofei Ma, Anoop Deoras
摘要
In the domain of code generation, self-debugging is crucial. It allows LLMs to refine their generated code based on execution feedback. This is particularly important because generating correct solutions in one attempt proves challenging for complex tasks. Prior works on self-debugging mostly focus on prompting methods by providing LLMs with few-shot examples, which work poorly on small open-sourced LLMs. In this work, we propose LeDex, a training framework that significantly improves the self-debugging capability of LLMs. Intuitively, we observe that a chain of explanations on the wrong code followed by code refinement helps LLMs better analyze the wrong code and do refinement. We thus propose an automated pipeline to collect a high-quality dataset for code explanation and refinement by generating a number of explanations and refinement trajectories from the LLM itself or a larger teacher model and filtering via execution verification. We perform supervised fine-tuning (SFT) and further reinforcement learning (RL) on both success and failure trajectories with a novel reward design considering code explanation and refinement quality. SFT improves the pass@1 by up to 15.92% and pass@10 by 9.30% over four benchmarks. RL training brings additional up to 3.54% improvement on pass@1 and 2.55% improvement on pass@10. The trained LLMs show iterative refinement ability and can keep refining code continuously. Lastly, our human evaluation shows that the LLMs trained with our framework generate more useful code explanations and help developers better understand bugs in source code.
问 Lune
几分钟读透这篇 Paper,不用再花一下午。
Lune 能读完全文,也能读引用它的顶会 Paper,讲清它的结论、证据和局限,每一点都注明出自哪篇 Paper。不用硬啃,也不靠猜。
已有 11 篇顶会 Paper 引用了它。别等审稿人问起,先弄清它们发现了什么。
脉络
- Hierarchy-of-Groups Policy Optimization for Long-Horizon Agentic Tasks 引用了 Direct Preference Optimization: Your Language Model is Secretly a Reward Model
- Hierarchy-of-Groups Policy Optimization for Long-Horizon Agentic Tasks 引用了 Reflexion: language agents with verbal reinforcement learning
- From Intent to Execution: Multimodal Chain-of-Thought Reinforcement Learning for Precise CAD Code Generation 引用了 Direct Preference Optimization: Your Language Model is Secretly a Reward Model
- Teaching Large Language Models to Self-Debug 引用了 Self-Refine: Iterative Refinement with Self-Feedback
- Reflexion: language agents with verbal reinforcement learning 引用了 Self-Refine: Iterative Refinement with Self-Feedback
- Reflexion: language agents with verbal reinforcement learning 引用了 Teaching Large Language Models to Self-Debug
- Co-PatcheR: Collaborative Software Patching with Component-specific Small Reasoning Models 引用了 Direct Preference Optimization: Your Language Model is Secretly a Reward Model
- Advancing Tool-Augmented Large Language Models via Meta-Verification and Reflection Learning 引用了 Self-Refine: Iterative Refinement with Self-Feedback
- Advancing Tool-Augmented Large Language Models via Meta-Verification and Reflection Learning 引用了 Direct Preference Optimization: Your Language Model is Secretly a Reward Model
- Advancing Tool-Augmented Large Language Models via Meta-Verification and Reflection Learning 引用了 Reflexion: language agents with verbal reinforcement learning
引用它的顶会 Paper11
- Hierarchy-of-Groups Policy Optimization for Long-Horizon Agentic TasksShuo He, Lang Feng, Qi Wei, Xin Cheng 等ICLR 2026 · 36 次引用
- From Intent to Execution: Multimodal Chain-of-Thought Reinforcement Learning for Precise CAD Code GenerationKe Niu, Haiyang Yu, Zhuofan Chen, Mengyang Zhao 等AAAI 2026 · 5 次引用
- CodeEvo: Interaction-Driven Synthesis of Code-centric Data through Hybrid and Iterative FeedbackQiushi Sun, Jingyang Gong, Lei Li, Qipeng Guo 等ACL 2026 · 4 次引用
- Advancing Tool-Augmented Large Language Models via Meta-Verification and Reflection LearningZhiyuan Ma, Jiayu Liu, Xianzhen Luo, Zhenya Huang 等KDD 2025 · 4 次引用
- Co-PatcheR: Collaborative Software Patching with Component-specific Small Reasoning ModelsYuheng Tang, Hongwei Li, Kaijie Zhu, Michael Yang 等NeurIPS 2025 · 2 次引用
它引用的 Paper22
- Direct Preference Optimization: Your Language Model is Secretly a Reward ModelRafael Rafailov, Archit Sharma, Eric Mitchell, Christopher D. Manning 等NeurIPS 2023 · 10,924 次引用
- Reflexion: language agents with verbal reinforcement learningNoah Shinn, Federico Cassano, Ashwin Gopinath, Karthik Narasimhan 等NeurIPS 2023 · 5,828 次引用
- Self-Refine: Iterative Refinement with Self-FeedbackAman Madaan, Niket Tandon, Prakhar Gupta, Skyler Hallinan 等NeurIPS 2023 · 4,972 次引用
- CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and GenerationYue Wang, Weishi Wang, Shafiq R. Joty, Steven C. H. HoiEMNLP 2021 · 1,224 次引用
- Teaching Large Language Models to Self-DebugXinyun Chen, Maxwell Lin, Nathanael Schärli, Denny ZhouICLR 2024 · 1,085 次引用
相关 Paper
- NExT: Teaching Large Language Models to Reason about Code ExecutionAnsong Ni, Miltiadis Allamanis, Arman Cohan, Yinlin Deng 等ICML 2024 · 73 次引用
- Revisit Self-Debugging with Self-Generated Tests for Code GenerationXiancai Chen, Zhengwei Tao, Kechi Zhang, Changzhi Zhou 等ACL 2025
- ReflexiCoder: Teaching Large Language Models to Self-Reflect on Generated Code and Self-Correct It via Reinforcement LearningJuyong Jiang, Jiasi Shen, Sunghun Kim, Kang Min Yoo 等ACL Findings 2026 · 2 次引用
- Code Reffix: A Benchmark for Reflection-Guided Code Repair with Large Language ModelsZaiyuan Di, Jianting Chen, Yunxiao Yang, Xiaoying Gao 等ACL Findings 2026 · 2 次引用
- Divide-Verify-Refine: Can LLMs Self-align with Complex Instructions?Xianren Zhang, Xianfeng Tang, Hui Liu, Zongyu Wu 等ACL Findings 2025 · 1 次引用
