In-context learning (ICL) allows large language models to adapt to new tasks by embedding demonstrations directly within the input prompt, eliminating the need for parameter updates or fine-tuning. This paradigm enables models to learn from examples at inference time, making it a cornerstone technique for prompt engineering and rapid task adaptation. Unlike traditional training, ICL leverages the model's pre-existing knowledge to generalize from a small number of contextual examples—and as context windows have expanded into the millions of tokens, the many-shot regime now approaches fine-tuning performance without any weight updates. The effectiveness of ICL depends critically on example selection, ordering, formatting, and reasoning structure—subtle variations can dramatically impact model performance, making prompt design as consequential as model architecture itself.
What This Cheat Sheet Covers
This topic spans 13 focused tables and 112 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: Core ICL Approaches
| Technique | Example | Description |
|---|---|---|
"Happy" → Positive"Terrible" → Negative"Excited" → Positive"Amazing" → | • Includes 2–10 labeled examples in the prompt to guide the model's understanding of the task • the standard ICL approach for most applications. | |
Classify: "I loved this movie!" → Sentiment: | • Direct task instruction without any demonstrations • relies entirely on the model's pre-training knowledge and instruction-following capability. | |
Q: "What is 2+2?" A: "4"Q: "What is 5+3?" A: | • Provides exactly one example to demonstrate the desired input-output pattern • useful when task format is novel but the pattern is simple. |