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

TL;DR
LeDex is a training framework that enhances large language models' ability to self-debug and explain code through supervised fine-tuning and reinforcement learning, leading to more accurate and useful code generation and debugging.
Contribution
This work introduces LeDex, a novel training pipeline that improves LLM self-debugging by leveraging explanation and refinement trajectories generated and filtered automatically.
Findings
Supervised fine-tuning improves pass@1 by up to 15.92%
Reinforcement learning further boosts pass@1 by up to 3.54%
Trained models demonstrate iterative code refinement and generate more helpful explanations.
Abstract
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…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
Taxonomy
TopicsLaw, AI, and Intellectual Property · Artificial Intelligence in Law
MethodsFocus · Shrink and Fine-Tune
