GlossaryLanguage models
In-context learning
Definition: In-context learning is an AI model doing a task from instructions or worked examples in its input, without any further training of the model.
A model’s weights are the numbers it learned in training. Fine-tuning, a separate entry, changes them. In-context learning leaves them as they are: the model picks up the task while it reads a single input. Zero-shot means the input gives only an instruction, one-shot adds one worked example and few-shot adds several. On TriviaQA, a set of trivia questions, the 175-billion-parameter GPT-3 answered 64.3% of the questions correctly zero-shot, 68.0% one-shot and 71.2% few-shot, with no access to outside documents (Brown et al., 2020). In the few-shot setting, Brown et al. typically gave 10 to 100 examples, as many as fit in the model’s context window of 2,048 tokens. For example, an agent given three sample trade summaries in its prompt may write new summaries in the same layout without any retraining.
Researchers disagree about what a model takes from the examples. Min et al. tested six language models, including GPT-3, each run in two ways, on up to 26 classification and multiple-choice datasets, with 16 examples in each prompt. Replacing each example’s correct label with one picked at random lowered nearly every model’s score by 0 to 5 percentage points (Min et al., 2022). For multiple-choice tasks, the score was the share of questions answered correctly. For classification, it was macro-F1, the average over the possible labels of each label’s F1 score, which falls both when the model assigns that label wrongly and when it misses it. The authors concluded that the examples helped mainly by showing the possible labels, the kind of input text and the format. Yoo et al. (2022) found that how much correct labels matter depends on the setup, including model size and how wordy the prompt template is. Wei et al. (2023) found that large models can follow examples whose labels have been deliberately flipped, against what they learned in training, while small models ignore the flipped labels.
The name comes from Language Models are Few-Shot Learners (Brown et al., 28 May 2020), the GPT-3 paper, which wrote that recent work “attempts to do this via what we call” in-context learning and cited the GPT-2 paper (Radford et al., 2019) as that work.
