No history yet

Introduction to In-Context Learning

Learning on the Fly

Imagine showing a friend a few postcards. On the back of the first, you've written "Paris - France." On the second, "Tokyo - Japan." Now, you hand them a third postcard from Rome and ask, "Where is this from?" Without any prior geography lessons, they'll likely guess "Italy."

This is the core idea behind in-context learning (ICL). It's a remarkable ability of modern artificial intelligence, particularly large language models (LLMs), to learn a new task simply by seeing a few examples provided in the prompt. There's no need for a long, grueling training session. The model learns on the spot, using the context you give it.

Prompt

noun

The input, often text, given to an AI model to instruct it or ask it a question.

Large language models are the engines that make in-context learning possible. These are massive neural networks trained on vast amounts of text and data from the internet. This extensive pre-training gives them a broad understanding of language, patterns, and concepts. It's like they've read a giant library, so they already have the raw knowledge to connect "Rome" with "Italy."

In-context learning taps into this pre-existing knowledge. The examples in the prompt act as a guide, showing the model how to apply what it already knows to your specific, immediate task. It’s not learning a new fact; it's learning a new pattern or format.

Lesson image

A Different Kind of Training

To appreciate why ICL is so significant, it helps to understand how AI models traditionally learned. For decades, the standard approach was a long and expensive process. Researchers would collect a massive, specialized dataset for a single task, like identifying spam emails. They would then train a model on this data for hours, days, or even weeks. Once the training was complete, the model was essentially frozen. It was an expert at its one job, but it couldn't adapt to anything new without starting the whole process over again.

A later improvement called fine-tuning allowed developers to take a pre-trained model and tweak it on a smaller, specific dataset. This was faster than training from scratch, but it still required a separate dataset and a retraining phase for every new task.

In-context learning changes the game entirely. There is no retraining. There is no fine-tuning. The model’s underlying parameters don't change at all. It simply uses the examples in the prompt as a temporary guide for how to behave for a single response.

This makes LLMs incredibly versatile. You can teach one to adopt a certain personality, translate between languages in a specific style, or extract data in a custom format, all by crafting a clever prompt. The learning is temporary, lasting only for that one interaction, but it's fast, cheap, and accessible to anyone who can write instructions.

Scaling large language models (LLMs) leads to an emergent capacity to learn in-context from example demonstrations.

Evolution Not Revolution

The idea of learning from examples isn't brand new. Early AI research explored similar concepts. However, older models lacked the scale and complexity to make it truly effective. They could handle very simple patterns, but they couldn't generalize in the human-like way today's models can.

The breakthrough came with the development of the transformer architecture and the massive increase in available data and computing power. This combination allowed researchers to build the first true large language models. They discovered, somewhat unexpectedly, that as these models got bigger and were trained on more data, the ability for in-context learning simply emerged. It wasn't explicitly programmed in; it was a natural consequence of the model developing a deep, flexible understanding of language.

Lesson image

This emergent ability is what makes ICL so powerful. It signifies a shift from designing specialized, narrow AI for each problem to using general, adaptable models that can learn on the fly. It's a foundational concept that opens the door to more dynamic and intuitive ways of interacting with artificial intelligence.

Ready to check your understanding?

Quiz Questions 1/5

What is the core concept of in-context learning (ICL)?

Quiz Questions 2/5

How does a large language model (LLM) accomplish in-context learning?

In-context learning represents a fundamental shift in how we build and use AI, moving us closer to more flexible and powerful systems.