Foundation Models and Their Training Data
The model is a foundation model that has learned from a massive amount of data during training.
Two Words That Seem to Mean the Same Thing
Anyone who reads about prompting large models quickly picks up a simple picture. The prompt is what you type. The context is something extra you add to it. The examples you include are a kind of context. Under this picture, prompt and context are close to synonyms, and the terms zero-shot and few-shot sound like labels for how much background you supply. Before reading on, make a guess: do you think prompt and context always name the same thing?
What do you think happens?
Do the words prompt and context always mean the same thing when people write about foundation models?
Reveal answer
No, different authors use them with different meanings
The vocabulary in this area is used inconsistently. Some authors use context for the entire input, others for the background information the model needs, and others for text that shapes the response over a conversation.
The picture is partly right and partly misleading. This article tests it, because a learner who assumes one fixed meaning will misread a good deal of documentation. The goal is to build a precise vocabulary first, then follow what happens inside a model when a prompt is processed.
Three Meanings of Context
The GPT-3 paper by Brown and colleagues, published in 2020, used the word context for the entire input given to a model. Under that usage, context and prompt name the same thing. The word is also used to mean contextual information, which is the material a model needs in order to carry out what the prompt asks. A third usage appears in Google's PaLM 2 documentation, which describes context as the text that shapes how the model responds throughout a conversation. That documentation gives examples such as words the model may or may not use, topics to focus on or avoid, and the required response format or style. Taken literally, that definition makes context very close to a task description.
Why does this matter? The mix-up is more than a matter of taste, because one sentence can be read in different ways. Consider the sentence 'the context is too long.' It might mean that the whole input is too long, or that the background material is too long. These two readings lead to different fixes. Shortening the background material does nothing if the real problem is the length of the whole input, and vice versa.
Prompt: the whole input into the model. Context: the information provided so that the model can perform a given task. This is the convention used in this course. Other authors may use the words differently, so check which meaning an author intends.
Where the Prompt and Context Sit
Under the course convention, the context is a part of the prompt, not a separate thing sitting beside it. The diagram below shows one way to arrange the parts of a prompt. The whole prompt contains a context section, which holds the task-relevant information such as instructions and examples, and a query, which is the input the model is asked to answer. The source does not give a fixed layout, so treat this arrangement as one reasonable way to see the nesting.
How In-Context Learning Works
In-context learning is the name for a model learning from the prompt and then performing a task based on it. The model is a foundation model that has learned from a massive amount of data during training. What is notable is that the prompt itself, rather than any further training, determines which task the model carries out. The same underlying model can answer very different requests depending on what the prompt contains.
Read the diagram as a flow. The prompt and the broad knowledge from training meet inside the model. The prompt does not add new knowledge in the sense of retraining; instead it selects which behavior appears in the output. This is why a single model can translate, summarize, or classify, depending on the examples and instructions it receives.
Counting Shots in a Prompt
A shot is one example placed in the prompt. Few-shot learning uses examples placed in the prompt, and zero-shot learning uses none. A prompt with five examples is called 5-shot learning. The number of shots is a count of the worked examples inside the prompt, not a count of how many times the model has been trained.
In the zero-shot column, the model receives the task and the query and nothing else. In the few-shot column, the same task is followed by several worked examples before the query. Each example is a shot. The query stays unanswered in both cases, because the model's job is to produce the answer for it.
Worked Example: Sentiment Labels with Shots
Labeling Customer Messages Two Ways
You want a model to label a customer message as positive, negative, or neutral. Compare a zero-shot prompt with a 3-shot prompt for the same task.
- 1Write the zero-shot prompt
Give the instruction and the query only: Label the following message as positive, negative, or neutral. Message: The package arrived two days late. No examples are included, so this is a zero-shot prompt.
- 2Add three labeled examples
Insert three shots before the query, each with an input and its correct label, such as Message: Great service, thank you! Label: positive. Message: The app keeps crashing. Label: negative. Message: The store opens at nine. Label: neutral. There are three shots, so this is 3-shot learning.
- 3Place the unanswered query last
End the prompt with Message: The package arrived two days late. Label: and leave the label blank. The model reads the examples as a pattern and produces the label for the final message.
- 4Compare what the model receives
The zero-shot prompt contains the task and one message. The 3-shot prompt contains the same task, three labeled examples, and the same message. Nothing about the model has changed; only the contents of the prompt differ.
The zero-shot prompt relies only on the instruction and the model's broad knowledge. The 3-shot prompt adds three demonstrations of the labeling format, which is the kind of change in-context learning responds to. Whether the extra examples help enough to justify their length depends on the model and the task.
Mechanism Check: What the Model Actually Receives
Before you move on, trace the state. Start with a prompt that has no examples. The model receives the instruction and the query, and its output is produced from those contents plus training. Now add one example in front of the query. The input has changed, but the model's weights have not. The only thing that changed is what the model reads. Predict what happens if you keep adding examples: which part of the process changes, and which part stays fixed?
What do you think happens?
If you add a fifth worked example to a prompt that had none, and you do not change the model, what is the new prompt called?
Reveal answer
5-shot learning
A prompt with five examples is called 5-shot learning, and the count refers to examples inside the prompt rather than training runs.
Choosing How Many Shots to Use
There is no universal count of examples. The right number depends on the model and the application. The general pattern is that more examples help a model learn better. The limit is the model's maximum context length, because every example uses space in the prompt. More examples also make the prompt longer, which raises the inference cost of each request. For this reason, you will usually need to experiment to find the number that works for your task.
| Choice | Effect on prompt length | Effect on cost per request | Constraint to watch |
|---|---|---|---|
| Zero shots | Shortest prompt: instruction and query only | Lowest from the prompt side | Model may not follow the format without guidance |
| A few shots | Grows with each example added | Rises as examples are added | Must stay under the maximum context length |
| Many shots | Long; uses much of the available space | Highest; each example adds to every request | Can reach the context limit and leave little room for the query |
Trade-offs as the number of shots increases
Benefit is not uniform. For GPT-3, few-shot learning showed a significant improvement over zero-shot learning. In the use cases of a 2023 Microsoft analysis, few-shot learning gave only limited improvement on GPT-4 and a few other models. One reading of that result is that more powerful models are better at understanding and following instructions, so they need fewer examples. The source cautions that such a study may underestimate few-shot examples in domain-specific work. For instance, if a model has seen few examples of the Ibis dataframe API in its training data, adding Ibis examples to the prompt can still make a large difference.
Mistakes Learners Make with Prompts and Shots
Common mistake Assuming prompt and context always mean the same thing
What it looks likeReading a document that says the context is too long and assuming only the background material is the problem.
Why it failsAuthors use context for the whole input, for task-relevant information, or for conversation-shaping text. The sentence can point to different parts of the input.
Do this insteadUnder this course's convention, prompt is the whole input and context is the information needed for the task. Check which meaning the author intends.
Common mistake Counting training runs as shots
What it looks likeSaying a model is 5-shot because it was trained on five datasets.
Why it failsThe number of shots counts worked examples inside the prompt, not training runs.
Do this insteadCount only the labeled examples placed in the prompt before the query.
Common mistake Believing more examples always help
What it looks likeAdding twenty examples to every prompt without checking the length of the prompt or the cost.
Why it failsMore examples generally help, but they are limited by maximum context length and raise inference cost, and the benefit varies by model and application.
Do this insteadExperiment with a small number of shots, measure the result, and increase only while the gain justifies the added length.
Common mistake Treating a zero-shot result as a failure of the model
What it looks likeConcluding a model cannot do a task because it failed without examples.
Why it failsZero-shot learning uses no examples, and capable models may follow instructions well without them, while other models may need demonstrations.
Do this insteadCompare zero-shot and few-shot results for the specific model and task before deciding which setting to use.
Practice: Classify Your Own Prompt
Write two prompts for the same task: sorting support tickets into billing, technical, or other. The first prompt should be zero-shot. The second should contain exactly three shots before the query. For each prompt, state how many shots it contains, identify the query, and describe what the model receives that the other prompt does not. Then state one reason you might still choose the zero-shot version.
Hints
- A zero-shot prompt contains no examples, only the instruction and the query.
- Each labeled input-output pair you place before the query is one shot.
- Think about prompt length and inference cost when weighing the two versions.
Key Takeaways
- The words prompt and context are used inconsistently; in this course, prompt is the whole input and context is the information needed for the task.
- A shot is one example placed in the prompt: few-shot learning uses examples, and zero-shot learning uses none.
- In-context learning means a foundation model performs a task based on the prompt, with the prompt selecting the behavior without any further training.
- The number of examples is limited by maximum context length and raises inference cost, and the benefit varies by model and application, so experimentation is usually needed.