Hello! Welcome to the first lesson of our new module, "LLM Interaction: Prompting and In-Context Learning."
Introduction
In our previous module, we focused on aligning and evaluating Large Language Models, culminating in a discussion on how platforms like Chatbot Arena use human preference to rank models. Those methods primarily concern the model's training and post-training phases. Now, we pivot from shaping the model's internal weights to guiding its behavior at inference time. How can we interact with a pre-trained model to elicit the exact response we need, without any further training?
This brings us to today's topic. Your learning outcome is to apply zero-shot and few-shot prompting for in-context learning. We will explore the powerful technique that allows LLMs to "learn" new tasks on the fly, just from the examples we provide in the prompt.
We will cover:
- The fundamental concept of In-Context Learning (ICL) and how it differs from traditional fine-tuning.
- The definitions and applications of zero-shot, one-shot, and few-shot prompting.
- A look at the theoretical hypotheses explaining why ICL works.
- Practical strategies for structuring prompts, especially to get structured outputs like JSON.
1. The Paradigm Shift: From Fine-Tuning to In-Context Learning
With models like BERT, the standard workflow was to take a pre-trained model and then fine-tune it on a labeled dataset for a specific task (e.g., sentiment analysis). This process involves updating the model's weights through gradient descent.
However, the introduction of massive-scale models like GPT-3 revealed a new, emergent capability: In-Context Learning (ICL). These models can perform tasks they were never explicitly trained for, simply by being shown a few examples within the prompt itself. This "learning" happens at inference time, with no gradient updates or changes to the model's parameters.
To understand this paradigm shift and the original context in which it was discovered, let's watch a video explaining the seminal GPT-3 paper.
GPT-3: Language Models are Few-Shot Learners (Paper Explained)
The video 'GPT-3: Language Models are Few-Shot Learners' by Yannic Kilcher provides a fantastic explanation of the paper that introduced In-Context Learning to the world. We'll focus on the parts that contrast the old fine-tuning approach with this new method and define the different types of prompting.
Please watch the following two segments: From 01:14 to 07:44: This section contrasts the traditional pre-training/fine-tuning paradigm with GPT-3's approach, which avoids gradient updates. From 07:44 to 15:22: This is the core of the lesson. It provides a detailed, visual explanation of what zero-shot, one-shot, and few-shot learning mean by showing exactly how a prompt is constructed for each case. Pay close attention to how the task description and examples are just a single string of text fed to the language model.
As the video explains, the model isn't being "trained" in the traditional sense. It's simply treating the examples as part of a long text sequence and using its powerful pattern-recognition abilities to predict what should come next, effectively completing the task.
2. Zero-Shot, One-Shot, and Few-Shot Prompting
Let's formalize the three main prompting techniques derived from In-Context Learning. The key difference is the number of examples, or "shots," you provide in the prompt.
Zero-Shot, One-Shot, and Few-Shot Prompting
The article 'Zero-Shot, One-Shot, and Few-Shot Prompting' from LearnPrompting.org offers a clear, side-by-side comparison that makes the distinction between these methods very intuitive.
Read the sections titled 'What is Zero-Shot Prompting?', 'What is One-shot Prompting?', and 'What is Few-Shot Prompting?'. Notice how they apply each technique to the exact same task (sentiment classification), which clearly illustrates the progression and the impact of adding examples.
To summarize the concepts from the article:
- Zero-Shot Prompting: You provide a task description but no examples. The model must rely entirely on its pre-trained knowledge.
- Example:
Classify the following text as positive, negative, or neutral. Text: I think the vacation was okay. Sentiment:
- Example:
- One-Shot Prompting: You provide one example to demonstrate the task format and context.
- Example:
Classify... Text: The product is terrible. Sentiment: Negative. Text: I think the vacation was okay. Sentiment:
- Example:
- Few-Shot Prompting: You provide two or more examples. This allows the model to better infer the pattern, handle more complex tasks, and adhere to a specific output format.
Here's a great visual summary of a few-shot prompt for a customer service classification task:

3. How Does In-Context Learning Actually Work?
The simple explanation is that LLMs are incredibly powerful sequence processors and pattern matchers. The provided examples create a strong contextual pattern that guides the model's prediction for the final, incomplete part of the sequence.
However, the deep mechanisms are still an active area of research. There are two leading hypotheses that offer a more profound explanation, which will likely resonate with your AI/ML background.
What Is In-Context Learning in Deep Learning?
The video 'What Is In-Context Learning in Deep Learning?' by Deep Learning with Yacine explores the fascinating theories behind this phenomenon.
Watch the following two segments to get a glimpse into the current research: Hypothesis 1 (03:11 - 04:55): This explains the Bayesian framework, where the model infers a 'latent concept' from the prompt examples and retrieves similar concepts learned during pre-training. Hypothesis 2 (07:11 - 09:20): This covers the idea that Transformers might be implicitly implementing learning algorithms, using components like 'induction heads' to perform on-the-fly learning without changing weights.
The second hypothesis, that Transformers can implement simple learning algorithms implicitly, is particularly compelling. It suggests that scaling up these models has led to an emergent ability that resembles symbolic reasoning and on-the-fly learning, moving beyond simple memorization.
4. Practical Applications and Structured Output
The true power of few-shot prompting, especially for a developer, lies in its ability to control the structure of the output. While you can describe the desired format in a zero-shot prompt (e.g., "Provide the answer in JSON format"), showing the model a few examples is often far more reliable.
Zero-Shot, One-Shot, and Few-Shot Prompting
Let's return to the LearnPrompting.org article to see how this works in practice, particularly for getting structured data.
Read the section 'Deep Dive into Few-Shot Prompting'. Pay special attention to the subsections on 'Information Extraction', 'Content Creation', and, most importantly, 'Few-Shot Prompting for Structured Outputs'. Notice how changing the format of the examples (e.g., from input: classification to input: {"label": "classification"}) directly changes the model's output format.
This ability to enforce a specific output structure (like a bulleted list, key-value pairs, or a JSON object) is invaluable for building robust applications on top of LLMs. It makes the model's output predictable and programmatically parsable, which is essential for integrating the LLM into a larger software pipeline.
Test your understanding!
Your task is to extract key information about a character from a short description from a light novel. You want the output to be a clean JSON object.
Design a few-shot prompt to extract the name, class, and a key skill from the following new text:
New Text: The swordsman known as Kirito, a dual-wielding Beater, was famous for his unique skill, Starburst Stream.
Your prompt should include at least two examples before the new text.
Show answer
Here is an example of an effective few-shot prompt. The key is that the examples establish a clear and consistent Input -> Output (JSON) pattern.
Prompt:
Extract the character's name, class, and a key skill into a JSON object.
Input:
Ainz Ooal Gown, the Overlord of Nazarick, could cast the super-tier spell 'Fallen Down'.
Output:
{
"name": "Ainz Ooal Gown",
"class": "Overlord",
"skill": "Fallen Down"
}
Input:
The Shield Hero, Naofumi Iwatani, is known for his defensive ability, Air Strike Shield.
Output:
{
"name": "Naofumi Iwatani",
"class": "Shield Hero",
"skill": "Air Strike Shield"
}
Input:
The swordsman known as Kirito, a dual-wielding Beater, was famous for his unique skill, Starburst Stream.
Output:
The model would see this pattern and generate the following JSON object:
{
"name": "Kirito",
"class": "Beater",
"skill": "Starburst Stream"
}
5. Choosing the Right Technique
When should you use each method? Here is a simple guide:

- Use Zero-Shot for simple, common tasks where the model likely has strong pre-existing knowledge (e.g., summarizing a generic article, answering a simple factual question). It's fast and token-efficient.
- Use One-Shot when the task is simple but might have an ambiguous format. A single example can clarify your expectations.
- Use Few-Shot for more complex or novel tasks, or when you require a specific, reliable output structure. The examples provide the necessary guidance, but come at the cost of using more of the model's limited context window.
Conclusion
Today we've explored the foundational techniques for interacting with modern LLMs at inference time. You've learned how to guide a model's behavior without updating its weights, a powerful and efficient way to adapt a general-purpose model to specific needs.
Key Takeaways:
- In-Context Learning (ICL) allows a model to "learn" a task from examples provided directly in the prompt, representing a paradigm shift from traditional fine-tuning.
- Zero-shot prompting gives instructions without examples and is best for simple, well-understood tasks.
- Few-shot prompting provides multiple examples to guide the model on more complex, novel, or structurally-demanding tasks. One-shot is a special case with a single example.
- The ability to enforce structured output (like JSON) via few-shot examples is a critical skill for building reliable, production-level AI applications.
- While ICL appears magical, it is rooted in the model's pattern-matching capabilities, with ongoing research exploring deeper mechanisms like implicit algorithm implementation.
Preview of the Next Lesson:
While few-shot prompting helps a model understand what to do, it doesn't always help it perform complex multi-step reasoning. What if the task isn't just pattern matching, but requires a logical sequence of steps to arrive at the correct answer?
In our next lesson, we will build directly on today's concepts to explore Chain-of-Thought (CoT) prompting, a revolutionary technique that encourages the model to "think step by step" to dramatically improve its reasoning abilities.