learn-ai-literacy-with-phoebe / Session 6 of 8
Learn AI Literacy with Phoebe · Session 6 of 8

How LLMs work: a next-word machine

The models behind ChatGPT and Claude feel like magic, so people either over-trust or dismiss them. Both are expensive mistakes. This session opens the box: an LLM predicts the next token from a probability list, over and over. Understand that one loop and everything - context windows, temperature, and why they confidently make things up - stops being mysterious.

🟠 Stretch Leaders & practitioners No code 45 min live + self-study
0-3 · Welcome 3-18 · Concepts 18-40 · Apply-along 40-45 · Q&A
Part 0

The demystifying session

Everything you have built so far - neural nets (S2), embeddings (S3), retrieval (S5) - comes together here. A large language model is a very large neural net that turns text into tokens, into vectors, and predicts what comes next. No lookup, no database of answers, no understanding in the human sense. Just a staggeringly good next-token guesser. That framing is the difference between using these tools well and being fooled by them.

Live - presented in session Self-study - practitioner depth ★ Apply-along - interactive, everyone plays Sequel to learn-data-literacy
★ What you walk out with today The one-sentence truth of how an LLM works (predict the next token, repeat), a working feel for the two dials you actually control - context window and temperature - and a clear-eyed understanding of why hallucination is baked into the design, so you stop expecting it to behave like a database.
Part 1 · the whole trick

Next-token prediction 5 min live

Give the model the text so far. It produces a probability for every possible next token (a token is a word or word-piece), picks one, appends it, and runs again. That loop, scaled to billions of parameters trained on much of the internet, is the entire mechanism. It is not retrieving a stored answer - it is predicting, token by token.

Given: The weather today is ___ predict the next token: sunny 34% cold 22% warm 18% rainy 14% nice 12% Pick one -> append -> repeat "The weather today is sunny" then predict the NEXT token, and the next, forever.
🔍 Click to zoom - one prediction step; a whole answer is thousands of these
LivePredicting, not retrieving3 min▶
  • A token is a word chunk. "unbelievable" might be un + believ + able. The model works in tokens, not letters or whole words - which is why it can miscount the letters in a word (self-study).
  • Every step is a probability list. The model does not "know" the answer; it computes how likely each token is to come next given everything so far, then samples one.
  • Fluency is the point, not a side effect. It was trained to make text that sounds like its training data. Sounding right and being right are different goals - hold onto that for Part 3.
Real world

Autocomplete on your phone is a tiny version of the same idea: it guesses your next word from the last few. An LLM is that, scaled up by a factor of billions and fed the internet - enough that "guess the next token" produces essays, code, and arguments. Same loop, wildly different scale.

Self-studyTokens vs words, and the "strawberry" trap2 min read▶

Ask some models "how many r's in strawberry?" and they stumble. Not because they are dumb - because they never see letters. Text is chopped into tokens before the model sees it, so "strawberry" might arrive as a few chunks with no letter-level view. Counting characters is genuinely hard for a system that thinks in tokens. The lesson for practitioners: LLMs are weak exactly where the task lives below the token (spelling, arithmetic digit-by-digit, exact character edits) - route those to a tool (Session 7's agents) instead of trusting the model.

Part 2 · what you actually control

Training vs inference, context, temperature 5 min live

Two moments matter: training (once, expensive, bakes patterns into the weights) and inference (every time you prompt it). At inference you control two dials that decide almost everything about the output: how much it can see (context window) and how boldly it strays from the safest token (temperature).

TRAINING · once, months, millions of dollars Most of the internet books, code, web, forums Frozen weights patterns baked in, fixed INFERENCE · every prompt, seconds, cents Your prompt + context window (memory) Frozen weights run temperature sets boldness Tokens out your answer, one at a time The weights never change when you chat. "Learning from our chat" is a myth.
🔍 Click to zoom - trained once, used endlessly; only the prompt and dials change per call
LiveContext and temperature, in plain terms3 min▶
  • Context window = short-term memory. Everything the model can "see" at once - your prompt, the conversation, any documents you paste. Past the limit, earlier content falls out of view. Bigger windows (now hundreds of pages) changed what is possible, but they are not infinite and cost more.
  • Temperature = boldness. Low temperature almost always grabs the top token (focused, repetitive, good for facts). High temperature flattens the odds so unlikely tokens can win (creative, surprising, riskier). You will feel this in the widget.
  • The weights are frozen at inference. ChatGPT does not learn from your conversation in real time. Genuinely updating the model means retraining or fine-tuning (Session 7) - a deliberate, separate act.
The exec move When output is too samey, raise temperature; too wild or off-task, lower it. When it "forgets" what you said earlier, you have hit the context window - not a bug, a budget. Both are dials, not defects.
Self-studyWhy the model does not know last week's news2 min read▶

Training has a cutoff date - the model only saw data up to some point, then its weights froze. Anything after that simply is not in there. That is why models get recent events wrong or refuse them, and why grounding matters: to answer about your latest data or today's news, you feed it in at inference time via the context window (paste it, or retrieve it with RAG from Session 5). The model supplies fluency and reasoning-shaped patterns; you supply the current facts. Confusing "it was trained on a lot" with "it knows everything now" is a top source of trust errors.

Part 3 · the built-in failure

Why they hallucinate 5 min live

A hallucination is a confident, fluent, wrong answer. It happens because the model optimizes for plausible next tokens, not for truth - and it has no built-in fact-checker. When it does not "know", it does not stop; it generates the most likely-sounding continuation, which can be a convincing fabrication. This is a property of the mechanism, not a bug you can fully patch. So you design around it.

"Fluent but false" confident cited case that never existed Optimizes plausibility, not truth. No internal fact-checker. Ground it (RAG) feed real documents at inference - Session 5 Human in the loop a person checks before it counts Evals test against known answers - Session 7
🔍 Click to zoom - you do not cure hallucination, you contain it
LiveDesign around it, do not wish it away3 min▶
  • Fluent and confident is not evidence. The model has the same smooth tone whether it is right or inventing. Never read confidence as accuracy.
  • Ground it. Give the model the real facts in the prompt (paste them, or retrieve with RAG). It is far more reliable summarizing what you handed it than recalling from training.
  • Keep a human on high-stakes output. Legal, medical, financial, anything published in your name - a person verifies before it counts. Session 8 makes this a governance rule.
  • Measure it. Evals (Session 7) tell you the real error rate on your task, so "seems fine" becomes a number you can manage.
Real world

In 2023 two lawyers filed a brief citing six court cases an LLM had invented, complete with fake quotes and citation numbers. The model was not malfunctioning - it produced plausible-looking legal text, which is exactly what it does. The failure was trusting fluency without verification. A grounding step or a human check would have caught all six.

Self-studyTransformers and attention, in one honest paragraph3 min read▶

The architecture behind modern LLMs is the transformer (2017, "Attention Is All You Need"). Its key trick is attention: for each token it is about to predict, the model weighs which earlier tokens matter most and how they relate - so "it" in a sentence can attend to the noun it refers to twenty words back. Stacking many attention layers lets the model track long-range structure in language, which is why transformers blew past the older sequence models (RNNs/LSTMs) that struggled to remember far back. You do not need the math; you need the intuition: attention is the mechanism that lets a next-token predictor stay coherent across a long passage. That coherence is why it feels like understanding - and why it is easy to over-trust.

Apply-along 1 of 3

Be the LLM ★ 10 min · everyone plays

Build a sentence one token at a time, straight from the probability list - then move the temperature dial and watch the odds change shape. This is the whole mechanism in your hands.

The debrief At low temperature the top token dominates - predictable, safe, a little boring. Crank it up and long-shot tokens start winning: more creative, and exactly where nonsense sneaks in. You just felt the dial behind both "why is it so bland?" and "why did it make that up?".
Apply-along 2 of 3

Rank the hallucination risk ★ 6 min · everyone judges

Four tasks: (a) summarize a document you paste in, (b) cite a specific court case from memory, (c) brainstorm 20 product names, (d) state a medication dose.

Rank them by hallucination danger. Ask for each: is the model grounded in facts you gave it, or recalling from training? Is the output verifiable? What is the cost of being wrong?

Land the pattern: grounded + low-stakes + easy-to-verify (summary, brainstorm) is safe; recall + high-stakes + hard-to-verify (case citation, dose) is dangerous - and needs grounding plus a human.

Map one real task from your work onto this spectrum. Decide its guardrail now.

Apply-along 3 of 3

Budget the context window ★ 6 min · everyone plans

Take a real big-input task: "analyze this 100-page contract" or "answer from our 500-page handbook".

The whole thing will not fit in one context window. List your options: paste the most relevant sections only, or retrieve the right chunks on demand (RAG, Session 5) and feed just those.

Notice the realization: the quality ceiling is set by which chunks you retrieve, not by the model. Retrieval quality = answer quality.

Write one line: for your task, how would you get the right few pages in front of the model? That sentence is your S7 starting point.

Real world

"We fed the AI our whole wiki and it still gave wrong answers" almost always means the retrieval picked the wrong chunks, not that the model is weak. The context window is a small stage - what you put on it is the job.

After the session

This week ◐ 25 min total

Check yourself

Three questions before you go 🎯 ◐ 90 seconds

1 · At its core, what does a large language model actually do?

It is a next-token predictor scaled up enormously. No lookup, no stored answers, no human-style reasoning - just probability over the next chunk of text, again and again.

2 · Output is coming out bland and repetitive. Which dial do you reach for?

Temperature is boldness. Low = safe and samey, high = creative and riskier. Context window is about how much it can see, not how adventurous it is.

3 · Why do LLMs hallucinate confident, wrong answers?

Hallucination is a property of how the mechanism works. Bigger models hallucinate less but never zero. You contain it with grounding, human review, and evals.

Source material

Concepts covered & where they come from

Leaders get the working model; practitioners get the Self-study lane and the names to go deeper.

✓Next-token predictionthe core loop, tokens, sampling - Part 1 + Apply-along 1
✓Training vs inference, context window, temperaturethe two dials you control - Part 2 + Apply-alongs 1 and 3
✓Hallucination and its three mitigationswhy it happens, RAG / human / evals - Part 3 + Apply-along 2
◐Transformers & attention (2017)self-study card - the architecture, practitioner depth
◐Tokens vs words, training cutoffself-study cards - where the model is structurally weak

Session 6 cheat sheet · pin this

The whole trickPredict the next token from a probability list, append it, repeat. Not lookup, not understanding - prediction at scale.
TokensText is chopped into word-pieces before the model sees it. That is why it miscounts letters - route spelling/math to a tool.
Training vs inferenceTrained once (frozen weights); used every prompt. It does not learn from your chat in real time.
Two dialsContext window = how much it can see at once. Temperature = how boldly it strays from the top token.
HallucinationOptimizes plausibility, not truth. Fluent + confident does not mean correct. Built-in, not a bug.
Contain itGround it (RAG), keep a human on high stakes, and measure with evals. You do not cure it - you design around it.