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

SemCoder: Training Code Language Models with Comprehensive Semantics

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

TL;DR

This paper introduces SEMCODER, a novel approach to training code language models (Code LLMs) that goes beyond static code analysis to incorporate a deeper understanding of program semantics. By training models to "reason" about code execution through a "monologue" process, SEMCODER significantly improves performance on complex tasks like code generation, execution reasoning, and debugging, even with a smaller model size.

What Problem Does This Paper Address?

Current Code LLMs, while adept at tasks like code completion, often struggle with understanding the deeper semantic implications of code, such as execution effects and dynamic states. This limitation hinders their ability to perform complex tasks like debugging and program repair effectively. The core challenge is bridging the gap between the static nature of code text that LLMs are trained on and the dynamic, semantic-rich behavior of programs during execution. Existing methods often rely on static analysis or simple execution traces, which don't fully capture the nuanced reasoning humans employ when debugging.

Methods

The paper introduces monologue reasoning as a novel training strategy for Code LLMs. This approach trains models to understand and explain code semantics to themselves, mimicking human "rubber-duck debugging." SEMCODER is trained to:

  • Summarize high-level functional descriptions: Understanding the overall purpose of the code.
  • Identify key properties and constraints: Grasping what should hold true for the program regardless of input.
  • Articulate operational semantics: Explaining step-by-step how individual code statements affect program state and behavior.

This is achieved through two types of monologues:

  • Forward Monologue: Simulating execution step-by-step from input to output, explaining state changes and predicting the final result.
  • Backward Monologue: Reasoning from the output to infer possible previous states, using abstract intermediate constraints to handle non-deterministic scenarios.

SEMCODER is trained on a multi-modal dataset that includes these monologues alongside code and functional descriptions.

Datasets

  • PYX: A newly curated dataset of fully executable Python code samples with functional descriptions and execution traces. This dataset was synthesized to ensure high-quality, executable code, addressing limitations of existing datasets.
  • PYX-R: A subset of PYX specifically designed for debugging and self-refinement, containing buggy code snippets, debugging rationales, and refinement plans.

The paper also uses existing benchmarks for evaluation:

  • EvalPlus and LiveCodeBench-Lite for code generation.
  • CRUXEval and LiveCodeBench-Exec for execution reasoning.

Key Insights and Ideas

  • Monologue Reasoning is Key: The core insight is that training LLMs to "talk through" code execution, much like humans do when debugging, significantly enhances their semantic understanding and reasoning capabilities. This goes beyond simply processing execution traces.
  • Static Reasoning for Dynamic Tasks: SEMCODER's monologue reasoning is purely static, meaning it doesn't require actual dynamic tracing. This is a significant advantage, making it more flexible and efficient.
  • Abstract Semantics Matter: The ability to reason about abstract intermediate constraints in backward monologues is crucial for handling complex operations and improving generalization.
  • Smaller Models Can Excel: SEMCODER, with only 6.7B parameters, demonstrates performance competitive with or exceeding much larger models, highlighting the effectiveness of its semantic-aware training.

Key Results

  • Code Generation: SEMCODER-S achieves 79.3% on HumanEval (GPT-3.5-turbo: 76.8%) and 63.6% on CRUXEval-I (GPT-3.5-turbo: 50.3%).
  • Execution Reasoning: SEMCODER-S achieves 63.9% on CRUXEval-O (GPT-3.5-turbo: 59.0%).
  • Debugging and Self-Refinement: SEMCODER-S outperforms baseline models in zero-shot debugging and self-refinement tasks.
  • Monologue vs. Traces: Monologue reasoning is shown to be comparably effective as attaching real execution traces for debugging, with added benefits of being static and more human-readable.

Limitations and Future Work

  • Intermediate Reasoning Flaws: While final answers are often correct, the intermediate reasoning steps in monologues can occasionally be flawed. This suggests a need for more robust process supervision for code reasoning.
  • LLM Reliance for Annotation: The monologue annotation process relies on powerful LLMs (GPT-3.5-Turbo/GPT-40-mini), which might limit scalability for smaller models. Future work could explore bootstrapping monologue generation with the base model itself.
  • Direct Integration with Code Generation: While execution reasoning indirectly benefits code generation, future work could explore directly integrating a model's own execution reasoning ability to assist its code generation and self-refinement process.
  • Larger Models: Exploring this semantic-oriented training on larger base models could further enhance capabilities.

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}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=PnlCHQrM69},
}
Figure