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

Case2Code: Scalable Synthetic Data for Code Generation

Yunfan Shao, Linyang Li, Yichuan Ma, Peiji Li, Demin Song, Qinyuan Cheng, Shimin Li, Xiaonan Li, Pengyu Wang, Qipeng Guo, Hang Yan, Xipeng Qiu, Xuanjing Huang, Dahua Lin

Abstract

Large Language Models (LLMs) have shown outstanding breakthroughs in code generation. Recent work improves code LLMs by training on synthetic data generated by powerful teacher models, which can be challenging to scale due to high costs and dependence on proprietary models. In this paper, we propose Case2Code, an inductive inference task that aims to infer underlying code implementations by observing input-output examples or program behaviors. By incorporating LLMs to generate program inputs and executing the program with a code interpreter to obtain ground-truth outputs, we can synthesize diverse and high-quality data at scale. Experimental results show that case-to-code induction is challenging for current representative LLMs. However, models trained with Case2Code improve performance not only on inductive tasks but also on various general code-generation benchmarks, demonstrating the significant potential of large-scale synthetic data and inductive learning.

Introduction

While Large Language Models (LLMs) have become proficient at generating code from natural language instructions (deductive reasoning), they often struggle with inductive reasoning—the ability to infer underlying logic from specific examples. Most existing code datasets focus on direct instruction following or code explanation, leaving a gap in tasks where the model must observe program behaviors to understand its implementation.

Furthermore, current methods for generating synthetic code data typically rely on "distillation," where a massive teacher model (like GPT-4) generates instructions and solutions for a smaller student. This approach is expensive, difficult to scale, and limited by the teacher's own biases or errors. Case2Code addresses these issues by leveraging real-world code and automated execution to create high-quality training data at scale without being tethered to a high-cost teacher model.

Methodology

The researchers proposed the Case2Code task: given a set of input-output pairs, the model must implement the function that produced them. For example, instead of being asked to explain a function like def func(a): return a + 5, the model is given examples like func(1) == 6 and func(2) == 7 and must infer the underlying logic. To create a massive dataset for this task, they developed a four-stage pipeline:

  1. Function Collection: 2.3 million Python functions were sampled from "The Stack," filtered for high-quality, self-contained code that passes syntax checks.
  2. I/O Generation: Instead of asking an LLM to write the whole task, a smaller LLM (e.g., InternLM2-7B) is used simply to generate 10 diverse input arguments for each function.
  3. Execution (The Ground Truth): The collected functions are run with the generated inputs using a code interpreter. This ensures the outputs are 100% correct according to the actual code logic, removing the need for a "perfect" teacher model.
  4. Data Synthesis: The resulting triples (Function, Inputs, Outputs) are converted into training prompts where the model sees the I/O pairs and must reconstruct the function.
The Case2Code synthetic framework pipeline

Experimental Setup

The framework was evaluated using a training set of 1.3 million high-quality Python functions derived from The Stack. Performance was measured on standard code generation benchmarks, including HumanEval/HumanEval+ and MBPP/MBPP+. Additionally, the authors introduced a new Case2Code Test Set of 500 samples specifically designed to test inductive reasoning, featuring complex cases generated by GPT-4 to ensure a strict evaluation.

Key Results

The Case2Code task proved to be a significant challenge for existing models. As shown in the performance table below, even GPT-4 only achieves 43.6% accuracy on the Case2Code test set, while smaller base models like LLaMA2-7B score near zero.

Zero-shot performance of representative LLMs on Case2Code and standard benchmarks

However, training on Case2Code data yielded impressive gains in general programming ability:

  • Generalization: An InternLM2-7B model trained with Case2Code saw its HumanEval score jump from 39.0% to 64.6% when combined with standard instruction tuning.
  • Efficiency: While using a massive model like LLaMA3-70B for input generation provided slightly better data quality, using the smaller InternLM2-7B was 4.5x more cost-effective while still providing substantial performance boosts.

Discussion and Insights

  • Inductive Learning as a "Hidden" Skill: The paper argues that learning to map inputs to outputs forces a model to understand the execution state and logic flow of code more deeply than just following a text description.
  • The Power of the Interpreter: By using a code interpreter to generate outputs, the framework achieves a "weak-to-strong" learning effect. A weak model can suggest inputs, but the execution provides the "gold standard" supervision.
  • Prompt Diversity Matters: The researchers found that using a variety of natural language templates to frame the Case2Code task was essential for the model to generalize its reasoning to other types of coding tasks.

Conclusion and Future Work

Case2Code demonstrates a scalable path for improving code LLMs through inductive learning. While the current study is limited to Python, the framework is naturally extendable to other languages like C++, Java, or Rust. Future work will focus on more robust, isolated execution environments to handle arbitrary code safely and exploring multi-modal inductive reasoning for programs dealing with non-textual data like images or audio.

Summary updated

BibTeX
@inproceedings{shao2025case,
  author = {Yunfan Shao and Linyang Li and Yichuan Ma and Peiji Li and Demin Song and Qinyuan Cheng and Shimin Li and Xiaonan Li and Pengyu Wang and Qipeng Guo and Hang Yan and Xipeng Qiu and Xuanjing Huang and Dahua Lin},
  title = {{Case2Code: Scalable Synthetic Data for Code Generation}},
  booktitle = {International Conference on Computational Linguistics},
  year = {2025},
  url = {https://openreview.net/forum?id=prVTuZhYu9},
}
Figure