NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Many-Shot In-Context Learning

Rishabh Agarwal, Avi Singh, Lei M Zhang, Bernd Bohnet, Luis Rosias, Stephanie C.y. Chan, Biao Zhang, Ankesh Anand, Zaheer Abbas, Azade Nova, John D Co-Reyes, Eric Chu, Feryal Behbahani, Aleksandra Faust, Hugo Larochelle

Abstract

In-context learning (ICL) has traditionally been limited to the "few-shot" regime due to the narrow context windows of early large language models (LLMs). With the advent of long-context models like Gemini 1.5 Pro, it is now possible to provide thousands of examples in a single prompt. This paper investigates the "many-shot" regime, demonstrating that scaling ICL to thousands of examples leads to significant performance gains, allows models to override pre-training biases, and enables the acquisition of complex new skills at inference time without weight updates.

Introduction

Since the introduction of GPT-3, in-context learning has been a defining characteristic of large language models, allowing them to perform tasks based on a handful of examples. However, the practical application of ICL has been constrained by context window limits, typically restricting prompts to fewer than 50 examples. This research explores the transition from few-shot to many-shot ICL, utilizing context windows of up to 1 million tokens to evaluate how LLMs behave when provided with hundreds or thousands of demonstrations.

Methodology

The researchers utilized Gemini 1.5 Pro to test ICL scaling up to 8,192 shots. To overcome the challenge of sourcing thousands of high-quality, human-labeled examples, the study introduced two primary strategies:

  1. Reinforced ICL: This method replaces human-written rationales with model-generated Chain-of-Thought (CoT) explanations. These explanations are filtered for correctness, providing a scalable way to generate high-quality demonstrations.
  2. Unsupervised ICL: In this regime, the prompt consists of a long series of raw inputs (e.g., mathematical problems) without solutions, followed by a zero-shot or few-shot instruction. This tests the model's ability to leverage unlabeled data to improve its task performance.

Additionally, the team employed synthetic tasks, such as high-dimensional linear classification and sequential parity, to analyze the underlying learning dynamics of the model in a controlled environment.

Experimental Evaluation

The study evaluated many-shot performance across a diverse set of benchmarks:

  • Reasoning and Mathematics: MATH, GSM8K, and Big-Bench Hard (BBH).
  • Language Processing: Low-resource translation (FLORES-200) for languages like Bemba and Kurdish, and sentiment analysis (Financial PhraseBank).
  • Planning: Logistics domain tasks using PDDL.
  • Synthetic Functions: Binary linear classification up to 64 dimensions.

Key Insights

1. The Scaling Law of ICL

Performance across most tasks does not plateau at the few-shot limit. Instead, it scales monotonically as more examples are added. In low-resource translation, for instance, increasing the prompt from 1-shot to 997-shot resulted in a performance boost of over 15%.

2. Overriding Pre-training Bias

A significant hurdle for LLMs is "pre-training bias," where the model's prior knowledge interferes with prompt instructions (e.g., a model struggling to label a positive sentence as "negative" in a flipped-label task). The researchers found that many-shot ICL eventually "breaks" this bias; given enough examples, the model ignores its pre-trained priors and follows the logic of the prompt perfectly.

3. ICL as an In-Context Optimizer

On synthetic tasks, many-shot LLMs behave similarly to traditional machine learning algorithms. The evidence suggests that in the many-shot regime, the model effectively implements algorithms like k-Nearest Neighbors or gradient descent entirely within its activations.

4. The NLL Paradox

The study observed that Negative Log-Likelihood (NLL) continues to improve as more shots are added, even in cases where task accuracy plateaus or slightly declines. This indicates that NLL remains a sensitive metric for learning progress in long contexts, even when discrete performance metrics become noisy.

Results

  • Comparison to Fine-Tuning: In machine translation tasks, many-shot ICL achieved results comparable to supervised fine-tuning (SFT) using the same volume of data.
  • Reinforced ICL Performance: On Big-Bench Hard, Reinforced ICL reached an 83% success rate, significantly higher than the 72.1% achieved with human-written 3-shot CoT.
  • Unsupervised Success: For the MATH benchmark, providing a long list of unsolved problems was nearly as effective as providing solved ones, suggesting that many-shot prompts can "locate" latent capabilities within the model.

Discussion and Limitations

While many-shot ICL offers a powerful alternative to fine-tuning, it introduces new challenges. The primary drawback is inference cost; processing thousands of tokens for every query is computationally expensive. The authors emphasize that Key-Value (KV) caching is essential for making this approach viable in production.

Furthermore, the researchers noted "overloading" in certain tasks like MATH, where performance began to degrade after approximately 125 shots. The sensitivity of the model to the order of examples also persists in the many-shot regime, suggesting that prompt engineering remains a complex requirement. Finally, while the trends were observed across other frontier models like GPT-4 Turbo, the magnitude of the many-shot benefit varies significantly between architectures.

Summary updated

BibTeX
@inproceedings{agarwal2024many,
  author = {Rishabh Agarwal and Avi Singh and Lei M Zhang and Bernd Bohnet and Luis Rosias and Stephanie C.Y. Chan and Biao Zhang and Ankesh Anand and Zaheer Abbas and Azade Nova and John D Co-Reyes and Eric Chu and Feryal Behbahani and Aleksandra Faust and Hugo Larochelle},
  title = {{Many-Shot In-Context Learning}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=AB6XpMzvqH},
}
Figure