Chapter 6 of 13 · 18 min

How LLMs Learn

From internet text to assistants.

Goal of this chapterAfter this chapter you will understand pretraining, compression, scaling, fine-tuning, assistant behavior, and why next-token prediction can produce broad competence.
Watch this chapterAndrej Karpathy's key moments on how llms learn, back to back
3 moments · 2 min
1 / 3
“…a large language model is just two files…”
Intro to Large Language Models, YouTube interview, 2024 · 0:00

The lesson

A useful starting point is to demystify what an LLM is. Karpathy frames it as a fixed program plus learned parameters, not a persistent self or hidden mind, and he repeatedly reduces neural networks to simple mathematical machinery with many adjustable knobs rather than something biologically brain-like12. That framing matters because it shifts the question from "what is it thinking?" to "what statistical structure did training push into the weights?"

Pretraining is the stage where that structure gets packed into the model. The training data is described as heavily filtered internet text, tokenized into pieces, and the model is trained by repeatedly increasing the probability of the correct next token in sequence. Karpathy characterizes this as a kind of compression of internet text into parameters, which helps explain why generation can look like the model is reconstructing documents or recalling facts: the knowledge is not stored as pages, but as compressed patterns in weights34.

Why does next-token prediction lead to broad competence instead of only autocomplete? Karpathy's answer is that predicting the next token well across internet-scale text forces the model to capture many regularities at once: syntax, facts, style, common reasoning patterns, and how pieces of context constrain what should come next. He also emphasizes scaling laws: performance on this simple objective improves in a smooth, predictable way as model size and dataset size grow, which helps explain why capability keeps expanding as systems are scaled up rather than redesigned around many separate skills.

Inside the model, those capabilities come from repeated computation over token representations. Karpathy describes the Transformer as repeated stages where attention gathers information across the sequence and MLP layers transform it locally, refining the residual stream block by block5. You do not need to imagine a symbolic database or hand-built modules; a large amount of capability can arise from optimizing this relatively simple architecture at scale, then storing the result in the learned weights and biases of the Transformer6.

A base model becomes an assistant through post-training, especially fine-tuning on curated question-answer style data, which teaches it to respond helpfully in the format people want. That assistant behavior is useful, but it should not be mistaken for reliability or full understanding: Karpathy advises treating these systems as tools whose outputs still need checking, because they can hallucinate or fail unpredictably even when they sound confident7. So the overall pipeline is: compress broad text with next-token prediction, scale the process, then shape the resulting base model into an assistant with additional training.

3 principles from Andrej Karpathy

1

Think of an LLM as weights plus computation

Treat the model as a learned mathematical function, not a human-like self. This helps you reason concretely about what training can and cannot produce: behavior comes from parameters shaped by optimization and the code that runs them.

“…a large language model is just two files…”
Intro to Large Language Models, YouTube interview, 2024
2

See pretraining as compression

Pretraining does not copy the internet into a lookup table; it compresses statistical structure from a huge text corpus into parameters. When the model generates text, it is using that compressed structure to continue token sequences plausibly.

“…this network then dreams internet documents…”
Intro to Large Language Models, YouTube interview, 2024
3

Use assistants, but verify them

Helpful interaction does not guarantee correctness. Apply these models as drafting, brainstorming, or question-answering tools, but keep responsibility for checking the result.

“…use it as a tool in a toolbox…”
Deep Dive into LLMs like ChatGPT, 2022

In his own words

The quotes behind the lesson, word for word from the transcripts. Numbers match the lesson above.

1
“…a large language model is just two files…”
Intro to Large Language Models, YouTube interview, 2024
2
“I think of it as a very complicated alien artifact.”
Lex Fridman Podcast #333, 2024
3
“…this network then dreams internet documents…”
Intro to Large Language Models, YouTube interview, 2024
4
“…we kind of understand that they build and maintain some kind of a knowledge database…”
Intro to Large Language Models, YouTube interview, 2024
5
“So the attention is the reduce, and the MLP is the map. And what you end up with is that the Transformer just ends up just being a repeated application of map produce if you want to think about it that way. So this is where they communicate, and this is where they think individually about the information that they've gathered. And every one of these blocks iteratively refines the representation at the residual stream.”
OpenAI / online talk, 2022-11answer page →
6
“…everything here is just the other weights and biases and everything else of this Transformer…”
OpenAI / online talk, 2022-11
7
“…use it as a tool in a toolbox…”
Deep Dive into LLMs like ChatGPT, 2022

Reflect

  1. When you use an assistant model, which part of its behavior do you think comes from broad pretraining versus later fine-tuning? Give one example of each from your own experience.
  2. If next-token prediction is a compression process, what kinds of knowledge or skills would you expect to compress well into weights, and what kinds would you expect to remain brittle?
  3. Pick one task you currently do with LLMs. How would you redesign your workflow if you fully accepted the rule to use the model as a tool but verify its work?

Check your understanding

1. Why does Karpathy describe pretraining as a kind of compression?
2. What best explains why next-token prediction can produce broad competence?
3. What is the role of fine-tuning in turning a base model into an assistant?

Go deeper

Search every transcript
Open the full search page →