LLM FundamentalsQwen2.5-0.5B-Instruct · transformers 5.17 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
18 small wins to finish your pathNext lesson

Few-shot prompting: showing examples

Describing a task only goes so far. Showing a few solved examples as earlier turns of the conversation often works better, especially for small models.

This lesson reuses reply from lesson 9 and tickets and structured from lesson 10.

Example
examples = [
    {"role": "user", "content": "You took money from my card two times"},
    {"role": "assistant", "content": '{"category": "billing", "priority": 4}'},
    {"role": "user", "content": "Where is my delivery? It is a week late"},
    {"role": "assistant", "content": '{"category": "shipping", "priority": 3}'},
    {"role": "user", "content": "Can I change the email on my account?"},
    {"role": "assistant", "content": '{"category": "other", "priority": 2}'},
]

Three made-up tickets, one per category, each followed by the answer you want. They go between the system prompt and the real ticket, so the model reads them as a conversation it has already had. None of them is one of the five test tickets; examples copied from the test would make the score meaningless.

Example
for text, expected in tickets:
    messages = [{"role": "system", "content": structured}, *examples, {"role": "user", "content": text}]
    answer = reply(messages)
    print(f"{expected:9} {answer}")

*examples spreads the list's items into the new list, the way * spread a list into gather in Python for AI.

Four of the five are now right. The password ticket is still filed as billing. The examples moved the model a long way, and they did not make it reliable.

Why it helped

Remember lesson 3: every token in the context shifts the next-token probabilities. Three answers where a delivery complaint was followed by shipping make shipping likelier after the next delivery complaint. The model is not learning in the training sense; its weights are unchanged. It is continuing a pattern it can see.

Try it yourself
  • Add a fourth example about a password or login, with other, and run it again.
  • Put the examples in a different order.
  • Remove the system prompt and keep only the examples.

Little by little, you're building something great.