Abstract
In-Context Learning (ICL) allows Large Language Models (LLMs) to perform tasks using only a few demonstrations without weight updates. However, the mechanism behind this success—whether it represents true task generalization or the retrieval of pre-training data—remains debated. This paper investigates the link between ICL and memorization, demonstrating that increasing the number of demonstrations significantly "surfaces" memorized training data. We find a strong correlation between a model's ability to recall specific training instances and its downstream task performance, suggesting that memory retrieval is a primary driver of ICL's effectiveness.
Introduction
The ability of LLMs to learn from context is one of their most transformative features. Despite its widespread use, the underlying mechanics of ICL are not fully understood. A significant concern is data contamination: if a model has encountered a dataset during pre-training, ICL might simply act as a retrieval mechanism. This study explores how the number of demonstrations (from zero-shot to 200-shot) influences the model's ability to replicate training instances from popular benchmarks like WNLI, RTE, TREC, and DBpedia.
Methodology
To quantify memorization, the researchers transformed standard classification tasks into text completion tasks. Each dataset instance was split into two segments. The model was provided with the first segment and the correct label, then prompted to generate the second segment exactly as it appeared in the original dataset.
Completions were categorized as Exact Match (EM), Near-Exact Match (NEM), or Inexact. The study evaluated GPT-4 across three prompt settings: Full Information (instructions, demonstrations, and labels), Segment Pairs & Labels, and Only Segment Pairs (demonstrations without instructions or labels).
Results
The findings indicate that ICL serves as a powerful trigger for memory retrieval. Moving from zero-shot to few-shot (25 examples) resulted in a dramatic increase in surfaced memorization.
Key observations include:
- Memory Surfacing: In zero-shot settings, memorization was low (11%–16.5%). In many-shot regimes (up to 200 shots), it reached 24%–75%.
- The 40% Threshold: Significant performance gains over zero-shot learning were typically observed once surfaced memorization reached approximately 40%.
- Performance Correlation: A Pearson correlation often exceeding 0.90 was found between task performance and memorization levels. Models consistently performed better on instances they could remember.
- Structural Cues: Providing segment pairs without labels was often the most effective way to surface memory, suggesting the model uses data structure as a retrieval key.
- WNLI Anomaly: A slight dip in memorization was observed for WNLI in the "Only Segment Pairs" setting. This was attributed to the dataset containing identical first segments with different completions; without labels, the model could not distinguish which memorized completion to retrieve.
Discussion and Conclusion
The strong link between memorization and ICL performance suggests that many-shot learning may be surfacing internal knowledge rather than learning new task logic. While this study focused on GPT-4, it raises critical questions about how we evaluate LLM "intelligence" on contaminated benchmarks. Future work should investigate whether smaller open-source models exhibit similar behavior and attempt to disentangle true generalization from sophisticated memory lookup. Ultimately, ICL success on known datasets should be viewed with caution, as it may reflect the model's capacity for retrieval rather than reasoning.
Summary updated