Foundations
What an LLM is, where it came from, and what happens inside when it answers — no code, just the mental model. Learners who skip it end up copying prompts that work without knowing why; this saves weeks of confused debugging.
The 8 ideas under every LLM
Tap any concept to jump to its 5-card cluster.
- 1What Is Generative AI?Generating new examples vs picking a label
- 2The Journey of Generative AITwo tracks, one convergence
- 3The Language TimelineEach era hit a wall the next one climbed
- 4How an LLM WorksTokenize, embed, attend, predict
- 5The Three Training StagesPretraining, fine-tuning, alignment
- 6Why Scale Changed EverythingEmergence and the Bitter Lesson
- 7Limits & MisconceptionsWhat an LLM can’t do
- 8From LLM to AgentThree layers around one core
Two kinds of model, two different jobs
The most useful distinction in modern AI is between discriminative and generative models. A discriminative model learns the boundary between categories and answers “which one?” — spam or not, fraud or not. It can’t create anything new.
A generative model learns what the data itself looks like, well enough to produce new examples that fit. A Large Language Model is simply a generative model, large in parameter count, trained on language.
If you remember one sentence from this module, make it this one: an LLM is a function that, given some text, predicts what text comes next. Answering questions, writing code, summarizing and holding a conversation are all built from that one move, repeated.
Two interns in an art gallery
BEFORE: One intern learns to look at any painting and say whether it’s a Van Gogh, a Monet or a Picasso. The other studies thousands of Van Goghs and then paints a brand-new picture in his style.
PAIN: Both studied the same paintings, but their skills don’t swap. Ask the first to paint and they freeze; ask the second to authenticate a canvas and you get a vague guess. Calling both “the art intern” sets them up to fail.
MAPPING: The first intern is discriminative: it draws boundaries between categories. The second is generative: it learned the patterns deeply enough to make new examples. Spam filters are the first kind; Claude is the second.
What each one learns
- DiscriminativeTrained on input–label pairs. Learns how likely each label is, given an input. Outputs one answer.
- GenerativeTrained on the data itself. Learns what normal text (or images, or music) looks like.
- SamplingTo create, a generative model samples from what it learned — the output is a fresh sequence that didn’t exist before.
- An LLMA generative model specialized to text, repeating “predict what comes next”.
Which kind of model is this?
IF the output is one of a fixed set: spam | not spam fraud | legitimate tumour | clear IT IS discriminative IF the output is new content: an answer, an essay, code, an image, a summary IT IS generative # LLMs, Claude, image generators: generative
Almost everything written about machine learning before 2020 was about the discriminative kind; almost everything in this course is about the generative kind.
Misconceptions
An LLM is a generative model: given text, it predicts what text comes next. Every capability you’ll use in this course is built from that one move.
Seventy years, two lineages, one convergence
Most timelines start in 2017. The fuller story is two long lineages — one teaching machines to write, the other to see and draw — plus the deep-learning revival that made both possible.
For about fifty years the field was a backwater: two “AI winters” (1974–80 and 1987–93) dismissed neural networks as a dead end. Then in 2012 AlexNet won the ImageNet competition by a huge margin, built on big datasets and cheap GPUs. Every modern generative advance descends from that moment.
By 2023 the tracks merged: multimodal models read images and text, and the transformer invented for language now powers most image and video models too.
Two rivers meeting
BEFORE: Two rivers run in parallel for hundreds of miles, each carving its own valley, each fed by its own streams.
PAIN: If you only ever map one river, you’re baffled when the water suddenly doubles downstream — you never saw the second one coming.
MAPPING: Vision and language were the two rivers, and they kept swapping tricks before merging around 2023. Knowing both lets you read product launches without being blindsided: advances in one track tend to land in the other.
The two tracks
- The revival (2012)AlexNet ends the symbolic-AI era: deep learning is back.
- VisionGANs (2014), StyleGAN faces (2018), DALL-E (2021), then diffusion: Stable Diffusion and Midjourney (2022).
- LanguageWord2Vec (2013), LSTMs, the transformer (2017), GPT-3 (2020), ChatGPT and Claude.
- Convergence (2023+)Multimodal models that see and talk — and, given tools, the agent era.
Reading a milestone
FOR any launch or paper, ASK: which track is it from? vision # GANs, diffusion, image/video language # embeddings, transformers what wall did it get past? will it cross to the other track? # usually yes -- e.g. transformers # now power image models too REMEMBER: every modern advance traces back to the 2012 revival
Diffusion models learn to reverse a noising process: start from noise and denoise step by step into an image. They overtook GANs around 2021.
Misconceptions
Generative AI is two tracks — vision and language — that converged. Knowing both explains why ideas keep jumping between them.
Seven acts, each ending at a wall
Modern LLMs feel like they appeared overnight in late 2022. They didn’t: they’re the seventh act in a long play, and each earlier act ended because researchers hit a wall the next breakthrough climbed.
The wall that mattered most fell in 2017. The transformer, from the paper “Attention Is All You Need”, replaced word-by-word reading with attention: every word looks at every other word in parallel. Training that took weeks took days, and everything you call an LLM today is a transformer.
Each era’s wall still shapes today’s models — which is why the history is a debugging aid, not trivia.
Climbing a staircase of walls
BEFORE: A climbing party reaches a cliff it can’t scale with the gear it has.
PAIN: Trying harder with the same gear gets nowhere. Hand-writing more grammar rules, or counting longer word sequences, just hits the same wall more expensively.
MAPPING: Each era of language AI brought new gear: counting, then meaning vectors, then memory, then attention. Knowing which wall each tool was built for tells you which of today’s limits are easy to fix and which are foundational.
The walls
- Rules (1950s–80s)Hand-written grammar, like ELIZA. Wall: language has effectively infinite rules.
- Statistics (1980s–2000s)N-gram counts. Wall: counts can’t capture meaning.
- Embeddings (2013)Word2Vec gives words meaning vectors. Wall: one vector per word, so “bank” is ambiguous.
- RNNs & LSTMs (2014–16)Read word by word with memory. Wall: slow, and forgets after a few sentences.
- Transformer (2017) onwardAttention in parallel, then GPT and BERT, then multimodal models and agents.
Where today’s quirks come from
IF a model favours common phrasings TRACE TO the counting era # frequent patterns dominate IF search struggles with ambiguous terms TRACE TO one-vector-per-word embeddings IF older models had tiny context TRACE TO the RNN era IF training at scale became possible TRACE TO attention (2017)
GPT-3 (2020) was the first model big enough to do useful tasks from a plain-English description, with no retraining.
Misconceptions
The transformer (2017) was the unlock: attention let every token compare with every other in parallel, which made large-scale training feasible.
Four steps, repeated for every token
When you send “The cat sat on the” to Claude, four things happen: tokenize the text, embed each token as a vector of meaning, attend so each token’s vector absorbs its context, and predict a probability for every possible next token.
One token is sampled, appended, and the whole pipeline runs again, until a stop token or a length limit. There’s no database lookup and no reasoning engine beside a knowledge base. Everything you experience falls out of doing this prediction at enormous scale.
Not a search engine — a jazz musician
BEFORE: Most people picture an LLM as a search engine that memorized facts and looks them up.
PAIN: That picture misleads constantly: you’re surprised when it “hallucinates”, can’t see why temperature changes answers, and can’t explain why it contradicts itself mid-paragraph.
MAPPING: Picture instead a well-read jazz musician improvising. You play an opening phrase; they’ve absorbed the patterns of millions of pieces, and each next note is whatever sounds most plausible given all that and your phrase. They improvise the next note, then the next — one token at a time.
“The cat sat on the ___”
- TokenizeText becomes token IDs, roughly 4 characters each. It’s why pricing is per token.
- EmbedEach ID becomes a vector of meaning; “cat” lands near “dog”.
- AttendAcross many layers, each token weighs every other token, so “sat” knows the cat did it.
- PredictA probability for every candidate token; one is sampled, and it repeats.
The whole show
tokens = TOKENIZE(prompt) REPEAT: vectors = EMBED(tokens) FOR each layer: vectors = ATTEND(vectors) # mix in context probs = PREDICT(vectors[last]) next = SAMPLE(probs, temperature) APPEND next to tokens UNTIL next is STOP OR length limit RETURN the generated tokens
Temperature 0 always picks the most likely token; higher values flatten the distribution and let less likely tokens through, for variety.
Misconceptions
Tokenize, embed, attend, predict, sample, repeat. Once this picture clicks, most “surprising” LLM behaviour stops being surprising.
Knowledge, then instructions, then behaviour
The Claude you talk to is the product of three training stages. Pretraining shows the model an enormous amount of text and trains one task: predict the next token. It costs millions and gives the model its raw knowledge — and its knowledge cutoff.
Supervised fine-tuning trains on curated question–answer pairs so the model answers instead of just continuing text. Alignment — RLHF, plus Anthropic’s Constitutional AI — nudges it toward helpful, honest, safe responses, and gives it much of its character.
Reading the library, then learning the job
BEFORE: A new assistant spends years reading an entire library: they know an astonishing amount about everything.
PAIN: Ask them “What’s the capital of France?” and they might reply “is a question students often ask” — they learned to continue text, not to answer. And they don’t yet know which answers are helpful or safe.
MAPPING: Pretraining is the library. Fine-tuning is job training on worked examples (“a question gets an answer”). Alignment is the performance review that shapes judgement and tone. Skip a stage and you get the cheap copies that disappoint.
The pipeline
- PretrainingTrillions of predict-the-next-token steps over books, websites and code. Weeks on thousands of GPUs.
- Fine-tuningThousands of human-written input–output pairs teach it to follow instructions.
- AlignmentHumans rank pairs of outputs; a reward model learns those preferences; the LLM is optimized to score well.
- Constitutional AIAnthropic also trains the model to critique its own outputs against a written set of principles.
Three stages, three jobs
# Stage 1 -- pretraining FOR trillions of steps over web-scale text: PREDICT next token; ADJUST weights # Stage 2 -- supervised fine-tuning TRAIN ON curated (question, good answer) pairs # Stage 3 -- alignment humans RANK pairs of outputs reward_model = LEARN those preferences OPTIMIZE LLM toward high reward THEN FREEZE the weights
After training, the weights are frozen. That’s why memory and retrieval are whole topics in this course: they simulate learning without retraining.
Misconceptions
Pretraining gives knowledge, fine-tuning gives instruction-following, alignment gives helpful and safe behaviour. After that, nothing changes until the next model.
Same recipe, much bigger
The architecture inside GPT-4 isn’t fundamentally different from GPT-2’s: same kind of transformer, same objective, broadly the same data. What changed was scale — more parameters, data and compute — and the capability gap is enormous. GPT-2 wrote a passable paragraph; GPT-4 a passable legal brief.
Some abilities appear suddenly past a size threshold rather than improving gradually: arithmetic, multi-step reasoning, following unfamiliar formats. These emergent capabilities weren’t fully predicted, and nobody is certain what the next size jump brings.
Water at 99° and 100°
BEFORE: Heat water from 20° to 99° and it just gets hotter — same liquid, gradual change.
PAIN: Judge it by that trend and 100° is a shock: it suddenly boils. The change wasn’t in the recipe, only the amount of heat.
MAPPING: Scaling a model can work like that. Below a threshold, an ability is near zero; past it, it appears. Researchers debate whether it’s truly sudden or under-measured at small sizes — but the practical effect is real.
What scale bought
- Same objectivePredict the next token, from GPT-1 to today.
- More of everythingParameters grew from 117 million (GPT-1) to an estimated trillion-plus.
- EmergenceCoherent sentences, then essays, few-shot learning, multi-step reasoning, tool use and coding.
- The Bitter LessonRich Sutton (2019): simple methods that scale with compute beat clever hand-built ones, again and again.
What scale does and doesn’t give you
SCALE GIVES: broader knowledge emergent abilities past size thresholds a model worth wrapping in tools SCALE DOES NOT GIVE: reliable action in the world current facts or a truth signal memory across conversations SO: the course adds tools, retrieval, memory and loops around it
The lesson is “bitter” because it implies a lot of elegant research was, in the long run, the wrong path.
Misconceptions
Scale was the engineering unlock; emergent abilities were its surprise. It gave us a model worth wrapping — the wrapping is still our job.
Know the limits you’ll engineer around
Understanding what an LLM can’t do matters more than what it can, because the rest of the course is about engineering around those limits.
The model has patterns, not facts. When it’s right, a fact appeared often enough in training to dominate the prediction. When it’s wrong — a hallucination — it’s doing exactly the same operation with the same confidence: there’s no internal truth signal. Math outside memorized patterns is unreliable, “reasoning” is pattern continuation, and nothing is learned between conversations.
The confident, well-read stranger
BEFORE: You meet someone who has read nearly everything and answers any question fluently, instantly, and in the same assured tone.
PAIN: Their right answers and wrong answers sound identical. They never say “I’m not sure”, can’t reliably do long arithmetic in their head, and won’t remember you tomorrow.
MAPPING: That’s an LLM. You wouldn’t fire them — you’d hand them a reference library, a calculator and a notebook. In this course those are retrieval, tools and memory.
Five myths and their fixes
- “It knows things”It has patterns. Ground it with retrieval and tools (M05, M09).
- “It can do math”Only familiar patterns. Give it a calculator tool.
- “It’s reasoning”It produces text that resembles reasoning. Chain-of-thought helps, but it’s still pattern continuation (M03).
- “It learns from us”Weights are frozen; persistence must be engineered (M08, M11).
- “Bigger is always better”For production, smaller specialized models often win on cost and latency (M14, M22).
Match the limit to the fix
IF it needs current or private facts: ADD retrieval or a lookup tool IF it needs exact arithmetic: ADD a calculator tool IF it must remember past sessions: STORE history, FEED it back as context IF an answer must be right: VERIFY it -- fluency is not a truth signal IF the step is routine: USE a smaller, cheaper model
The context window is the limit of what the model can consider at once — 200,000+ tokens for modern Claude. Anything outside it is invisible.
Misconceptions
An LLM is fluent, not factual. Retrieval, tools, memory and verification exist because of these limits — they’re the rest of the course.
Wrap the predictor in layers
An LLM by itself just produces text. A useful product wraps that prediction engine in layers. The raw LLM predicts text from text: stateless, factless, toolless.
Add a system prompt and conversation memory and you have an assistant: it follows instructions and holds a thread. Add tools and a loop — the model picks a tool, reads the result, picks the next — and you have an agent that can act in the world.
Every module in the course adds one of these layers around the same predict-the-next-token core.
An engine, a car, a driver
BEFORE: An engine on a test stand is powerful: it spins, it roars, it produces enormous force.
PAIN: It goes nowhere. It can’t steer, can’t carry anything, and can’t decide where to go.
MAPPING: The raw LLM is the engine. The assistant is the car around it — controls and a seat (system prompt, memory). The agent is the car with a driver who reads the road and chooses each turn (tools plus a loop). The engine never changed.
The three layers
- Layer 1: raw LLMCompletion, summarization, classification — “here’s input, continue”.
- Layer 2: assistantSystem prompt for role and rules, plus memory of the conversation (M03, M08).
- Layer 3: agentTools you wrote — search, code, email, databases — inside a loop the model drives (M05–M07, M12).
- Around themRetrieval, evaluation, guardrails and monitoring — more layers on the same core.
The agent layer
messages = [system_prompt, user_goal] LOOP: reply = ASK LLM(messages, tools) IF reply calls a tool: result = RUN that tool APPEND result to messages ELSE: RETURN reply # answered, or gave up # same LLM underneath -- the loop and # the tools are what make it an agent
You’re ready for M00, which shows a working agent end to end and the lifecycle the rest of the course follows.
Misconceptions
Agent = LLM + tools + loop. The rest of the course teaches you to build that wrapping responsibly.
Test the core insight
5 questions on the module’s sharpest insights. Tap to reveal the answer.
Open the full module on desktop
The desktop version has the full timelines with interactive animations, the step-through of tokenize → embed → attend → predict, the scaling chart, a glossary of every term, and a knowledge check. No code — it’s the same mental model at full depth.
Open Generative AI Foundations on Desktop → Full primer · timelines, glossary, quiz · ~45 minBonus module · Foundations Primer