A genetic algorithm-based framework known as GAFS demonstrates that evaluating complete subsets of demonstration examples improves few-shot learning performance in large language models. In-context few-shot learning in large language models is highly sensitive to the selection of suitable demonstration examples. However, existing approaches commonly guide this selection through predefined retrieval methods or local criteria rather than considering the collective impact of the chosen demonstration prompts on downstream behavior.
To overcome these limitations in existing techniques, GAFS formulates few-shot example selection as a global combinatorial optimization problem. Rather than scoring and ranking candidate demonstrations independently, the GAFS method searches for fixed-size subsets of demonstrations that jointly maximize downstream task performance. This optimization strategy directly evaluates complete demonstration sets during the search process to identify combinations of examples that function effectively together.
The research team evaluated GAFS on four Spanish hate speech detection datasets, identified as HatEval, EXIST, DETESTS, and HOMO-MEX. The experimental design incorporated ten open-weight large language models representing different model families and parameter scales. For comparative assessment, the authors evaluated GAFS against three baseline methods, specifically zero-shot learning without demonstration examples, random few-shot learning, and retrieval-based few-shot learning.
Across the benchmark evaluations, the best GAFS configurations attained macro-averaged F1-scores of 68.6 on HatEval, 73.1 on EXIST, 67.6 on DETESTS, and 63.7 on HOMO-MEX. The optimization framework demonstrated consistent advantages across the diverse model families and datasets. Across the tested datasets, GAFS achieved a higher macro-averaged F1-score than random few-shot learning in 37 of 40 model-dataset configurations, and it likewise exceeded the performance of retrieval-based few-shot learning in 37 of 40 configurations.
Statistical evaluation confirmed the significance and stability of the observed performance gains over the retrieval-based baseline. An aggregate McNemar analysis comparing GAFS against retrieval-based few-shot learning identified 2,269 additional correct predictions among the discordant test cases, reaching statistical significance at p less than 0.001. Additionally, a complementary multi-seed analysis revealed that this performance pattern was largely preserved across independent evolutionary optimization runs, confirming the stability of the approach.
To isolate the precise contribution of model-specific optimization, the researchers also compared GAFS with matched-budget model-aware random search, designated as MA-RS. Neither search strategy demonstrated a systematic advantage over the other across the evaluated configurations. This parity indicates that model-aware, performance-driven evaluation of complete demonstration subsets is an important component of the gains achieved over standard few-shot baselines, rather than the evolutionary search mechanism alone.
Further analysis of the selected demonstration sets established that higher diversity, coverage, or class balance was not systematically associated with better downstream task performance. The authors concluded that global, model-aware optimization of demonstration subsets provides an effective operational strategy for few-shot learning in language models. These findings also motivate further scientific investigation into the relative advantages of different search mechanisms for selecting demonstrations.
Subject of Research: Genetic algorithm optimization for few-shot demonstration selection in language models
Article Title: GAFS: a genetic algorithm-based few-shot example selection for large language models
Article References: Bernal-Beltrán, T., Pan, R., García-Díaz, J. A., Beydoun, G., & Valencia-García, R. (2026). GAFS: a genetic algorithm-based few-shot example selection for large language models. Complex & Intelligent Systems. https://doi.org/10.1007/s40747-026-02559-y
Image Credits: AI Generated
DOI: 10.1007/s40747-026-02559-y
Keywords: few-shot learning, large language models, genetic algorithms, in-context learning, demonstration selection, combinatorial optimization, hate speech detection, HatEval, EXIST dataset, DETESTS, HOMO-MEX, open-weight language models, macro-F1 score, McNemar test, model-aware random search, zero-shot learning, retrieval-based selection
Cite Scienmag News
Juliet Wilcox. (November 27, 2026). Genetic Algorithm Selects Demonstration Subsets to Boost Language Model Few-Shot Performance. Scienmag. https://scienmag.com/genetic-algorithm-selects-demonstration-subsets-to-boost-language-model-few-shot-performance/
Juliet Wilcox. "Genetic Algorithm Selects Demonstration Subsets to Boost Language Model Few-Shot Performance." Scienmag, 27 November 2026, https://scienmag.com/genetic-algorithm-selects-demonstration-subsets-to-boost-language-model-few-shot-performance/. Accessed 27 November 2026.
Juliet Wilcox. "Genetic Algorithm Selects Demonstration Subsets to Boost Language Model Few-Shot Performance." Scienmag. November 27, 2026. https://scienmag.com/genetic-algorithm-selects-demonstration-subsets-to-boost-language-model-few-shot-performance/








