Reproduce “SemGuard: Real-Time Semantic Evaluator for Correcting LLM-Generated Code” on OpenResearch

Run Claude Code, Codex or any coding agent as a research agent: literature, hypotheses and experiments on your laptop, cluster or cloud GPUs.

Universal app for Apple silicon and Intel. Requires macOS 11 or later.

About this paper

Qinglin Wang, Zhihong Sun, Ruyun Wang, Tao Huang, Zhi Jin, Ge Li, Chen Lyu

Researchers at Shandong Normal University, the Chinese Academy of Sciences, and Peking University developed SemGuard, a real-time semantic evaluator that corrects Large Language Model-generated code at the line level during the decoding process. This system, which employs a fine-tuned lightweight LLM and a targeted token-penalty scheme, achieves higher code correctness (e.g., up to 38.34% Pass@1) while reducing inference time by 60% and token usage by 31% compared to baselines like ROCODE, on Python and Java benchmarks.

Key insights

  • Real-time, line-level semantic supervision during code generation is highly effective in proactively preventing and correcting semantic errors before they propagate through the generated code.
  • Precise identification of the semantic deviation point, coupled with a targeted token-penalty, significantly improves correction efficiency and accuracy compared to coarser or more heuristic-driven rollback strategies.
  • A dedicated, lightweight semantic evaluator, trained on fine-grained deviation data like SemDiff, can provide robust semantic discrimination with low latency, proving more effective than relying solely on the LLM's internal uncertainty signals.

Summary by alphaXiv.

Tip: change arxiv.org to autoarxiv.org in any arXiv abstract link to open the paper here.