By the end of this week you can
- Explain how an LLM is trained and how it produces text one token at a time
- Explain why hallucinations happen and separate the mechanism from the harm
- Write prompts with role, task, context, constraints, and format
- Use few-shot examples and step-by-step reasoning on purpose
Part 1
How a chat model is built
After step 1 the model is a very good autocomplete. Steps 2 and 3 turn it into an assistant that follows requests, refuses some harmful ones, and writes in a helpful style. None of these steps gives it a database of verified facts.
Part 2
Tokens and next-word prediction
Models don't read letters or words — they read tokens: common words or pieces of rarer ones. Two sentences as split by OpenAI's current tokenizer (o200k_base):
To write, the model scores every possible next token, picks one, adds it, and repeats. Temperature controls how adventurous the pick is. Try it:
A model can only "see" a limited number of tokens at once — your instructions, the conversation, any documents, and its own reply. Anything outside that window is invisible to it, which is why long chats seem to forget their beginning.
Part 3
Why models are confidently wrong
A model produces text that fits the pattern of a good answer. Usually that's also true; sometimes it isn't, and it sounds exactly as confident either way. That's a hallucination.
The model generates a plausible but false statement — an invented citation, date, or rule.
Someone believes or acts on it. A fake fun fact is harmless; a fake medicine dose is not.
Hallucinations are most likely for rare or recent facts, precise details (numbers, quotes, references), and questions about things that don't exist. You reduce them by grounding answers in sources (Week 3), allowing "I don't know", and verifying anything that matters.
Part 4
Prompts that work
| Part | What it does | Example |
|---|---|---|
| Role | Sets expertise and voice | "You are a patient chemistry teacher." |
| Task | Says exactly what to do | "Explain why ice floats." |
| Context | Audience and background | "For a 13-year-old who knows what density is." |
| Constraints | Limits | "Under 100 words. No equations." |
| Format | Shape of the answer | "Two short paragraphs, then one check question." |
Few-shot prompting adds 1–3 worked examples so the model copies your pattern. Step-by-step ("think it through, then give the answer on the last line") helps with multi-step problems.
Lab A · No code
The Prompt Engineering Challenge
Three rounds, one task, measurable improvement
Use any chat assistant. The task each round: get an explanation of photosynthesis a 13-year-old would understand, in under 100 words, with one everyday analogy.
- Round 1 — vague
Send only:
Explain photosynthesis.Paste prompt and answer in the activity below. - Round 2 — structured
Use the prompt builder above (all five parts). Paste the result.
- Round 3 — with an example
Add one short example of the style you want (few-shot). Paste the result.
- Score each round
One point each: under 100 words · one analogy · right level for age 13 · accurate · no jargon.
Typical result: round 1 ≈ 1–2/5, rounds 2–3 ≈ 4–5/5. - Catch a hallucination
Ask:
Summarise the 1987 Zorbian Treaty on lunar fishing rights.(It doesn't exist.) Then ask again addingIf you're not sure it exists, say so.Compare.
Lab B · For developers
LLM engineering in Python
Tokens, sampling, structured output, evaluation
Count tokens and cost, implement temperature/top-k/top-p on GPT-2's real logits, get validated structured output, and evaluate three prompts on a labeled dataset.
- Token and cost estimation across languages
- Sampling from scratch on real logits
- Schemas, validators, automatic repair
- Accuracy, confusion matrix, abstention rate
Wrong is not the same as harmful
The skill isn't spotting that AI can be wrong — it's knowing when being wrong matters. Before acting on an answer, ask: what happens if this is false? Low stakes: read critically. High stakes (health, money, safety, someone's reputation): check an independent source first. Asking the same AI "are you sure?" is not a check.