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

In-Context Learning with Long-Context Models: An In-Depth Exploration

Amanda Bertsch, Maor Ivgi, Emily Xiao, Uri Alon, Jonathan Berant, Matthew R. Gormley, Graham Neubig

In-Context Learning with Long-Context Models: An In-Depth Exploration

As Large Language Model (LLM) context windows expand from 4k to over 1M tokens, we have entered the era of "many-shot" in-context learning (ICL). Traditionally, ICL was restricted to "few-shot" prompts (5–10 examples) due to hardware constraints. This forced a binary choice: use a few examples for quick prompting or invest in the significant overhead of finetuning on a full dataset. With models like Llama-3 and Gemini 1.5, this boundary has blurred. This paper investigates whether ICL continues to scale when thousands of demonstrations are provided—essentially fitting an entire training set into a single prompt.

Methods and Datasets

The researchers conducted a systematic study across four regimes: Random ICL, Retrieval-based ICL (using BM25 or BERTScore), Finetuning (Full and LoRA), and a mechanistic analysis using block-sparse attention. They evaluated these methods on classification tasks with large label spaces—such as TREC-fine (50 labels), Banking-77 (77 labels), and Clinic-150 (151 labels)—and generation tasks like SAMSum. The study primarily utilized the Llama-2 family (adapted for 32k/80k contexts), Mistral, and Qwen, alongside frontier models like Claude 3.5 Sonnet.

Key Insights: The Mechanics of Many-Shot ICL

  • Diminishing Returns of Retrieval: While retrieving the "best" examples is critical in few-shot settings, the gap between smart retrieval and random sampling narrows significantly as context scales to 1,000+ examples. This suggests that with enough data, a "cached" set of random examples is nearly as effective as custom-retrieved ones.
  • Order Robustness vs. Sorting Sensitivity: Many-shot ICL is surprisingly robust to example ordering, mitigating the "recency bias" seen in few-shot settings. However, it is highly sensitive to label grouping; interleaving labels is essential for the model to learn decision boundaries.
  • Retrieval-in-Context Hypothesis: Using block-sparse attention, the authors found that performance remains stable even when demonstrations cannot "see" each other. This suggests the model treats the prompt as a sophisticated internal database for retrieval rather than learning complex inter-example relationships.

Key Results and Scaling

The study demonstrates that performance continues to climb well past 2,000 demonstrations for complex tasks. On the Llama2-80k model, increasing from 10 to 1,000 demonstrations yielded an average accuracy gain of 36.8 points across five datasets.

Accuracy scales significantly with the number of in-context examples across various classification datasets.

ICL vs. Finetuning

A standout finding is that many-shot ICL can rival or even outperform Parameter-Efficient Finetuning (PEFT/LoRA) when given the same amount of data. While full finetuning eventually prevails, it only does so when the dataset size significantly exceeds the context window capacity.

Comparison of Retrieval ICL, Base ICL, PEFT, and Full Finetuning across different data scales. Many-shot ICL often outperforms PEFT.

Conclusion and Future Directions

Many-shot ICL offers a viable alternative to finetuning, especially when combined with KV-caching to amortize inference costs. However, challenges remain, including the high computational cost of long-context attention and the potential for "lost in the middle" effects. Future work will need to optimize the many-shot inference path and explore scaling behaviors in trillion-parameter frontier models.

Summary updated

BibTeX
@inproceedings{bertsch2025context,
  author = {Amanda Bertsch and Maor Ivgi and Emily Xiao and Uri Alon and Jonathan Berant and Matthew R. Gormley and Graham Neubig},
  title = {{In-Context Learning with Long-Context Models: An In-Depth Exploration}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2025},
  doi = {10.18653/v1/2025.naacl-long.605},
}
Figure