Lesson 5 / 27

Few-Shot Prompting: In-Context Learning

Teach a pattern with examples placed in the prompt.

The model adapts without any weight change

Large models can pick up a pattern from a few examples in the prompt (in-context learning). Nothing is trained: the examples are part of the input, so they are sent and paid for on every call and use context window. It is the best first move: immediate, needs few examples, easy to change. Limits: more examples cost more tokens, results depend on which examples and what order, and gains flatten. Choose diverse, representative, correct examples, include hard cases, and test the choice on your evaluation set.

Examples in the prompt versus examples in the weights

Few-shot prompting learns instantly from a handful of examples but plateaus; training can use many more.

Three ideas: show, plateau, cost.
Figure 2.1 — Show, plateau and cost.

A few-shot prompt (illustrative)

Three examples teach labels and format. Not run here.

Classify each support ticket as billing, technical or other. Reply with the label only.

Ticket: "I was charged twice this month."       Label: billing
Ticket: "The app crashes when I open settings."   Label: technical
Ticket: "Do you have an office in Pune?"           Label: other

Ticket: "My invoice shows the wrong amount."      Label:

Test example order

Shuffle the example order and compare scores; a big swing means the prompt is fragile and needs better examples.

Quick check: What does in-context learning mean?

  • The model retrains overnight
  • The model adapts to a pattern from examples in the prompt, with no weights changed
  • The model reads the internet live
  • The model forgets its training
Answer

The model adapts to a pattern from examples in the prompt, with no weights changed — Examples in the prompt steer behaviour only for that call.