NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

SemCoder: Training Code Language Models with Comprehensive Semantics Reasoning

Yangruibo Ding, Jinjun Peng, Marcus J. Min, Gail Kaiser, Junfeng Yang, Baishakhi Ray

Most developers are familiar with "rubber-duck debugging"—the practice of explaining your code line-by-line to an inanimate object to find bugs. It turns out this technique is just as effective for Artificial Intelligence. In their recent paper, SemCoder: Training Code Language Models with Comprehensive Semantics Reasoning, researchers introduce a novel training strategy that teaches models to "think out loud" about code execution.

TL;DR

SemCoder is a 6.7B parameter Code Large Language Model (Code LLM) that bridges the gap between static code text and dynamic execution behavior using monologue reasoning. By training the model to verbally simulate execution and reason about program constraints, it achieves state-of-the-art performance, outperforming much larger models like GPT-3.5-Turbo on both code generation and execution reasoning tasks.

The Problem: Syntax Without Semantics

While modern Code LLMs excel at code completion, they often lack a deep understanding of program semantics—what the code actually does when it runs. Most models are trained on static source code, which helps them learn syntax but leaves them blind to dynamic states, execution effects, and complex debugging scenarios.

When a model doesn't understand execution, it struggles to repair its own errors or reason about how a specific input will transform into an output. Existing attempts to fix this, like "scratchpads" (where models write out variable states), often provide redundant, hard-to-parse information that doesn't capture the underlying causal logic of a program.

Methods: Monologue Reasoning

The core innovation of SemCoder is Monologue Reasoning. Instead of just training on raw code, the authors train SemCoder to generate natural language explanations across four distinct semantic modalities:

  1. Approximate Semantics: High-level functional descriptions detailing the overall goal of the code.
  2. Symbolic Semantics: The direct relationship between the code's structure and its logic.
  3. Abstract Semantics: Reasoning about key properties and constraints, such as how inputs relate to outputs.
  4. Operational Semantics: A step-by-step verbal simulation of execution. Given code and an input, the model explains how each line affects variables and control flow to reach the final output.
SemCoder's training strategy across different semantic modalities.

By training on these monologues, SemCoder learns to link static code text with dynamic execution states. The model was initialized from DeepSeekCoder-6.7B and fine-tuned using a combination of standard code generation and these reasoning tasks.

Datasets

The researchers curated two primary datasets to support this training:

  • PyX: A synthetic dataset of 32,489 clean, fully executable Python samples. Unlike previous datasets, every sample in PyX is verified to run correctly and is paired with functional descriptions, unit tests, and execution monologues.
  • PyX-R: A specialized debugging dataset containing 18,473 samples of buggy code, human-like debugging rationales (the "monologues"), and the resulting corrected patches.

Key Insights

  • Natural Language > Structured Traces: The authors found that "monologue-style" reasoning is more effective than concrete "scratchpads." Natural language allows the model to focus on why a state changed, capturing causal relations that numeric traces miss.
  • Static Reasoning for Dynamic Problems: SemCoder can perform effective debugging and execution reasoning purely through "mental simulation" (static reasoning) without needing a real-time execution environment at inference time.
  • The Power of Bi-directional Reasoning: Training on both forward (input-to-output) and backward (output-to-input) monologues forces the model to understand abstract constraints and invariants, making it more robust to complex operations.

Key Results

Despite having only 6.7B parameters, SemCoder variants consistently outperformed larger open-source models and even closed-source giants like GPT-3.5-Turbo.

  • Code Generation: SemCoder-S achieved 79.3% on HumanEval, surpassing GPT-3.5-Turbo's 76.8%.
  • Execution Reasoning: On the CRUXEval-I benchmark (predicting input), SemCoder-S scored 63.6%, a massive jump over GPT-3.5-Turbo's 50.3%.
  • Self-Refinement: The model demonstrated a strong ability to "rubber-duck" its own errors, identifying root causes of bugs and fixing them iteratively.
Overall performance of SemCoder compared to baseline models across generation and reasoning tasks.

Limitations and Future Work

The authors acknowledge a few key limitations:

  • Flawed Intermediate Steps: While the final answers are often correct, the intermediate reasoning monologues can occasionally contain logical flaws or incorrect assumptions about code properties.
  • Teacher Model Reliance: The training monologues were generated using "teacher" models (GPT-3.5 and GPT-4o-mini). Future work could explore using the model's own successful executions to bootstrap higher-quality reasoning data.
  • Scaling: The current work focuses on a 6.7B parameter base. Testing this semantic-oriented training on much larger models (e.g., 33B+ or 70B+) remains an open area for exploration.

For those interested in the implementation, the data, code, and models are available on the ARiSE-Lab GitHub.

Summary updated

BibTeX
@inproceedings{ding2024semcoder,
  author = {Yangruibo Ding and Jinjun Peng and Marcus J. Min and Gail Kaiser and Junfeng Yang and Baishakhi Ray},
  title = {{SemCoder: Training Code Language Models with Comprehensive Semantics Reasoning}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=PnlCHQrM69},
}
Figure