Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 3.3 — Examples in the Prompt (Few-Shot)
LLM Engineering · Example 1 of 1

Zero-shot vs few-shot, and the order trap

The fake model picks the label of the example with the most words in common, and falls back to the last example when nothing matches.

Showing the model two or three solved examples often works better than explaining the rule in words. Zero-shot has none, one-shot has one, few-shot has several. Which examples you pick, and their order, change the answer.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write build_shots(examples) that turns a list of (text, label) pairs into a list of chat messages, alternating user and assistant.

02

Write label_counts(examples) that returns a dictionary of how many examples have each label, to check whether the examples are balanced.

Explain it without notes

01

What is few-shot prompting, and when is it better than writing instructions?

02

What are recency bias and majority label bias, and how do you reduce them?

03

Why must the test set be different from the examples in the prompt?

Zero-shot vs few-shot, and the order trap
Sign in to run this example in your browser.

Expected output

"my parcel is late": zero-shot=Hard to say, maybe billing. | few-shot=shipping | reversed order=shipping
"charged me twice": zero-shot=Hard to say, maybe billing. | few-shot=billing | reversed order=billing
"hello there": zero-shot=Hard to say, maybe billing. | few-shot=other | reversed order=shipping