Understanding the Generalization of In-Context Learning in Transformers: An Empirical Study

Xingxuan Zhang, Haoran Wang, Jiansheng Li, Yuan Xue, Shikai Guan +4 more
3/19/2025
cs.LG

No official code found. Best implementation: UbeCc/Generalization-of-Transformers (4 stars, last commit 2025-04-27).

Abstract

Large language models (LLMs) like GPT-4 and LLaMA-3 utilize the powerful in-context learning (ICL) capability of Transformer architecture to learn on the fly from limited examples. While ICL underpins many LLM applications, its full potential remains hindered by a limited understanding of its generalization boundaries and vulnerabilities. We present a systematic investigation of transformers' generalization capability with ICL relative to training data coverage by defining a task-centric framework along three dimensions: inter-problem, intra-problem, and intra-task generalization. Through extensive simulation and real-world experiments, encompassing tasks such as function fitting, API calling, and translation, we find that transformers lack inter-problem generalization with ICL, but excel in intra-task and intra-problem generalization. When the training data includes a greater variety of mixed tasks, it significantly enhances the generalization ability of ICL on unseen tasks and even on known simple tasks. This guides us in designing training data to maximize the diversity of tasks covered and to combine different tasks whenever possible, rather than solely focusing on the target task for testing.

View on arXivView PDF

Code Implementations(1)

[ICLR'25] Understanding the Generalization of In-Context Learning in Transformers: An Empirical Study

40Shell, PythonNov 21, 20241 years ago

Similar Papers

Cite this paper

@article{zhang2025understanding,
  title  = {Understanding the Generalization of In-Context Learning in Transformers: An Empirical Study},
  author = {Xingxuan Zhang and Haoran Wang and Jiansheng Li and Yuan Xue and Shikai Guan and Renzhe Xu and Hao Zou and Han Yu and Peng Cui},
  year   = {2025},
  eprint = {2503.15579},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2503.15579v1},
  journal = {ICLR 2025 2025}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2503.15579.svg)](https://codeofpaper.com/paper/2503.15579)

Discussion