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

PanGu-Coder: Program Synthesis with Function-Level Language Modeling

Fenia Christopoulou, Gerasimos Lampouras, Milan Gritta, Guchun Zhang, Yinpeng Guo, Zhongqi Li, Qi Zhang, Meng Xiao, Bo Shen, Lin Li, Hao Yu, Li Yan, Pingyi Zhou, Xin Wang, Yuchi Ma, Ignacio Iacobacci, Yasheng Wang, Guangtai Liang, Jiansheng Wei, Xin Jiang, Qianxiang Wang, Qun Liu · DOI

TL;DR

This paper introduces PanGu-Coder, a new decoder-only language model for text-to-code generation. It achieves competitive performance with models like CodeX, even when trained on less data and with a smaller context window, by employing a novel two-stage training strategy that focuses on function-level language modeling.

What Problem Does This Paper Address?

The paper tackles the challenge of automatically generating functional code from natural language descriptions, a task known as text-to-code generation or program synthesis. While many large language models have shown promise in this area, achieving high functional correctness remains difficult. Existing models often require vast amounts of training data and large context windows, and there's a need for models that can efficiently learn to generate correct code, especially for complex programming tasks.

Methods

PanGu-Coder builds upon the Pangu-α architecture, a decoder-only transformer. Its training involves a two-stage approach:

  • Stage 1: Causal Language Modeling (CLM) on Raw Code: The model is pre-trained on a large corpus of raw programming language data (Python in this case). This stage helps the model learn general code structures and syntax by predicting the next token in a sequence. Natural language elements like docstrings are incorporated where available.
  • Stage 2: Task-Focused Training: This stage refines the model for text-to-code generation. It uses a combination of CLM and Masked Language Modeling (MLM) objectives, specifically focusing on pairs of natural language problem descriptions (docstrings) and their corresponding code functions. This stage aims to bridge the gap between understanding the problem description and generating the correct code.

Additionally, the paper introduces PanGu-Coder-FT, which is fine-tuned on competitive programming problems and continuous integration test data, further specializing the model for accurate code generation.

Datasets

  • Training Data:
    • Large corpus of Python code (from GitHub) for Stage 1 pre-training.
  • Loosely curated pairs of natural language problem descriptions (docstrings) and code functions for Stage 2 training.
  • Competitive programming datasets (APPS, Code Contests) and continuous integration (CI) data for fine-tuning (PanGu-Coder-FT).
  • Evaluation Datasets:
    • HumanEval: A benchmark of 164 handcrafted Python problems with unit tests for evaluating functional correctness.
  • Mostly Basic Programming Problems (MBPP): A dataset of 974 programming problems designed for entry-level programmers.

Key Insights and Ideas

  • Function-Level Modeling is Key: The paper emphasizes that focusing on function-level language modeling, by treating docstrings and code bodies as distinct but related sequences, is crucial for effective text-to-code generation.
  • Two-Stage Training Efficiency: The two-stage training strategy allows the model to first learn general code patterns and then specialize in translating natural language descriptions to code, achieving good performance with less data than some prior models.
  • Docstring-Code Synergy: While incorporating docstring information is beneficial, the paper suggests that solely optimizing for docstring understanding in Stage 2 might not be optimal. A balanced approach, or focusing primarily on code generation objectives, seems to yield better results.
  • Fine-tuning for Domain Adaptation: Fine-tuning on data closer to the target distribution (like competitive programming problems) significantly boosts performance, highlighting the model's sensitivity to data domain.
  • Data Similarity for Efficient Fine-tuning: Using data similarity to a few-shot sample can help select a more effective subset of fine-tuning data, reducing computational costs while maintaining or even improving performance.

Key Results

  • PanGu-Coder (317M and 2.6B parameter versions) achieves competitive or better performance than similarly sized models like CodeX on the HumanEval and MBPP datasets.
  • The 317M PanGu-Coder model achieves 17.07% pass@1 on HumanEval, outperforming models like GPT-NEO and CODEGEN-MULTI of similar sizes.
  • The 2.6B PanGu-Coder model achieves 23.78% pass@1 on HumanEval, competitive with larger models like CODEGEN-MONO.
  • PanGu-Coder-FT shows significant improvements, with pass@1 on MBPP increasing from 16.20% to 24.60% after fine-tuning.
  • The model demonstrates that it can achieve strong results with a smaller context window (1024 tokens) and less training data compared to some state-of-the-art models.

Limitations and Future Work

  • Context Window Limitation: The paper speculates that the smaller context window might be a reason for performance gaps on tasks requiring long solutions or attending to extensive descriptions, suggesting future work could explore larger context windows.
  • Data Sensitivity: PanGu-Coder-FT is sensitive to fine-tuning data distribution, indicating that careful data curation or selection methods (like similarity-based selection) are important for optimal performance.
  • Further Exploration of Objectives: The paper suggests that exploring how to best simultaneously encode natural language and programming language remains an interesting direction for future research.
  • Cross-Lingual and Multi-Language Capabilities: While Pangu-α was designed for both English and Chinese, PanGu-Coder currently focuses on English and Python. Extending to other languages is a natural future step.

Summary updated

BibTeX
@misc{christopoulou2022pangu,
  author = {Fenia Christopoulou and Gerasimos Lampouras and Milan Gritta and Guchun Zhang and Yinpeng Guo and Zhongqi Li and Qi Zhang and Meng Xiao and Bo Shen and Lin Li and Hao Yu and Li Yan and Pingyi Zhou and Xin Wang and Yuchi Ma and Ignacio Iacobacci and Yasheng Wang and Guangtai Liang and Jiansheng Wei and Xin Jiang and Qianxiang Wang and Qun Liu},
  title = {{PanGu-Coder: Program Synthesis with Function-Level Language Modeling}},
  year = {2022},
  eprint = {2207.11280},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2207.11280},
}
Figure