Does Few-Shot Learning Help LLM Performance in Code Synthesis?
On the map: LLM reasoning → Reasoning for agents, planning and code
Abstract (arXiv)
Large language models (LLMs) have made significant strides at code generation through improved model design, training, and chain-of-thought. However, prompt-level optimizations remain an important yet under-explored aspect of LLMs for coding. This work focuses on the few-shot examples present in most code generation prompts, offering a systematic study on whether few-shot examples improve LLM's coding capabilities, which few-shot examples have the largest impact, and how to select impactful examples. Our work offers 2 approaches for selecting few-shot examples, a model-free method, CODEEXEMPLAR-FREE, and a model-based method, CODEEXEMPLAR-BASED. The 2 methods offer a trade-off between improved performance and reliance on training data and interpretability. Both methods significantly improve CodeLlama's coding ability across the popular HumanEval+ coding benchmark. In summary, our work provides valuable insights into how to pick few-shot examples in code generation prompts to improve LLM code generation capabilities.
Key facts. Cited by 6 papers in the map (data through 14 Oct 2026). Placed in Reasoning for agents, planning and code, one of 17 directions in LLM reasoning. Builds on 43 of its 66 references that are in the map. First posted on arXiv 3 Dec 2024.
Builds on
43 of 66 references.
Closest ancestors · 4
Same direction, newest first
- 2024Qwen2.5-Coder Technical Report18 Sep
- 2024MapCoder: Multi-Agent Code Generation for Competitive Problem Solving18 May
- 2024OpenCodeInterpreter: Integrating Code Generation with Execution and Refinement22 Feb
- 2023Structured Chain-of-Thought Prompting for Code Generation11 May
Other references · 39
- 2020Language Models are Few-Shot Learnerscited by 32,419
- 2019PyTorch: An Imperative Style, High-Performance Deep Learning Librarycited by 20,305
- 2024The Llama 3 Herd of Modelscited by 14,715
- 2019Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformercited by 14,599
- 2023LLaMA: Open and Efficient Foundation Language Modelscited by 14,132
- 2021Evaluating Large Language Models Trained on Codecited by 8,320
- 2020Scaling Laws for Neural Language Modelscited by 6,586
- 2022FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awarenesscited by 3,673
- 2021Program Synthesis with Large Language Modelscited by 3,637
- 2023Code Llama: Open Foundation Models for Codecited by 2,139
- 2021Calibrate Before Use: Improving Few-Shot Performance of Language Modelscited by 1,392
- 2023Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generationcited by 1,391
27 more
- 2021What Makes Good In-Context Examples for GPT-3?cited by 1,195
- 2024DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligencecited by 1,181
- 2021Fantastically Ordered Prompts and Where to Find Them: Overcoming Few-Shot Prompt Order Sensitivitycited by 1,135
- 2021CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generationcited by 906
- 2024Chronos: Learning the Language of Time Seriescited by 759
- 2022TabPFN: A Transformer That Solves Small Tabular Classification Problems in a Secondcited by 674
- 2021Learning To Retrieve Prompts for In-Context Learningcited by 648
- 2023WizardMath: Empowering Mathematical Reasoning for Large Language Models via Reinforced Evol-Instructcited by 625
- 2024BigCodeBench: Benchmarking Code Generation with Diverse Function Calls and Complex Instructionscited by 546
- 2024StarCoder 2 and The Stack v2: The Next Generationcited by 502
- 2022InCoder: A Generative Model for Code Infilling and Synthesiscited by 498
- 2023The Impact of AI on Developer Productivity: Evidence from GitHub Copilotcited by 274
- 2023An Empirical Evaluation of Using Large Language Models for Automated Unit Test Generationcited by 194
- 2023Large Language Models Are Latent Variable Models: Explaining and Finding Good Demonstrations for In-Context Learningcited by 149
- 2023Few-shot Fine-tuning vs. In-context Learning: A Fair Comparison and Evaluationcited by 136
- 2023Large Language Models as Evolutionary Optimizerscited by 124
- 2024A Note on Shumailov et al. (2024): `AI Models Collapse When Trained on Recursively Generated Data'cited by 115
- 2022Repository-Level Prompt Generation for Large Language Models of Codecited by 106
- 2024VerilogCoder: Autonomous Verilog Coding Agents with Graph-based Planning and Abstract Syntax Tree (AST)-based Waveform Tracing Toolcited by 85
- 2024Revisiting Demonstration Selection Strategies in In-Context Learningcited by 58
- 2024Let's Learn Step by Step: Enhancing In-Context Learning Ability with Curriculum Learningcited by 47
- 2023Can Large Language Models Write Good Property-Based Tests?cited by 31
- 2024Customizing Language Model Responses with Contrastive In-Context Learningcited by 19
- 2024AcTracer: Active Testing of Large Language Model via Multi-Stage Samplingcited by 17
- 2024RAMBO: Enhancing RAG-based Repository-Level Method Body Completioncited by 10
- 2024Learning Program Behavioral Models from Synthesized Input-Output Pairscited by 4
- 2020Generating Unit Tests for Documentationcited by 1
Built on by
Citing papers per year: 2024: 1; 2025: 3; 2026: 2.
6 papers.
- 2025MCPTox: A Benchmark for Tool Poisoning Attack on Real-World MCP Serverscited by 66
- 2024The Impact of Prompt Programming on Function-Level Code Generationcited by 13
- 2025Instance-level Randomization: Toward More Stable LLM Evaluationscited by 1
- 2026Hawk: Harnessing Hardware-Aware Knowledge for High-Performance NPU Kernel Generationcited by 1
- 2025Rethinking Technology Stack Selection with AI Coding Proficiencycited by 0
- 2026Goal-Conditioned Supervised Learning for LLM Fine-Tuningcited by 0
- 2026Hawk: Harnessing Hardware-Aware Knowledge for High-Performance NPU Kernel Generation2 Jul 2026
- 2026Goal-Conditioned Supervised Learning for LLM Fine-Tuning8 May 2026
- 2025Instance-level Randomization: Toward More Stable LLM Evaluations16 Sep 2025
- 2025Rethinking Technology Stack Selection with AI Coding Proficiency14 Sep 2025
- 2025MCPTox: A Benchmark for Tool Poisoning Attack on Real-World MCP Servers19 Aug 2025
- 2024The Impact of Prompt Programming on Function-Level Code Generation29 Dec 2024
Similar, not cited
Close in wording, no citation either way
- 2024Improving the Ability of Pre-trained Language Model by Imparting Large Language Model's Experience ↗
- 2024Enhancing Code Translation in Language Models with Few-Shot Learning via Retrieval-Augmented Generation
- 2024Does Prompt Formatting Have Any Impact on LLM Performance?
- 2025Training-free LLM Verification via Recycling Few-shot Examples
- 2025Holistic Evaluation of State-of-the-Art LLMs for Code Generation
- 2024Enhancing Code Generation Performance of Smaller Models by Distilling the Reasoning Ability of LLMs
- 2026Not the Example, but the Process: How Self-Generated Examples Enhance LLM Reasoning
- 2024Mastering the Craft of Data Synthesis for CodeLLMs