Skip to main content
QUICK REVIEW

[Paper Review] CERT: Continual Pre-Training on Sketches for Library-Oriented Code Generation

Daoguang Zan, Bei Chen|arXiv (Cornell University)|Jun 14, 2022
Software Engineering ResearchComputer Science9 citations
TL;DR

This paper proposes CERT, a continual pre-training framework that leverages code sketches to improve library-oriented code generation. By training a sketcher to predict structural templates and a generator to fill in details—both continually pre-trained on unlabelled code—CERT achieves a 15.67% absolute pass@1 improvement over the base model on the PandasEval benchmark, demonstrating strong performance without requiring expensive text-code paired data.

ABSTRACT

Code generation is a longstanding challenge, aiming to generate a code snippet based on a natural language description. Usually, expensive text-code paired data is essential for training a code generation model. Recently, thanks to the success of pre-training techniques, large language models are trained on large-scale unlabelled code corpora and perform well in code generation. In this paper, we investigate how to leverage an unlabelled code corpus to train a model for library-oriented code generation. Since it is a common practice for programmers to reuse third-party libraries, in which case the text-code paired data are harder to obtain due to the huge number of libraries. We observe that library-oriented code snippets are more likely to share similar code sketches. Hence, we present CERT with two steps: a sketcher generates the sketch, then a generator fills the details in the sketch. Both the sketcher and the generator are continually pre-trained upon a base model using unlabelled data. Furthermore, we craft two benchmarks named PandasEval and NumpyEval to evaluate library-oriented code generation. Experimental results demonstrate the impressive performance of CERT. For example, it surpasses the base model by an absolute 15.67% improvement in terms of pass@1 on PandasEval. Our work is available at https://github.com/microsoft/PyCodeGPT.

Motivation & Objective

  • To address the challenge of generating library-oriented code snippets without relying on costly text-code paired datasets.
  • To explore whether code sketches—abstracted structures omitting user-defined terms—can serve as effective supervision signals in continual pre-training for code generation.
  • To improve code generation performance for popular libraries like Pandas and NumPy using unlabelled code corpora.
  • To develop dedicated benchmarks, PandasEval and NumpyEval, to evaluate library-specific code generation capabilities.

Proposed method

  • A sketcher is trained to predict code sketches by anonymizing user-defined terms (e.g., variable names, constants) from code snippets.
  • A generator is trained to produce full code by conditioning on the predicted sketch, using the sketch as a structural prompt.
  • Both the sketcher and generator are continually pre-trained on a large-scale unlabelled code corpus, without requiring any text-code paired data.
  • The method leverages a base code language model (PyCodeGPT) as the foundation, fine-tuned through continual pre-training on library-specific code files.
  • The approach is evaluated using two new benchmarks: PandasEval and NumpyEval, each containing 101 library-specific programming problems in Python.
  • A variant, CERTg, is also trained on the full code corpus to evaluate generalization, showing that sketch-based pre-training is particularly effective for library-oriented tasks.

Experimental results

Research questions

  • RQ1Can code sketches serve as effective supervision signals for continual pre-training in the absence of text-code paired data?
  • RQ2Does decomposing code generation into sketch prediction and detail filling improve performance on library-oriented code generation tasks?
  • RQ3How does CERT compare to strong baselines like Codex and GPT-3 on library-specific code generation benchmarks?
  • RQ4Is the sketch-based approach generalizable to general code generation, or is it specifically beneficial for library-oriented code?

Key findings

  • CERT achieves a 15.67% absolute improvement in pass@1 on the PandasEval benchmark compared to the base model, demonstrating significant gains in library-oriented code generation.
  • The sketcher and generator components work synergistically, with the generator able to correct imperfect sketch predictions, showing robustness to sketch errors.
  • CERT outperforms GPT-3 and Codex on the PandasEval and NumpyEval benchmarks despite having only 110 million parameters, indicating strong sample efficiency.
  • The variant CERTg, trained on the full code corpus, performs similarly to the base model on HumanEval, confirming that sketch-based pre-training is most effective for library-specific tasks.
  • The ablation study confirms that extracting library-oriented code files is essential for CERT’s performance, as CERTg underperforms CERT on library-specific benchmarks.
  • Case studies show that the sketcher can generate correct structural templates even without user-defined terms, and the generator can recover from incorrect sketches, highlighting the framework’s resilience.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.