In-context learning
In-context learning is a language model's ability to pick up a task from instructions and examples placed in its prompt and perform it straight away, without any change to the model's weights.
Normally a machine learning model learns by having its weights adjusted during training. In-context learning is different: the model is shown a task in its input, perhaps a few labelled examples, and carries it out on a new case in the same pass. Nothing about the model changes. When the conversation ends, so does the learning.
The term was set out in OpenAI's GPT-3 paper in 2020. The authors described pre-training as giving a model a broad set of skills and pattern-recognition abilities, which it then uses at inference time to recognise and adapt to the task in front of it. They called that inner step in-context learning, happening within the forward pass for each sequence, and found that larger models made increasingly efficient use of information in the context.
A typical example: a prompt shows four customer emails, each followed by a category such as billing, delivery or complaint, then a fifth email with no label. The model assigns a category to the fifth. No one trained it on these categories; it inferred the task from the examples.
What the model learns from those examples is less than the name suggests. In a 2022 study, Sewon Min and colleagues swapped the correct labels in demonstrations for random ones and found performance barely fell across 12 models, including GPT-3, on classification and multiple-choice tasks. The demonstrations helped mainly by showing the possible labels, the kind of input and the format. Much of in-context learning, on this evidence, is the model recognising which task it already knows how to do rather than learning a new one from scratch.
The terms overlap. Google's machine learning glossary treats in-context learning as a synonym for few-shot prompting, and a survey by Qingxiu Dong and colleagues defines it as a model making predictions from contexts augmented with a few examples. In practice, in-context learning usually names the ability and few-shot prompting the technique that uses it. Either way it is temporary, cheap to change and limited by the context window, which is why tasks needing lasting changes or large amounts of data still call for fine-tuning.
No. The model's weights stay exactly the same; the task is picked up from the prompt and applies only to that request or conversation. Start a new conversation without the examples and the effect is gone. Fine-tuning trains the model on examples and permanently changes its weights. In-context learning puts examples in the prompt and changes nothing lasting. In-context learning is quicker and cheaper to adjust, while fine-tuning suits large example sets and behaviour you want every time. The GPT-3 authors described it as the model using skills and patterns acquired in pre-training to recognise the task it is shown. Research by Min and colleagues in 2022 supports a version of this: examples work mainly by showing the format and the range of answers, even when the example answers are wrong. The terms are often used interchangeably, and Google's glossary treats them as synonyms. Strictly, in-context learning is the model's ability, and few-shot prompting is the technique of supplying examples that draws on it.Common questions
Does in-context learning change the model?
What is the difference between in-context learning and fine-tuning?
Why does in-context learning work?
Is in-context learning the same as few-shot prompting?
Search for "in-context learning", "ICL survey" or "what makes in-context learning work" to find the research. The GPT-3 paper and later studies on arXiv are the primary sources, and survey papers collect the many explanations researchers have offered. Treat claims that models "learn new skills" from a prompt with care, since evidence suggests examples often help a model recognise a task rather than teach it something new.Finding more
Working out what this means for your business?
Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.