Nanyang Technological University
Using evolutionary computation for demonstration example selection in in-context learning
Abstract
dc:description.abstractIn-Context Learning (ICL) enables frozen large language models (LLMs) to solve natural language tasks via labeled demonstrations within input prompts, without parameter fine-tuning. Nevertheless, ICL performance heavily relies on demonstration quality: both which examples are chosen and their sequence order impact model outputs drastically. Existing methods optimize demonstration selection and ordering independently or adopt simple similarity retrieval, ignoring their mutual synergy. Joint tuning of examples and their arrangement forms a large combinatorial search problem that rules out exhaustive scanning as candidate pools grow, creating key optimization bottlenecks. To resolve this gap, this thesis puts forward EC-ICL, an integrated evolutionary computation framework for simultaneous demonstration selection and ordering. The work transforms prompt building into a discrete combinatorial task solved by permutation genetic algorithms (GAs). Each GA individual encodes an ordered list of demonstration indices, unifying selection and permutation into one representation. A dual fitness metric combining validation prediction accuracy and semantic diversity reward is constructed to balance predictive power and sample coverage. Only black-box LLM inference outputs are required for evaluation, so EC-ICL works with closed commercial LLMs inaccessible to internal weights. Three custom genetic operators are tailored for ICL search: Order Crossover retains beneficial sequence layouts; Replace Mutation expands candidate example diversity; Recency-Biased Swap Mutation refines late-position examples to match LLMs’ recency positional bias. Tournament selection and elite retention are also integrated to stabilize evolution and avoid premature convergence. Validated on SST-2, AG News and CommonsenseQA with GPT-3.5 Turbo, EC-ICL surpasses Zero-shot, Random Selection, KATE and EPR across all benchmarks, delivering a maximum 4.5% accuracy lift over the top baseline on CommonsenseQA. Ablation tests confirm the necessity of all proposed operators and diversity regularization. Additional experiments prove the method possesses stable performance and reliable convergence across diverse tasks. This work verifies evolutionary computation as a flexible, gradient-free solution for joint demonstration prompt optimization, offering a novel evolutionary paradigm for ICL prompt engineering.
Degree
thesis:*- College dc:contributor.school
- School of Electrical and Electronic Engineering
- Grantor dc:publisher
- Nanyang Technological University
- Year dc:date.issued
- 2026
Author and committee
dc:creator, dc:contributor.*- Author dc:creator
-
- Wang, Zhaoxuan
- Advisor dc:contributor.supervisor
-
- Mao Kezhi
Subjects
dc:subject × 1Rights
- Language dc:language.iso
- en
Identifiers
dc:identifier.*- Handle dc:identifier.uri
- https://hdl.handle.net/10356/221361