SkCoder: A Sketch-based Approach for Automatic Code Generation
Recently, deep learning techniques have shown great success in automatic code generation. Inspired by the code reuse, some researchers propose copy-oriented approaches that can copy the content from similar code snippets to obtain better performance. Practically, human developers recognize the content in the similar code that is relevant to their needs, which can be viewed as a \textit{code sketch}. The sketch is further edited to the desired code. However, existing copy-oriented approaches ignore the code sketches and tend to repeat the similar code without necessary modifications, which leads to generating wrong results.
In this paper, we propose a sketch-oriented code generation approach named SkCoder to mimic developers’ code reuse behavior. Given a natural language requirement, SkCoder retrieves a similar code snippet, extracts relevant parts as a code sketch, and edits the sketch into the desired code. Our motivations are that the extracted sketch provides a well-formed pattern for telling models ‘‘how to write’’. The post-editing further adds requirement-specific details into the sketch and outputs the complete code. We conduct experiments on two public datasets and a new dataset collected by this work. We compare our approach to 20 baselines using 5 widely used metrics. Experimental results show that (1) SkCoder can generate more correct programs, and outperforms the state-of-the-art - CodeT5-base by 30.30%, 35.39%, and 22.29% on three datasets. (2) Our approach is effective to multiple code generation models and improves them by up to 120.1% in Pass@1. (3) We investigate three plausible code sketches and discuss the importance of sketches. (4) We manually evaluate the generated code and prove the superiority of our SkCoder in three aspects.
Fri 19 MayDisplayed time zone: Hobart change
13:45 - 15:15 | Code generationJournal-First Papers / Technical Track at Meeting Room 101 Chair(s): Iftekhar Ahmed University of California at Irvine | ||
13:45 15mTalk | Learning Deep Semantics for Test Completion Technical Track Pengyu Nie University of Texas at Austin, Rahul Banerjee The University of Texas at Austin, Junyi Jessy Li University of Texas at Austin, USA, Raymond Mooney The University of Texas at Austin, Milos Gligoric University of Texas at Austin | ||
14:00 15mTalk | Dynamic Human-in-the-Loop Assertion Generation Journal-First Papers Lucas Zamprogno University of British Columbia, Braxton Hall University of British Columbia, Reid Holmes University of British Columbia, Joanne M. Atlee University of Waterloo | ||
14:15 15mTalk | SkCoder: A Sketch-based Approach for Automatic Code Generation Technical Track Jia Li Peking University, Yongmin Li Peking University, Ge Li Peking University, Zhi Jin Peking University, Xing Hu Zhejiang University Pre-print | ||
14:30 15mTalk | An Empirical Comparison of Pre-Trained Models of Source Code Technical Track Changan Niu Software Institute, Nanjing University, Chuanyi Li Nanjing University, Vincent Ng Human Language Technology Research Institute, University of Texas at Dallas, Richardson, TX 75083-0688, Dongxiao Chen Software Institute, Nanjing University, Jidong Ge Nanjing University, Bin Luo Nanjing University Pre-print | ||
14:45 15mTalk | On the Robustness of Code Generation Techniques: An Empirical Study on GitHub Copilot Technical Track Antonio Mastropaolo Università della Svizzera italiana, Luca Pascarella ETH Zurich, Emanuela Guglielmi University of Molise, Matteo Ciniselli Università della Svizzera Italiana, Simone Scalabrino University of Molise, Rocco Oliveto University of Molise, Gabriele Bavota Software Institute, USI Università della Svizzera italiana | ||
15:00 15mTalk | Source Code Recommender Systems: The Practitioners' Perspective Technical Track Matteo Ciniselli Università della Svizzera Italiana, Luca Pascarella ETH Zurich, Emad Aghajani Software Institute, USI Università della Svizzera italiana, Simone Scalabrino University of Molise, Rocco Oliveto University of Molise, Gabriele Bavota Software Institute, USI Università della Svizzera italiana |