What Builds Effective In-Context Examples for Code Generation?
Dongze Li, Songqiang Chen, Jialun Cao, Shing-Chi Cheung

TL;DR
This paper systematically examines how different features of in-context code examples influence large language models' code generation, highlighting the importance of variable naming and identifying current limitations in reflection capabilities.
Contribution
It provides a controlled analysis of code features affecting ICL effectiveness, revealing the critical role of naming and the challenges in reflection-based learning.
Findings
Proper variable and function naming significantly improves performance.
LLMs prioritize semantic meaning over formatting conventions.
Current models struggle with extracting generalizable insights from code.
Abstract
In-Context Learning (ICL) has emerged as a promising solution to enhance the code generation capabilities of Large Language Models (LLMs), which incorporates code examples inside the prompt to let LLMs learn from demonstrations. However, despite the substantial effectiveness of the code example-based ICL approach, the specific features (e.g., identifier naming styles, code formatting, solution insight) within the ICL-provided code examples that significantly contribute to the ICL's effectiveness remain unclear. This paper systematically investigates the impact of various code features on ICL with code examples through controlled ablation studies. Our findings reveal that the appropriate naming of variables and functions is crucial for effective code generation, with their elimination leading to performance decreases of up to 30 percentage points. We further demonstrate that LLMs…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsModel-Driven Software Engineering Techniques · Software Engineering Techniques and Practices · Advanced Software Engineering Methodologies
