Research map / Large language models / Agents, code and math
LeDex: Training LLMs to Better Self-Debug and Explain Code
Read the paperCheck your idea against 108,967 papers
AI-extracted summary. Written by AI from the paper's full text. Numbers and claims can be wrong or missing context, so check the paper before you cite or build on it.
Proposes LeDex, a pipeline that collects code explanation-and-refinement trajectories from LLMs (GPT-3.5, CodeLlama-34B/7B) filtered by execution, then trains StarCoder-15B and CodeLlama-7B/13B with SFT and PPO using a novel explanation-and-refinement reward to improve self-debugging.
Problem
Open-sourced code LLMs have limited self-debugging ability: prompting them to explain and refine incorrect code works poorly, and high-quality code explanation and refinement training data is scarce.
Approach
Collect verified chain-of-thought trajectories (explanation then refinement) from a stronger or the same LLM, filter them by unit-test execution, fine-tune with SFT, and then apply PPO with separate rewards for the refinement (CodeBLEU plus test pass rate) and the explanation (RoBERTa embedding similarity to correct explanations).
Key results
- SFT improves StarCoder-15B pass@1 by up to 15.92% and pass@10 by 9.30% over prompting on MBPP/HumanEval and MBPP+/HumanEval+ combined.
- RL adds up to 3.54% pass@1 and 2.55% pass@10 on top of SFT.
- CodeLlama-7B trained on CodeLlama-34B data gains up to 5.28% pass@1 on MBPP+/HumanEval+ with RL; self-bootstrapped CodeLlama-7B gains up to 8.25% pass@1 with SFT.
Measured effects reported in the paper
| What was changed | Where | Measured | Effect |
|---|---|---|---|
| SFT on explanation and refinement trajectories | StarCoder-15B · MBPP & HumanEval | pass@1: +15.92 | Helped |
| Apply RL after SFT with direct refinement | StarCoder-15B · MBPP & HumanEval | pass@10: +2.55 | Helped |
| Apply RL after SFT with explanation and refinement | CodeLlama-7B · MBPP & HumanEval | pass@1: -0.60; +0.66 | Mixed |
| Apply RL after SFT with explanation and refinement | CodeLlama-13B · MBPP+ & HumanEval+ | pass@1: +3.34 | Helped |
| Train with code explanation and refinement data instead of prompting | StarCoder-15B · Four benchmarks | success refinement rate: 6.90 -> 16.27 | Helped |
| Add code explanation before refinement rather than requesting refinement directly (ablation) | StarCoder-15B · MBPP | success refinement rate: 2.58 -> 4.43 | Helped |
| Add code explanation before refinement rather than requesting refinement directly (ablation) | CodeLlama-7B · MBPP | success refinement rate: 7.42 -> 6.71 | Hurt |
| Add code explanation before refinement rather than requesting refinement directly (ablation) | CodeLlama-13B · MBPP | success refinement rate: 9.80 -> 10.20 | Helped |
| Use self-bootstrapped training data rather than prompting | CodeLlama-7B · MBPP & HumanEval | pass@1: +8.25 | Helped |
| Apply RL after SFT using self-bootstrapped data | CodeLlama-7B · MBPP & HumanEval | pass@10: +0.11; -0.05 | Mixed |
| Use full explanation and refinement data rather than code-generation-only data (ablation) | CodeLlama-7B · HumanEval | pass@1: 42.91 -> 52.65 | Helped |
| Use RL training with separate explanation and refinement rewards after SFT | StarCoder-15B · Code explanation rating | GPT-4 average score: 2.92 -> 3.18 | Helped |
Surprising findings
- Prompted open-source models often just repeat the wrong solution or hallucinate explanations, and explanation-then-refine prompting only modestly helps them (e.g., StarCoder-15B 4.43% refinement on MBPP).
- RL gains are larger on harder benchmarks (MBPP+/HumanEval+) than on the originals, and RL offers less improvement when data comes from self-bootstrapping than from stronger LLMs.
Limitations
- Relies on specific teacher LLMs for data collection, though tested with several models.
- Only two prompt types for self-debugging were explored.
- Explanation quality evaluated on only 50 problems with human raters limited to StarCoder and GPT-3.5 outputs.
Experimental setup
Datasets: MBPP APPS CodeContests
Benchmarks: MBPP HumanEval MBPP+ HumanEval+
Metrics: pass@1 pass@10 success refinement rate
Baselines: Prompting self-refinement ILF GPT-3.5-Turbo CYCLE Self-Edit
Builds on: PPO CodeBLEU StarChat ILF
Closest papers by meaning
- Teaching Large Language Models to Self-Debug (ICLR 2024 · similarity 0.90)
- NExT: Teaching Large Language Models to Reason about Code Execution (ICML 2024 · similarity 0.88)
- SemCoder: Training Code Language Models with Comprehensive Semantics Reasoning (NeurIPS 2024 · similarity 0.87)
- Code Repair with LLMs gives an Exploration-Exploitation Tradeoff (NeurIPS 2024 · similarity 0.87)
- LLM-Assisted Code Cleaning For Training Accurate Code Generators (ICLR 2024 · similarity 0.87)
- Rethinking Verification for LLM Code Generation: From Generation to Testing (NeurIPS 2025 · similarity 0.87)
Writing a paper in this area? scime draft is a free LaTeX editor with AI included, real-time co-authors and a check of your references and venue rules before you submit. It also imports OpenAI Prism projects.
