An Explanation of In-context Learning as Implicit Bayesian Inference

Sang Michael Xie, Aditi Raghunathan, Percy Liang, Tengyu Ma
11/3/2021
1,264 citations
cs.CLcs.LG
bayesian

Official code: p-lambda/incontext-learning (111 stars, Python, last commit 2023-11-10).

Abstract

Large language models (LMs) such as GPT-3 have the surprising ability to do in-context learning, where the model learns to do a downstream task simply by conditioning on a prompt consisting of input-output examples. The LM learns from these examples without being explicitly pretrained to learn.

Show full abstract

Thus, it is unclear what enables in-context learning. In this paper, we study how in-context learning can emerge when pretraining documents have long-range coherence. Here, the LM must infer a latent document-level concept to generate coherent next tokens during pretraining. At test time, in-context learning occurs when the LM also infers a shared latent concept between examples in a prompt. We prove when this occurs despite a distribution mismatch between prompts and pretraining data in a setting where the pretraining distribution is a mixture of HMMs. In contrast to messy large-scale datasets used to train LMs capable of in-context learning, we generate a small-scale synthetic dataset (GINC) where Transformers and LSTMs both exhibit in-context learning. Beyond the theory, experiments on GINC exhibit large-scale real-world phenomena including improved in-context performance with model scaling (despite the same pretraining loss), sensitivity to example order, and instances where zero-shot is better than few-shot in-context learning.

View on arXivView PDF

Code Implementations(1)

Experiments and code to generate the GINC small-scale in-context learning dataset from "An Explanation for In-context Learning as Implicit Bayesian Inference"

11114Python, Jupyter NotebookOct 28, 20213 years ago
datasetfew-shot-learninggpt-3in-context-learninglanguage-modeling

Similar Papers

Cite this paper

@article{xie2021explanation,
  title  = {An Explanation of In-context Learning as Implicit Bayesian Inference},
  author = {Sang Michael Xie and Aditi Raghunathan and Percy Liang and Tengyu Ma},
  year   = {2021},
  eprint = {2111.02080},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2111.02080}
}

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/2111.02080.svg)](https://codeofpaper.com/paper/2111.02080)

Discussion