Cited by 64Software Engineering ResearchTopic ModelingTeaching and Learning Programming

SkCoder: A Sketch-based Approach for Automatic Code Generation

Open access
Li, Jia, Li, Yongmin, Li, Ge, Jin, Zhi, Hao, Yiyang, Hu, Xing·2023·2023 IEEE/ACM 45th International Conference on Software Engineering (ICSE)

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 Skcoderto mimic developers' code reuse behavior. Given a natural language requirement, Skcoderretrieves 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) Skcodercan generate more correct programs, and outperforms the state-of-the-art -CodeT5-base 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@l. (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 Skcoderin three aspects.

The claims and statistics of this paper haven’t been checked yet.

Run the check — free, no account needed. It reads the open-access text and checks the sources it cites.

A few free checks a day · papers already verified open instantly · results are public

Integrity signals

Registry

Crossref · 10.1109/icse48619.2023.00179

Cites

4 of 4 references verified0 citation errors · 0 not checkable

Statistics

Claims the paper makes

The claims and statistics of this paper haven’t been checked yet.

Run the check — free, no account needed. It reads the open-access text and checks the sources it cites.

A few free checks a day · papers already verified open instantly · results are public

Self-check

Percentages, sums and reported differences re-computed from the paper’s own numbers.

The self-check needs the paper’s full text.

Cites

Flagged first, then by citations

Research works printed but not linked: 36

  1. P. Yin and G. Neubig, "Tranx: A transition-based neural abstract syntax parser for semantic parsing and code generation," in Proceedings of the Conference on Empirical Methods in Natural Language Processing (Demo Track), 2018.
  2. Z. Sun, Q. Zhu, Y. Xiong, Y. Sun, L. Mou, and L. Zhang, "Treegen: A tree-based transformer architecture for code generation," in Proceedings of the AAAI Conference on Artificial Intelligence, vol. 34, no. 05, 2020, pp. 8984-8991.
  3. S. Haefliger, G. Von Krogh, and S. Spaeth, "Code reuse in open source software," Management science, vol. 54, no. 1, pp. 180-193, 2008.
  4. S. A. Hayati, R. Olivier, P. Avvaru, P. Yin, A. Tomasic, and G. Neubig, "Retrieval-based neural code generation," in Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing, 2018.
  5. T. B. Hashimoto, K. Guu, Y. Oren, and P. S. Liang, "A retrieve-and- edit framework for predicting structured outputs," Advances in Neural Information Processing Systems, vol. 31, 2018.
  6. M. R. Parvez, W. Ahmad, S. Chakraborty, B. Ray, and K.-W. Chang, "Retrieval augmented code generation and summarization," in Findings of the Association for Computational Linguistics: EMNLP 2021, 2021, pp. 2719-2734.
  7. A. Mockus, "Large-scale code reuse in open source software," in First International Workshop on Emerging Trends in FLOSS Research and Development (FLOSS'07: ICSE Workshops 2007). IEEE, 2007, pp. 7-7.
  8. J. Wang, Y. Dang, H. Zhang, K. Chen, T. Xie, and D. Zhang, "Mining succinct and high-coverage api usage patterns from source code," in 2013 10th Working Conference on Mining Software Repositories (MSR). IEEE, 2013, pp. 319-328.
  9. H. Niu, I. Keivanloo, and Y. Zou, "Api usage pattern recommendation for software development," Journal of Systems and Software, vol. 129, pp. 127-139, 2017.
  10. K. Papineni, S. Roukos, T. Ward, and W.-J. Zhu, "Bleu: a method for automatic evaluation of machine translation," in Proceedings of the 40th annual meeting of the Association for Computational Linguistics, 2002, pp. 311-318.
  11. S. Ren, D. Guo, S. Lu, L. Zhou, S. Liu, D. Tang, N. Sundaresan, M. Zhou, A. Blanco, and S. Ma, "Codebleu: a method for automatic evaluation of code synthesis," arXiv preprint arXiv:2009.10297, 2020. · arXiv
  12. S. Robertson, H. Zaragoza et al., "The probabilistic relevance frame- work: Bm25 and beyond," Foundations and Trends® in Information Retrieval, vol. 3, no. 4, pp. 333-389, 2009.
  13. B. Wei, Y. Li, G. Li, X. Xia, and Z. Jin, "Retrieve and refine: exemplar-based neural comment generation," in 2020 35th IEEE/ACM International Conference on Automated Software Engineering (ASE). IEEE, 2020, pp. 349-360.
  14. J. Li, Y. Li, G. Li, X. Hu, X. Xia, and Z. Jin, "Editsum: A retrieve- and-edit framework for source code summarization," in 2021 36th IEEE/ACM International Conference on Automated Software Engineer- ing (ASE). IEEE, 2021, pp. 155-166.
  15. S. Lu, N. Duan, H. Han, D. Guo, S.-w. Hwang, and A. Svyatkovskiy, "Reacc: A retrieval-augmented code completion framework," in Pro- ceedings of the 60th Annual Meeting of the Association for Computa- tional Linguistics (Volume 1: Long Papers), 2022, pp. 6227-6240.
  16. X. Gu, H. Zhang, and S. Kim, "Deep code search," in 2018 IEEE/ACM 40th International Conference on Software Engineering (ICSE). IEEE, 2018, pp. 933-944.
  17. J. Cambronero, H. Li, S. Kim, K. Sen, and S. Chandra, "When deep learning met code search," in Proceedings of the 2019 27th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering, 2019, pp. 964-974.
  18. R. A. Wagner and M. J. Fischer, "The string-to-string correction prob- lem," Journal of the ACM (JACM), vol. 21, no. 1, pp. 168-173, 1974.
  19. Y. Hao, G. Li, Y. Liu, X. Miao, H. Zong, S. Jiang, Y. Liu, and H. Wei, "Aixbench: A code generation benchmark dataset," arXiv preprint arXiv:2206.13179, 2022. · arXiv
  20. D. Zan, B. Chen, D. Yang, Z. Lin, M. Kim, B. Guan, Y. Wang, W. Chen, and J.-G. Lou, "Cert: Continual pre-training on sketches for library- oriented code generation," in Proceedings of the 31-th International Joint Conference on Artificial Intelli-gence (IJCAI 2022).
  21. W. Zaremba, I. Sutskever, and O. Vinyals, "Recurrent neural network regularization," arXiv preprint arXiv:1409.2329, 2014. · arXiv
  22. A. Vaswani, N. Shazeer, N. Parmar, J. Uszkoreit, L. Jones, A. N. Gomez, Ł. Kaiser, and I. Polosukhin, "Attention is all you need," Advances in neural information processing systems, vol. 30, 2017.
  23. L. Dong and M. Lapata, "Language to logical form with neural at- tention," in 54th Annual Meeting of the Association for Computational Linguistics. Association for Computational Linguistics (ACL), 2016, pp. 33-43.
  24. M. Rabinovich, M. Stern, and D. Klein, "Abstract syntax networks for code generation and semantic parsing," in Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), 2017, pp. 1139-1149.
  25. Z. Feng, D. Guo, D. Tang, N. Duan, X. Feng, M. Gong, L. Shou, B. Qin, T. Liu, D. Jiang et al., "Codebert: A pre-trained model for programming and natural languages," in Findings of the Association for Computational Linguistics: EMNLP 2020, 2020, pp. 1536-1547.
  26. D. Guo, S. Ren, S. Lu, Z. Feng, D. Tang, L. Shujie, L. Zhou, N. Duan, A. Svyatkovskiy, S. Fu et al., "Graphcodebert: Pre-training code representations with data flow," in International Conference on Learning Representations, 2020.
  27. S. Lu, D. Guo, S. Ren, J. Huang, A. Svyatkovskiy, A. Blanco, C. Clement, D. Drain, D. Jiang, D. Tang et al., "Codexglue: A machine learning benchmark dataset for code understanding and generation," in Thirty-fifth Conference on Neural Information Processing Systems Datasets and Benchmarks Track (Round 1), 2021.
  28. A. Radford, J. Wu, R. Child, D. Luan, D. Amodei, I. Sutskever et al., "Language models are unsupervised multitask learners," OpenAI blog, vol. 1, no. 8, p. 9, 2019.
  29. E. Nijkamp, B. Pang, H. Hayashi, L. Tu, H. Wang, Y. Zhou, S. Savarese, and C. Xiong, "A conversational paradigm for program synthesis," arXiv preprint arXiv:2203.13474, 2022. · arXiv
  30. W. U. Ahmad, S. Chakraborty, B. Ray, and K.-W. Chang, "Unified pre-training for program understanding and generation," arXiv preprint arXiv:2103.06333, 2021. · arXiv
  31. M. Evtikhiev, E. Bogomolov, Y. Sokolov, and T. Bryksin, "Out of the bleu: how should we assess quality of the code generation models?" arXiv preprint arXiv:2208.03133, 2022. · arXiv
  32. B. Wei, G. Li, X. Xia, Z. Fu, and Z. Jin, "Code generation as a dual task of code summarization," Advances in neural information processing systems, vol. 32, 2019.
  33. J. Li, G. Li, Z. Li, Z. Jin, X. Hu, K. Zhang, and Z. Fu, "Codeeditor: Learning to edit source code with pre-trained models," arXiv preprint arXiv:2210.17040, 2022. · arXiv
  34. J. Li, Y. Zhao, Y. Li, G. Li, and Z. Jin, "Towards enhancing in-context learning for code generation," arXiv preprint arXiv:2303.17780, 2023. · arXiv
  35. J. Li, G. Li, Y. Li, and Z. Jin, "Enabling programming thinking in large language models toward code generation," arXiv preprint arXiv:2305.06599, 2023. · arXiv
  36. T. Brown, B. Mann, N. Ryder, M. Subbiah, J. D. Kaplan, P. Dhariwal, A. Neelakantan, P. Shyam, G. Sastry, A. Askell et al., "Language mod- els are few-shot learners," Advances in neural information processing systems, vol. 33, pp. 1877-1901, 2020.

Cited by

Sorted by citations

Authors
Li, J., Li, Y., Li, G., Jin, Z., Hao, Y., & Hu, X.
Affiliations
  • Peking University (CN)
  • aiXcoder,Beijing,China
  • Zhejiang University (CN)
Venue
2023 IEEE/ACM 45th International Conference on Software Engineering (ICSE)
Publisher
IEEE
Published
2023-05
Pages
2124-2135
ISSN
0270-5257 (ISSN-L)
OpenAlex
W4384345649
Cited by
64
References
4
Citations by year
2026: 14 · 2025: 17 · 2024: 24 · 2023: 9
FWCI
16.45
Type
conference paper
Language
en
Open access
Locations
  • ACM/IEEE International Conference on Software Engineering: Companion Proceedings (ICSE-Companion) (publishedVersion)
  • arXiv (Cornell University) (submittedVersion)
  • Brunel University Research Archive (BURA) (Brunel University London) (submittedVersion, other-oa)
  • arXiv (Cornell University)
Funders
National Natural Science Foundation of China (61832009, 62192730, 61751210, 62072007, 62192731, 62192733)
Topics
  • Physical Sciences › Computer Science › Information Systems › Software Engineering Research
  • Physical Sciences › Computer Science › Artificial Intelligence › Topic Modeling
  • Physical Sciences › Computer Science › Computer Science Applications › Teaching and Learning Programming
Keywords
automatic code generation, code reuse, post-editing, natural language requirements

About these checks

Registry, retraction, Cites and statistics results are computed, not judged, with one exception: a printed reference that no index lists is read once by a model before it counts as a citation error. Claims are extracted by a model and kept only when their quote appears verbatim in the text; each cited source is then checked, with a model’s help, for whether it says what the claim relies on. Those verdicts can be wrong — read the claim’s quote and the cited source before relying on one.

Statistics and arithmetic are recomputed, not judged.

Confidence bands are shown only for fields calibrated on our annotated test set. None is calibrated yet, so no band is shown.

What counts as a claim ›How we measure confidence ›How we check this ›

Are you an author, or do you see a problem with this page? Request a review