MarginSel : Max-Margin Demonstration Selection for LLMs

Rajeev Bhatt Ambati, James C. Lester, Shashank Srivastava, Snigdha ChaturvediarXiv 2025 · DOI

Abstract

Few-shot In-Context Learning (ICL) is highly sensitive to the specific demonstrations provided in a prompt. We present MarginSel, a novel, training-free method that improves ICL performance by selecting "hard" examples located near the model's decision boundary. By mimicking the behavior of Support Vector Machines (SVMs), MarginSel identifies examples that act as support vectors, inducing a "max-margin" effect. Our experiments across multiple Large Language Models (LLMs) demonstrate absolute F1-score gains of 2–7% over standard selection methods, particularly in tasks with high label ambiguity.

Introduction

Large Language Models (LLMs) exhibit remarkable few-shot capabilities, yet their performance is notoriously unstable depending on the choice of demonstrations. Existing selection strategies generally fall into two categories: computationally expensive retriever-trained methods and retriever-free methods like k-Nearest Neighbors (kNN-ICL). While kNN-ICL selects examples based on semantic similarity, it often retrieves "easy" or redundant examples that fail to help the model resolve fine-grained distinctions in ambiguous regions of the feature space.

MarginSel addresses this gap by introducing a dynamic, uncertainty-aware selection mechanism. Instead of relying solely on similarity, it identifies training instances that challenge the model's internal decision boundaries, effectively providing the LLM with the most informative "support vectors" for a given test case.

Methodology: The MarginSel Framework

MarginSel operates as a two-step, training-free pipeline designed to surface boundary-proximal examples:

  1. Candidate Label Assignment: The LLM is prompted in a zero-shot, multi-label fashion to assign all plausible labels to every training instance and the current test instance. When the model is uncertain, it naturally outputs multiple labels (e.g., a bitstring like "10010" indicating that labels 1 and 4 are both relevant candidates).
  2. Hard Example Selection: The system filters the training set for instances that share the exact same set of candidate labels as the test instance. These represent the "hard" examples where the model's internal logic is most ambiguous.
The MarginSel workflow: identifying ambiguous candidate labels to select boundary-proximal examples.

The final prompt is constructed using a hybrid approach, mixing these "hard" examples with standard kNN-selected similar examples. Theoretically, the authors demonstrate that including these boundary-proximal examples is equivalent to a parameter update in an affine layer, shifting the decision boundary to maximize the margin between classes.

Experimental Setup

The method was evaluated on three classification tasks with varying levels of ambiguity:

  • SST-5: Fine-grained sentiment analysis.
  • Cognitive Distortion: A challenging clinical dataset for detecting subtle psychological distortions.
  • Medical Abstracts: Topic classification for medical research papers.

Testing spanned several state-of-the-art models, including Phi-3, Mistral-7B, Phi-4, and Llama-3.1 (8B and 70B).

Key Results and Analysis

MarginSel consistently outperformed both random selection and kNN-ICL across all models and datasets. The most significant gains (up to 7% F1 improvement) were observed in the Cognitive Distortion task, where identifying the precise decision boundary is most critical due to high label overlap.

Beyond accuracy metrics, MarginSel fundamentally alters the model's internal representation of the data. As shown in the t-SNE visualizations below, MarginSel induces significantly higher class separation compared to random selection or zero-shot learning. The resulting clusters are tighter and more distinct, confirming that the inclusion of "support vector" demonstrations helps the model resolve inter-class ambiguity.

t-SNE visualizations comparing class separation under MarginSel, Random Selection, and Zero-Shot Learning.

Conclusion and Limitations

MarginSel provides a robust, theoretically grounded framework for demonstration selection without the need for task-specific retriever training. By leveraging the LLM's own zero-shot uncertainty, it identifies the most informative examples for navigating complex decision boundaries.

However, the method's efficacy is partially dependent on the base model's zero-shot capability; if the initial candidate labels are entirely inaccurate, the selected "hard" examples may be less effective. Future work will explore the application of max-margin selection to generative tasks such as reasoning and summarization.

Summary updated

BibTeX
@misc{ambati2025marginsel,
  author = {Rajeev Bhatt Ambati and James C. Lester and Shashank Srivastava and Snigdha Chaturvedi},
  title = {{MarginSel : Max-Margin Demonstration Selection for LLMs}},
  year = {2025},
  eprint = {2506.06699},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2506.06699},
}
Figure