Lune

EMNLP Findings2025

Self-Correcting Code Generation Using Small Language Models

Jeonghun Cho, Deokhyung Kang, Hyounghun Kim, Gary Lee

Abstract

Self-correction has demonstrated potential in code generation by allowing language models to revise and improve their outputs through successive refinement. Recent studies have explored prompting-based strategies that incorporate verification or feedback loops using proprietary models, as well as training-based methods that leverage their strong reasoning capabilities. However, whether smaller models possess the capacity to effectively guide their outputs through self-reflection remains unexplored. Our findings reveal that smaller models struggle to exhibit reflective revision behavior across both self-correction paradigms. In response, we introduce COCOS, an approach designed to enhance the ability of small language models for multi-turn code correction. Specifically, we propose an online reinforcement learning objective that trains the model to confidently maintain correct outputs while progressively correcting incorrect outputs as turns proceed. Our approach features an accumulated reward function that aggregates rewards across the entire trajectory and a fine-grained reward better suited to multi-turn correction scenarios. This facilitates the model in enhancing initial response quality while achieving substantial improvements through self-correction. With 1B-scale models, COCOS achieves improvements of 35.8% on the MBPP and 27.7% on HumanEval compared to the baselines. 1

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

1 top-tier paper has cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • STaR: Bootstrapping Reasoning With Reasoning cites Language Models are Few-Shot Learners
  • Direct Preference Optimization: Your Language Model is Secretly a Reward Model cites Language Models are Few-Shot Learners
  • Teaching Large Language Models to Self-Debug cites Self-Refine: Iterative Refinement with Self-Feedback
  • Teaching Large Language Models to Self-Debug cites Language Models are Few-Shot Learners
  • MM-ReCoder: Advancing Chart-to-Code Generation with Reinforcement Learning and Self-Correction cites Direct Preference Optimization: Your Language Model is Secretly a Reward Model
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers1

  1. MM-ReCoder: Advancing Chart-to-Code Generation with Reinforcement Learning and Self-CorrectionZitian Tang, Xu Zhang, Jianbo Yuan, Yang Zou et al.CVPR 2026 · 4 citations

Builds on18

  1. Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 citations
  2. Direct Preference Optimization: Your Language Model is Secretly a Reward ModelRafael Rafailov, Archit Sharma, Eric Mitchell, Christopher D. Manning et al.NeurIPS 2023 · 10,924 citations
  3. Self-Refine: Iterative Refinement with Self-FeedbackAman Madaan, Niket Tandon, Prakhar Gupta, Skyler Hallinan et al.NeurIPS 2023 · 4,972 citations
  4. STaR: Bootstrapping Reasoning With ReasoningEric Zelikman, Yuhuai Wu, Jesse Mu, Noah D. GoodmanNeurIPS 2022 · 1,126 citations
  5. Teaching Large Language Models to Self-DebugXinyun Chen, Maxwell Lin, Nathanael Schärli, Denny ZhouICLR 2024 · 1,085 citations

Related papers

  1. 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 et al.ACL Findings 2026 · 2 citations
  2. Small Language Models Need Strong Verifiers to Self-Correct ReasoningYunxiang Zhang, Muhammad Khalifa, Lajanugen Logeswaran, Jaekyeom Kim et al.ACL Findings 2024 · 6 citations
  3. Training Language Models to Self-Correct via Reinforcement LearningAviral Kumar, Vincent Zhuang, Rishabh Agarwal, Yi Su et al.ICLR 2025
  4. Teaching Language Models to Critique via Reinforcement LearningZhihui Xie, Jie Chen, Liyu Chen, Weichao Mao et al.ICML 2025
  5. Self-Verifying Reflection Helps Transformers with CoT ReasoningZhongwei Yu, Wannian Xia, Xue Yan, Bo Xu et al.NeurIPS 2025 · 3 citations
Dusk over the sea between two cliffs drawn in fine vertical lines