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

CodeS: Natural Language to Code Repository via Multi-Layer Sketch

Daoguang Zan, Ailun Yu, Wei Liu, Dong Chen, Bo Shen, Wei Li, Yafen Yao, Yongshun Gong, Xiaolin Chen, Bei Guan, Zhiguang Yang, Yongji Wang, Qianxiang Wang, Lizhen CuiACM Transactions on Software Engineering and Methodology 2024

TL;DR

This paper introduces "NL2Repo," a new task for automatically generating entire code repositories from natural language requirements. They propose CODES, a framework that breaks this down into three stages: sketching the repository structure, then individual files, and finally filling in function bodies. CODES significantly outperforms existing methods and demonstrates practical utility through a VSCode plugin.

What Problem Does This Paper Address?

Large Language Models (LLMs) have shown impressive capabilities in generating code snippets (NL2Code). However, building a complete software project involves more than just generating individual functions. It requires creating a structured repository with a coherent directory layout, multiple interconnected files, and well-defined interfaces. Existing LLMs struggle with this complexity due to the inherent difficulty of generating structured, long-form code and the challenge of translating high-level, often lengthy, natural language requirements into a complete project. This gap between current NL2Code capabilities and the demands of full-fledged software development is what the NL2Repo task and the CODES framework aim to address.

Methods

The core of the CODES framework is its "multi-layer sketch" approach, which decomposes the NL2Repo task into three sequential stages:

  1. RepoSketcher: This module takes the natural language requirements (e.g., a README file) and generates a repository sketch. This sketch outlines the directory structure and lists the files within each directory.
  2. FileSketcher: For each file identified in the repository sketch, this module generates a "file sketch." This sketch includes the file's imports and function signatures but leaves the function bodies empty, often using a placeholder like "TODO."
  3. SketchFiller: This final module takes the file sketches and fills in the actual function bodies, completing the code for each function.

CODES can be implemented using two approaches: prompt engineering (leveraging existing LLMs with carefully crafted prompts) and supervised fine-tuning (SFT) on a custom dataset. The authors also developed a VSCode plugin to make CODES accessible to developers.

Datasets

The authors introduced a new benchmark called SketchEval for evaluating NL2Repo tasks. It consists of 19 real-world Python repositories of varying complexity (easy, medium, hard). They also created a new evaluation metric, SketchBLEU, which adapts the CodeBLEU metric to assess repository-level similarity by considering structural and semantic aspects. For supervised fine-tuning, they curated a dataset of 100 Python repositories, extracting instruction data for each of CODES's three modules.

Key Insights and Ideas

  • Decomposition is Key: The multi-layer sketch approach is crucial for tackling the complexity of generating entire code repositories. Breaking down the problem into structural (directory), file-level (sketch), and functional (body) stages significantly improves performance.
  • SFT Boosts Performance: Supervised fine-tuning on a curated dataset of repository components (README, repository sketch, file sketch, function body) leads to substantial performance gains over prompt engineering alone.
  • Instruction Format Matters: Specific elements within the prompts, like the "TODO" placeholder in function bodies and the inclusion of cross-file import information, are vital for guiding the LLM effectively. Removing these degrades performance, especially for complex tasks.
  • LLM Size and Data Scale: Larger base models generally yield better results. For SFT, there's a threshold for the number of training repositories (around 60) beyond which performance plateaus, suggesting a balance between data scale and computational cost.
  • Generalization Potential: CODES, particularly its RepoSketcher module, shows promising generalization capabilities to other programming languages (Java, C++, Go) even after being fine-tuned on Python data.

Key Results

  • CODES significantly outperforms baseline methods (like vanilla LLMs without sketching and agent-based approaches) on the SketchEval benchmark, achieving higher SketchBLEU scores, especially for medium and hard repositories.
  • Supervised fine-tuned versions of CODES consistently outperform their prompt-engineered counterparts, with improvements of up to 13.15% in SketchBLEU.
  • The VSCode plugin and empirical studies with 30 participants demonstrated the practical utility of CODES, with users finding it effective for accomplishing real-world projects.
  • CODES Extended (SFT) generated repositories with better code quality and fewer dependency-related errors compared to GitHub Copilot in user studies.

Limitations and Future Work

  • Repository Structure Hierarchy: The current CODES framework uses a three-layer sketch (directory, file, function). The authors acknowledge that real-world repository structures can be more intricate and suggest exploring more fine-grained sketching.
  • Invocation Relationships: Ensuring consistency and accuracy of invocation relationships between modules remains a challenge. Future work could involve program static analysis techniques like call graph analysis.
  • Long Context Limitations: Despite improvements, LLMs still face constraints with extremely large repositories. Future work might explore advanced summarization techniques or more efficient context management.
  • Cascading Errors: The multi-layer approach could be susceptible to cascading errors. Human intervention can mitigate this, but further research into error propagation and correction is needed.
  • Generalization to Other Languages/Tasks: While promising, generalization to other languages and more specialized programming tasks (e.g., web development, robotics) is an area for future exploration.
  • Product Design: The user study indicated that while CODES is effective, its VSCode plugin's product design could be improved to match commercial offerings like GitHub Copilot.

Summary updated

BibTeX
@misc{zan2024codes,
  author = {Daoguang Zan and Ailun Yu and Wei Liu and Dong Chen and Bo Shen and Wei Li and Yafen Yao and Yongshun Gong and Xiaolin Chen and Bei Guan and Zhiguang Yang and Yongji Wang and Qianxiang Wang and Lizhen Cui},
  title = {{CodeS: Natural Language to Code Repository via Multi-Layer Sketch}},
  year = {2024},
  eprint = {2403.16443},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2403.16443},
}
Figure