PofoliaShared via Pofolia

Scientific Reports· 2026Q1

Token-level defect feedback and alternating optimization for coupled code generation and defect detection with large language models

Wenzeng Shan

Short summary

A novel coupled optimization framework for large language models (LLMs) simultaneously generates code and detects defects, reducing the defect rate of test-passing Python/C code from 0.216 to 0.128 (a 41% reduction) and improving pass@10 from 0.724 to 0.761.

AI-generated from the title and abstract; the full text is not read.

Key points

  • Coupled optimization framework integrates LLM code generation and defect detection.
  • Detector's token-level risk estimates reweight generator loss, improving code quality.
  • Defect rate of test-passing Python/C code reduced from 0.216 ± 0.008 to 0.128 ± 0.008.
  • Pass@10 metric improved from 0.724 ± 0.008 to 0.761 ± 0.008.
  • Token-level blame assignment identified as the primary contributor to defect rate reduction.

AI-generated from the title and abstract; the full text is not read.

Abstract

Abstract Large language models write code fluently, yet the programs they produce carry defect rates that ordinary functional evaluation seldom exposes, and detection systems that could catch these faults act too late to shape the generation that created them. This paper argues that generation and detection should be optimized together rather than in sequence, and it makes that argument concrete through one specific coupling: the detector’s node-level risk estimates are mapped back onto decoder positions and used to reweight the generation loss token by token, while a composite reward built from test outcomes and defect probability supplies a second, sampled gradient. Generator and detector are updated in alternation under a bounded schedule; failed candidates re-enter the detector’s training stream, and twelve mutation operators widen its exposure to underrepresented fault families. Using Qwen2.5-Coder-7B-Instruct as the generator and a gated graph neural network as the detector, and averaging five independent seeds, the coupled method lowered the defect rate of test-passing code from 0.216 ± 0.008 to 0.128 ± 0.008 while raising pass@10 from 0.724 ± 0.008 to 0.761 ± 0.008. Every defect rate reported here is scored by a reference detector frozen outside the loop, so the improvement cannot be an artefact of a critic grading its own pupil. Detection F1 rose from 0.627 ± 0.011 to 0.681 ± 0.011, although that gain confounds the coupling with the larger training stream the coupled detector receives. Ablation isolates token-level blame assignment as the component doing most of the work, and a controlled error-injection study quantifies how far detector mistakes propagate into generation. The evidence is confined to function-level Python and C, and concurrency faults remain resistant, so the claims made here are deliberately bounded to that setting; code, configurations and per-seed records accompany the submission so the boundary can be tested directly.

The authors' abstract, as published at the source. Scientific Reports, 2026 · DOI ↗

TakeawaysIn the app
Ask the paperIn the app

The rest is in the Pofolia app

Takeaways and questions to the paper; new summaries every day for your field. Free.

Sign in on the web to open

Field: Software

SoftwareComputer Science