In-context learning is a way an AI model can appear to learn a new task from examples placed inside the prompt. Instead of changing its stored weights, the model uses the pattern in the given examples to decide what to output next. This matters because it lets people guide an AI system quickly, using instructions and sample inputs rather than new training data.
It is one reason modern chatbots can adapt to many school, coding, math, and writing tasks.
Key Facts
- In-context learning uses examples in the prompt, not extra training, to guide the model's next output.
- A prompt can include instructions, examples, a question, and formatting rules.
- The model predicts the next token using probabilities: P(next token | context).
- Few-shot prompting means giving a small number of examples, such as 2 to 5, before the new problem.
- More relevant examples usually improve results, but too many examples can confuse the model or exceed the context window.
- Accuracy can be estimated as accuracy = correct answers / total questions.
Vocabulary
- In-context learning
- A model behavior where an AI uses information and examples inside a prompt to handle a task without updating its weights.
- Prompt
- The text, data, instructions, and examples given to an AI model before it generates an answer.
- Token
- A small unit of text, such as a word, part of a word, number, or symbol, that a language model processes.
- Context window
- The maximum amount of prompt and conversation information a model can consider at one time.
- Few-shot example
- A sample input and correct output included in a prompt to show the model the pattern to follow.
Common Mistakes to Avoid
- Thinking the model is permanently learning from the prompt, which is wrong because in-context learning usually does not update the model's stored weights.
- Giving examples that do not match the final question, which is wrong because the model may copy the wrong pattern or format.
- Using vague instructions like answer correctly, which is wrong because the model needs clear rules, labels, and output format to infer the task well.
- Assuming more examples always help, which is wrong because irrelevant or excessive examples can waste context space and reduce clarity.
Practice Questions
- 1 A student gives an AI 4 example input-output pairs and then asks it to solve 6 new items. The AI gets 5 of the 6 new items correct. What is its accuracy on the new items?
- 2 A prompt has 120 tokens of instructions, 3 examples that are 80 tokens each, and a final question that is 60 tokens. How many total tokens are in the prompt?
- 3 You want an AI to convert temperatures from Celsius to Fahrenheit. Explain why giving two worked examples before the new temperature could help the model, and name one risk if one example contains a mistake.