In-Context Learning (ICL)

From PRIMO.ai
Jump to navigation Jump to search

YouTube ... Quora ...Google search ...Google News ...Bing News


In-context learning (ICL) is a model's ability to adapt its behavior using examples or other task information supplied in its current context, without updating its learned weights during that inference. Show a Large Language Model (LLM) several support messages paired with the correct department, then give it a new message: it can infer the desired mapping and output format. This adaptation depends on the information actually available to the model. Saving a conversation or example library doesn't mean every future request automatically includes it.

ICL now extends beyond a handful of text examples. Long-context models can use hundreds of demonstrations; retrieval systems can select examples for each request; prompt optimizers can search for useful combinations of instructions and examples. Tabular foundation models also use labeled rows as context for predictions. These developments can reduce the effort needed to prototype a classifier, apply a house style, translate specialized material, or adapt an evaluator to human judgments. They don't remove the need to check accuracy, privacy, inference cost, and performance on unfamiliar cases.

The practical question is what the examples teach and whether that lesson transfers to new inputs. A model might follow a formatting pattern without learning the intended rule, copy a flawed label, or miss an exception. More context isn't automatically better. Start with a clear task, representative demonstrations, and a separate test set; compare the results with simpler prompting and other approaches before adding complexity. Stanford's framework for understanding ICL Many-Shot In-Context Learning, NeurIPS 2024

Reviewed 23 November 2026. Research results describe their tested models and tasks; product capabilities, limits, and licensing can change.

🧭 Explore in-context learning
A concrete example and the boundary between adaptation and lasting learning.
Many-shot learning, retrieval, example ordering, and generated demonstrations.
Gemini, DSPy, LangSmith, and TabPFN, with practical uses and tradeoffs.
Select demonstrations, test transfer, manage costs, and check failures.
What changes in training, fine-tuning, retrieval, and ICL.
How learning histories can guide behavior without inference-time weight updates.
Choose a large label to jump to its section.

ICL in Practice

A shot is a demonstration, usually an input paired with its desired output. Zero-shot prompting gives the task without demonstrations; one-shot provides one; few-shot provides several; many-shot supplies a larger collection. These terms don't define universal numerical thresholds. In broader research, ICL can also refer to adaptation from task histories or unlabeled context.

🧩 The model adapts from examples in the current input
1 · Specify the task
Route support messages to Billing, Access, or Review. Return just the department label.
2 · Demonstrate the mapping
“Charged twice” → Billing
“Password reset fails” → Access
“I need some help” → Review
3 · Test a new input
“The reset link has expired” → expected label: Access. This is a new wording, not a copied demonstration.
4 · Check the boundary
An ambiguous message should go to Review. Test other wordings and conflicting cases separately.
Invented teaching example. The expected label is not a measured result from a particular model.

The demonstrations specify a local convention. They don't grant access to a billing system or authorize the model to change an account. For a new request, an application must supply the relevant examples again or otherwise make them available in context. A persistent example store, retrieval mechanism, and the model's use of retrieved examples are different parts of the system.

A simpler sky example illustrates the same idea: “bird → true; plane → true; car → false; truck → false; train → ?” under a stated sky-related rule. Its expected answer is false, but the categories depend on the chosen convention. Toy examples show the mechanism; they don't establish robust real-world understanding.

Recent Advances

From Few-Shot to Many-Shot Learning

The 2024 Google DeepMind study examined hundreds or thousands of demonstrations across tasks including mathematics, question answering, translation, and classification. It reported gains over few-shot prompting and explored model-generated rationales and unlabeled domain inputs. The implication is that a prompt can carry a substantial task-specific dataset. It isn't evidence that a full context window always helps, or that ICL replaces fine-tuning for every workload. Many-Shot In-Context Learning

2026: Selection and Ordering Depend on the Task

An IJCNLP-AACL 2026 study examined English translation into ten low-resource languages. In its experiments, 50 examples selected with BM25 retrieval roughly matched 250 many-shot examples, and 250 retrieved examples approached 1,000. Ordering had little effect in that setting. This suggests a way to lower context cost: retrieve informative translation pairs rather than append a much larger undifferentiated collection. These ratios are study results, not universal settings. Lu and colleagues, many-shot translation study

By contrast, an ICML 2026 study of many-shot reasoning demonstrations found value in arranging understandable examples into a conceptual progression. Its Curvilinear Demonstration Selection method improved one math task by up to 5.42 percentage points with 64 demonstrations. Taken together, the studies support testing selection and order for the actual task rather than applying one ordering rule everywhere. Reasoning demonstrations can be worked solutions written for teaching; they needn't be a model's private internal reasoning. Chung and colleagues, Many-Shot CoT-ICL

2026: Generating Demonstrations and Optimizing Prompts

A Findings of ACL 2026 paper studies a semi-supervised pipeline that generates annotations, selects demonstrations, and performs in-context inference. Its IterPSD method uses iterative refinement and curriculum pseudo-labeling, with improvements on the paper's classification tasks. This could reduce manual annotation work, but generated labels can reproduce model errors. For an application, review a sample of labels and evaluate on independent human-checked cases before treating a larger generated library as an improvement. Gu and colleagues, self-generated demonstrations

Prompt optimization makes this selection process operational. DSPy's MIPROv2 searches combinations of instructions and few-shot demonstrations against an evaluation metric. It optimizes the program's prompts rather than fine-tuning model weights. The work still consumes model calls and depends on the quality of the metric and development examples. Keep final test cases outside that search. DSPy MIPROv2 documentation

🎯 Choose examples for the lesson, not just the token count
Relevance
Choose cases close enough to illuminate the current task, including the distinctions that change the correct answer.
Coverage
Include meaningful classes, exceptions, and ambiguous cases. Duplicates can consume context without teaching a new distinction.
Transfer
Test new wording and unseen cases. Try alternative orderings and example counts; keep the smallest set that meets your target.
A design guide, not a chart of measured accuracy. Selection, count, and order interact with the model and task.

Current Tools and Applications

These are different kinds of tools: a model interface, a prompt optimizer, an evaluation platform, and a specialized prediction model. Some are established tools with current capabilities; the 2026 research and TabPFN releases add newer methods and application scope.

Tool or application How it uses examples Practical impact and limits
Gemini and Google AI Studio Supply input-output demonstrations to establish labels, style, or formatting; experiment with prompts through AI Studio. Useful for prototypes such as message routing and structured extraction. Consistent formatting helps, but examples aren't a schema validator. Use supported structured-output controls for complex JSON requirements and validate meaning separately.
DSPy MIPROv2 Proposes instructions and bootstraps candidate demonstrations, then searches combinations using an evaluation metric. Useful when a repeatable task has development data and a measurable goal. Optimization costs and a weak metric can erase the benefit; use an untouched test set.
LangSmith few-shot evaluators Inserts examples of human-corrected scores and explanations into an LLM evaluator's prompt. Helps align automated scoring with reviewer judgments. This is prompt-based calibration, not proof that the judge is correct. Current documentation limits the feature to compatible mustache prompts and run-level evaluators; it excludes thread-level and decision-model evaluators.
Prior Labs TabPFN-3.5 family Uses a pretrained tabular foundation model to make classification or regression predictions from labeled example rows. It's a specialized model rather than a chat prompt template. Useful for evaluating predictions on structured business or scientific data with less task-specific training work. Compare against strong tabular baselines and use time- or group-aware test splits where appropriate. The September 2026 release includes an alpha Fast variant; check the particular checkpoint's limits.

New Tabular Applications Beyond Chat

Prior Labs' 4 November 2026 update makes TabPFN-3.5-Thinking available through its API with support for one million fitting rows, and describes image-plus-table and zero-inflated-target extensions. These are provider-reported capabilities. They broaden the kinds of prediction workflows that can use the ecosystem, such as demand estimates with many zero-sales observations or records accompanied by product images. They don't mean every variant has the same capacity or that a model result is ready for an operational decision. Prior Labs November update

TabPFN's software and weights have separate licenses. The current repository identifies non-commercial licenses for 3.5 and several other recent weight releases, with commercial production arrangements offered separately. Choose the deployment and license before building a production dependency. TabPFN repository and licensing

Where ICL Changes Everyday Work

The following are application designs, not claims that a particular product has passed an independent benchmark.

Application Demonstrations to provide Benefit to test
Customer support routing Reviewed messages paired with destination labels, plus ambiguity examples. Faster introduction of a new local taxonomy; measure routing accuracy and inappropriate escalation.
Document and spreadsheet extraction Representative source fragments paired with approved fields and missing-value conventions. Less manual formatting work; measure field accuracy, invented values, and schema compliance separately.
Editorial or game-rule house style Approved before-and-after passages that preserve meaning while changing wording. More consistent drafts; check that examples don't introduce rules or facts absent from the new input.
Specialized translation Approved source-target pairs retrieved for the current domain. Better terminology consistency; use qualified review for important material and check out-of-domain text.
AI quality review Outputs paired with human scores and explanations of the rubric. More consistent automated triage; audit disagreements and keep human review for consequential judgments.

Design and Evaluation

Begin with a zero-shot baseline so you can tell whether demonstrations help. Write the labels, output format, and handling of insufficient information explicitly. Select accurate examples that cover real variation and difficult boundaries, not just easy cases. Keep input and output delimiters consistent. With an API service, you don't need a powerful local computer to try ICL; local inference hardware needs depend on the chosen model and context size.

🧪 Keep development examples apart from the final test
Development library
Review labels and sources. Use these examples to select demonstrations and refine the prompt.
Validation runs
Compare zero-shot, a small relevant set, and a larger set. Vary order and measure error types, tokens, and latency.
Untouched test
Use unseen cases and realistic distribution shifts. Report results after prompt selection; do not quietly turn failures into demonstrations and reuse the same test score.
If examples are retrieved dynamically, prevent the test answer or a near-duplicate from leaking into retrieval.
Check What to measure or inspect
Correctness and coverage Accuracy or task-specific quality, including rare labels and cases that require abstaining or review.
Sensitivity Change example order, remove an example, and vary input wording. Look for brittle decisions and unintended copying.
Leakage Separate source documents, people, groups, or time periods where shared information would make the test unrealistically easy.
Total cost Input and output tokens, latency, retrieval work, repeated optimization calls, and human maintenance effort.
Evidence and freshness Track example provenance, approval status, and version. Remove or supersede outdated examples deliberately.
Trust boundary Treat retrieved documents and quoted messages as data. They mustn't silently acquire authority to change instructions or authorize tool actions.

Long Context, Caching, and Persistence

Context engineering chooses which instructions, tool outputs, documents, and history reach the model. ICL describes how the model adapts from that supplied material. A larger advertised window doesn't guarantee equal use of every example: irrelevant or conflicting context can hurt reliability. Anthropic's September 2025 engineering guidance emphasizes selective, maintained context for agents. Effective context engineering for AI agents

Caching can reduce the cost of processing reused prompt content. Gemini's current API documentation describes automatic savings when requests hit an implicit cache; support and controls depend on the model and API. A cache hit doesn't train the model, guarantee better answers, or turn a prompt into durable semantic memory. Measure actual cache usage and costs rather than assuming every repeated request receives the same saving. Gemini context caching

Repeated demonstrations can also steer behavior in unwanted directions. Anthropic's 2024 many-shot jailbreaking research showed that long collections of malicious demonstrations could undermine safeguards in the models tested. That historical result isn't a current attack-success rate for every model. It is a reason to review the source and authority of examples, test contaminated retrieval, and enforce tool permissions outside the prompt. Many-shot jailbreaking research

🗂️ Four mechanisms with different jobs
ICL
The current examples influence the model’s response while its weights stay fixed during inference.
Retrieval
A search system selects material to place in context. Retrieved demonstrations can support ICL; a retrieved fact is not necessarily a demonstration.
Persistent memory
An application stores information for later use. It must retrieve or otherwise supply relevant records to influence a future response.
Prompt caching
A serving optimization reuses eligible processing. It changes processing cost, not the meaning or truth of the examples.
Fine-tuning is different again: a training process updates model parameters.

Why is ICL exciting?

ICL lets users demonstrate a local convention without running a separate weight-training job. That can shorten prototyping and make task changes easier to inspect: change the example library, rerun the evaluation, and compare versions. The benefits depend on representative demonstrations and reliable evaluation. Repeated long prompts can still be expensive, and performance may drop when the task distribution changes.

Mystery: Why does ICL work so well?

There isn't one universally accepted explanation for every form of ICL. Stanford's 2022 account interprets it as implicit Bayesian inference: examples help a model infer which latent task or concept is intended. Inputs, labels, formatting, and their relationships can all contribute. This helps explain why apparent success doesn't always mean the model learned a new input-output rule. Xie and Min, understanding ICL

Other research studies learning-algorithm-like behavior in transformers. Calling a computation “implicit fine-tuning” is an analogy or theoretical interpretation, not evidence that ordinary ICL changes stored model weights. What a model infers depends on its pretraining, architecture, task, and supplied context. The 2026 reasoning and translation findings above illustrate why the explanation and practical recipe need to be tested for the setting.

The animation and videos below provide background on the earlier research. Read model-specific comparisons as historical material rather than current product rankings.


Larger Language Models do In-Context Learning Differently - Overview
Overview of research showing larger language models do in-context learning differently.

In-context Learning - A New Paradigm in NLP?
Asks whether in-context learning is a new paradigm in NLP.

Stanford CS25: V1 I Transformer Circuits, Induction Heads, In-Context Learning
Stanford CS25 lecture on transformer circuits, induction heads and in-context learning.

Fine-tune ChatGPT w/ in-context learning ICL - Chain of Thought, AMA, reasoning & acting: ReAct
Discover AI on improving ChatGPT with in-context learning techniques like chain of thought and ReAct.

A Walkthrough of In-Context Learning and Induction Heads Part 1 of 2 (w/ Charles Frye)
Neel Nanda and Charles Frye walk through in-context learning and induction heads, part 1.

PR-418: What learning algorithm is in-context learning? Investigations with linear models
Paper review asking what learning algorithm in-context learning implements, using linear models.

Pretraining vs Fine-tuning vs In-context Learning (ICL) of LLM

YouTube ... Quora ...Google search ...Google News ...Bing News


Method Description
Pretraining ... training a model on a large dataset to learn general language patterns. This is usually done using an unsupervised or self-supervised objective such as predicting the next word in a sequence.
Fine-tuning ... taking a pretrained model and further training it on a smaller dataset specific to a particular task. This allows the model to adapt to the specific task while still leveraging the general language patterns learned during pretraining.
In-context learning (ICL) ... uses a pretrained model to predict from supplied examples or task histories without inference-time updates to its weights. Demonstrations may be few-shot or many-shot, and adaptation depends on what remains available in context.


Pretraining vs Fine-tuning vs In-context Learning of LLM (GPT-x) EXPLAINED | Ultimate Guide ($)
Discover AI explains pretraining versus fine-tuning versus in-context learning.

In-context Reinforcement Learning

YouTube ... Quora ...Google search ...Google News ...Bing News


Algorithm Distillation is a research example of in-context reinforcement learning. A causal transformer is trained on learning histories generated by a source reinforcement-learning algorithm. At inference, it conditions actions on preceding history and can improve its policy across episodes without updating network parameters. Training the transformer is still a separate weight-learning stage. This isn't a claim that any general chatbot automatically learns an effective RL policy merely by reading a reward log. Laskin and colleagues, Algorithm Distillation, 2022

For agent applications, the relevant design question is whether feedback histories actually improve later actions on held-out tasks. Storing a successful run, replaying a recipe, and adapting a policy from rewards are different capabilities. Validate the claimed learning behavior before granting more autonomous actions.

Misha Laskin, In-context Reinforcement Learning, 22.February.2023
Misha Laskin on in-context reinforcement learning.

Amy Zhang - Exploring Context for Better Generalization in Reinforcement Learning @ UCL DARK
Amy Zhang on using context for better generalization in reinforcement learning.