Lune

ICSE2023Top-tier venue

SkCoder: A Sketch-based Approach for Automatic Code Generation

Jia Li, Yongmin Li, Ge Li, Zhi Jin, Yiyang Hao, Xing Hu

Abstract

Recently, deep learning techniques have shown great success in automatic code generation. Inspired by the code reuse, some researchers propose copy-based 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 code sketch. The sketch is further edited to the desired code. However, existing copy-based 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-based 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 -CodeT5base by 30.30%, 35.39%, and 29.62% 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.

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

23 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
  • CodeGen4Libs: A Two-Stage Approach for Library-Oriented Code Generation cites CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation
  • CodeGen4Libs: A Two-Stage Approach for Library-Oriented Code Generation cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
  • CodeGen4Libs: A Two-Stage Approach for Library-Oriented Code Generation cites ReACC: A Retrieval-Augmented Code Completion Framework
  • ReACC: A Retrieval-Augmented Code Completion Framework cites CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation
  • ReACC: A Retrieval-Augmented Code Completion Framework cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
  • ReACC: A Retrieval-Augmented Code Completion Framework cites GraphCodeBERT: Pre-training Code Representations with Data Flow
  • ReACC: A Retrieval-Augmented Code Completion Framework cites Language Models are Few-Shot Learners
  • Self-Edit: Fault-Aware Code Editor for Code Generation cites Language Models are Few-Shot Learners
  • Out of Sight, Out of Mind: Better Automatic Vulnerability Repair by Broadening Input Ranges and Sources cites CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation
  • Out of Sight, Out of Mind: Better Automatic Vulnerability Repair by Broadening Input Ranges and Sources cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
  • Out of Sight, Out of Mind: Better Automatic Vulnerability Repair by Broadening Input Ranges and Sources cites GraphCodeBERT: Pre-training Code Representations with Data Flow
  • Out of Sight, Out of Mind: Better Automatic Vulnerability Repair by Broadening Input Ranges and Sources cites Language Models are Few-Shot Learners
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers23

  1. Exploring and Unleashing the Power of Large Language Models in Automated Code TranslationZhen Yang, Fang Liu, Zhongxing Yu, Jacky Wai Keung et al.FSE 2024 · 72 citations
  2. Hot or Cold? Adaptive Temperature Sampling for Code Generation with Large Language ModelsYuqi Zhu, Jia Li, Ge Li, Yunfei Zhao et al.AAAI 2024 · 68 citations
  3. Self-Edit: Fault-Aware Code Editor for Code GenerationKechi Zhang, Zhuo Li, Jia Li, Ge Li et al.ACL 2023 · 42 citations
  4. Out of Sight, Out of Mind: Better Automatic Vulnerability Repair by Broadening Input Ranges and SourcesXin Zhou, Kisub Kim, Bowen Xu, DongGyun Han et al.ICSE 2024 · 32 citations
  5. CodeGen4Libs: A Two-Stage Approach for Library-Oriented Code GenerationMingwei Liu, Tianyong Yang, Yiling Lou, Xueying Du et al.ASE 2023 · 31 citations

Builds on9

  1. Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 citations
  2. CodeBERT: A Pre-Trained Model for Programming and Natural LanguagesZhangyin Feng, Daya Guo, Duyu Tang, Nan Duan et al.EMNLP Findings 2020 · 2,828 citations
  3. GraphCodeBERT: Pre-training Code Representations with Data FlowDaya Guo, Shuo Ren, Shuai Lu, Zhangyin Feng et al.ICLR 2021 · 1,644 citations
  4. CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and GenerationYue Wang, Weishi Wang, Shafiq R. Joty, Steven C. H. HoiEMNLP 2021 · 1,224 citations
  5. ReACC: A Retrieval-Augmented Code Completion FrameworkShuai Lu, Nan Duan, Hojae Han, Daya Guo et al.ACL 2022 · 208 citations

Related papers

  1. Source Code Recommender Systems: The Practitioners' PerspectiveMatteo Ciniselli, Luca Pascarella, Emad Aghajani, Simone Scalabrino et al.ICSE 2023 · 6 citations
  2. Compilable Neural Code Generation with Compiler FeedbackXin Wang, Yasheng Wang, Yao Wan, Fei Mi et al.ACL Findings 2022 · 46 citations
  3. Retrieve and Refine: Exemplar-based Neural Comment GenerationBolin Wei, Yongmin Li, Ge Li, Xin Xia et al.ASE 2020 · 68 citations
  4. Improving Code Extraction from Coding Screencasts Using a Code-Aware Encoder-Decoder ModelAbdulkarim Malkadi, Ahmad Tayeb, Sonia HaiducASE 2023 · 5 citations
  5. Code Search is All You Need? Improving Code Suggestions with Code SearchJunkai Chen, Xing Hu, Zhenhao Li, Cuiyun Gao et al.ICSE 2024 · 31 citations
Dusk over the sea between two cliffs drawn in fine vertical lines