Skip to content
ContentLora

    Tip: press / anywhere to search.

    Explainer

    In-context learning: how AI models learn from examples in a prompt

    In-context learning is a language model doing a new task from a few examples placed in its prompt, with no change to its weights.[1] OpenAI's 2020 GPT-3 paper reported that this few-shot ability improves greatly with model size,[2] and later work found that the format of the examples can matter more than whether their answers are right.[3]

    Editor reviewedUpdated Explainer9 claims · 11% primaryFrontier AI, Artificial intelligence
    Reading level: 3 passages differ; the rest is the same for everyone.

    This page is part of the Frontier AI course. It assumes how transformers work and how large language models work. The next step is AI scaling laws.

    In-context learning means a language model picks up a task from examples in its prompt instead of from extra training. A 2022 EMNLP paper defines it as performing a new task “via inference alone” by conditioning on a few input-label pairs, called demonstrations.[1]

    Few-shot prompting and GPT-3

    The standard way to teach a model a new task, as the GPT-3 paper described it, was fine-tuning: training it further on thousands of labelled examples.[4] OpenAI’s GPT-3 paper tried something different. It gave a 175-billion-parameter model a description of the task and a handful of examples as plain text, then asked it to continue, without changing the model at all.[5] Bigger models got much better at this.[2]

    The GPT-3 paper (NeurIPS 2020) evaluated a few-shot setting in which tasks and demonstrations are specified purely via text, with no gradient updates.[5] It contrasted this with fine-tuning on task-specific datasets of thousands to tens of thousands of examples,[4] and reported that scale greatly improved task-agnostic few-shot performance, sometimes rivalling fine-tuned systems.[2] It also flagged datasets where few-shot learning still struggled and datasets with methodological issues linked to training on large web corpora.[6]

    What the examples actually teach

    You might think the model learns the right answers from the examples. A 2022 study tested this by giving models examples with deliberately wrong answers. Performance barely dropped. What mattered more was that the examples showed the possible answers, the kind of input to expect and the format to follow.[3]

    Min and colleagues found that randomly replacing demonstration labels barely hurt performance across 12 models, including GPT-3, on classification and multiple-choice tasks.[3] The key drivers were the label space, the distribution of input text and the overall sequence format.[3]

    A possible mechanism: induction heads

    Researchers have looked inside transformers to find what does the work. One candidate is the induction head: a part of the attention mechanism that spots a pattern earlier in the text and repeats it, so after seeing “A then B” once, it predicts B the next time A appears.[7]

    In a 2022 lab-published paper, Olsson and colleagues at Anthropic described induction heads as attention heads that complete sequences of the form [A][B] … [A] → [B].[7] They reported that these heads form at the same point in training as a sudden jump in in-context learning, visible as a bump in the loss curve, and argued they might be the mechanism for most in-context learning in large transformers.[8] The authors call the evidence preliminary and indirect: causal for small attention-only models, correlational for larger ones.[8]

    What is known and what is open

    Known: large language models can perform many tasks from a few examples given as text, and this ability improves with scale.[5][2] Reported by a 2022 study, for classification-style tasks: the format and range of the examples matter a lot, and correct labels less than expected.[3] Open: whether induction heads explain in-context learning in large models, where the evidence so far is correlational.[8]

    In-context learning is limited by the context window, the amount of text a model can read at once. A related prompting technique asks the model to write out a chain of thought, a series of intermediate reasoning steps, which a 2022 study found improves performance on complex reasoning.[9] Models trained to reason this way are covered in how reasoning models work.

    Next in the crash course

    More in Frontier AI

    Questions readers ask

    What is in-context learning?

    A language model performing a new task through inference alone, by reading a few input-and-answer examples in its prompt and then answering a new input in the same way.[1]

    Does the model learn permanently from the examples?

    No. In the GPT-3 experiments the model was used without any gradient updates or fine-tuning: the task and examples were given only as text.[5]

    Do the examples in a prompt need correct answers?

    Less than you might expect. A 2022 study found that randomly replacing the labels in the examples barely hurt performance on classification and multiple-choice tasks; the label options, the kind of input and the format mattered more.[3]

    How do models do in-context learning internally?

    Not fully known. One 2022 paper presented preliminary evidence that attention heads called induction heads might be the main mechanism, with causal evidence only in small models.[8]

    Sources

    · 9 claims from 5 publishers

    Each numbered claim is a statement we checked against the sources listed with it. Tap a number in the text to see its sources in place.

    1. [1]

      A 2022 EMNLP paper defines in-context learning as a language model performing a new task through inference alone, by conditioning on a few input-label pairs (demonstrations) and predicting outputs for new inputs. reportedas of 2026-11-22

    2. [2]

      The GPT-3 paper reported that scaling up language models greatly improves task-agnostic few-shot performance, sometimes reaching competitiveness with prior fine-tuning approaches. reportedas of 2026-11-22

    3. [3]

      The same 2022 study found that randomly replacing the labels in demonstrations barely hurt performance on a range of classification and multiple-choice tasks across 12 models including GPT-3; the label space, the input distribution and the format of the examples mattered more. reportedas of 2026-11-22

    4. [4]

      The GPT-3 paper contrasted few-shot learning with standard fine-tuning, which needs task-specific datasets of thousands or tens of thousands of examples, and noted that humans can often do a new language task from a few examples or simple instructions. reportedas of 2026-11-22

    5. [5]

      The 2020 GPT-3 paper (NeurIPS 2020) tested a 175-billion-parameter model in a few-shot setting, giving it tasks and a few demonstrations purely as text, without any gradient updates or fine-tuning. confirmedas of 2026-11-22

    6. [6]

      The GPT-3 paper also identified datasets where few-shot learning still struggled, and datasets with methodological issues related to training on large web corpora. reportedas of 2026-11-22

    7. [7]

      A 2022 Anthropic research paper describes induction heads as attention heads that complete token sequences of the form [A][B] ... [A] by predicting [B]. reportedas of 2026-11-22

    8. [8]

      The induction-heads paper presents what it calls preliminary and indirect evidence that induction heads might be the mechanism for most in-context learning in large transformers; they formed at the same point in training as a sharp rise in in-context learning, with causal evidence in small attention-only models and only correlational evidence in larger models. reportedas of 2026-11-22

    9. [9]

      A 2022 study showed that prompting large language models to generate a chain of thought, a series of intermediate reasoning steps, significantly improves their performance on complex reasoning. reportedas of 2022-01-28

    Revision history (1)
    1. Page created.

    Created Nov 22, 2026. Last reviewed by an editor on Nov 22, 2026. Next scheduled review: Jul 5, 2027.

    Cite this page

    "In-context learning: how AI models learn from examples in a prompt." ContentLora, updated Nov 22, 2026. https://contentlora.com/explain/in-context-learning-explained

    Spotted an error? Suggest a correction or emailcorrections@contentlora.com.