youtube.nixfred.com nixfred.com

Deep Dive into LLMs like ChatGPT

Andrej Karpathy's general audience deep dive into the full training stack behind ChatGPT, in one sitting: pretraining on a filtered crawl of the internet, tokenization, what the base model actually is (an internet document simulator), supervised fine tuning that turns it into an assistant, and reinforcement learning as the third and least mature stage. The second half is LLM psychology: why hallucinations happen and how they get patched, why models need tokens to think, why they cannot spell or compare 9.11 to 9.9, and what emergent chains of thought in DeepSeek R1 mean. It ends with where to find and run these models yourself.

Published Feb 5, 2025 15 min read Added Jul 30, 2026 Open on YouTube →

At a glance

This is the single video to hand someone who asks "what actually is ChatGPT." Andrej Karpathy spends three and a half hours walking the entire training stack of a modern large language model with no math prerequisites and nothing waved away: where the training data comes from and what gets thrown out, what tokenization does to text before the network ever sees it, what a base model is and why it is not yet an assistant, how supervised fine tuning manufactures a helpful persona out of human labeled conversations, and why reinforcement learning is the third stage and the one still being figured out.

The second half is the part people quote. Karpathy calls it LLM psychology: the cognitive deficits that fall out of how these things are built. Hallucination is not a bug someone forgot to fix, it is the default behavior of a system trained to imitate confident text. Models cannot count letters or compare 9.11 to 9.9 for reasons that trace back to tokenization. They need tokens to think, so answers that arrive too fast are worse. And the DeepSeek R1 paper matters because it showed chains of thought emerging from reinforcement learning rather than being written in by hand.

This page rebuilds the argument in the video's own order, keeps the numbers, and ends where he ends: with the practical question of where to find these models and run them yourself.

The deep explanation

Stage one: pretraining, and what the internet looks like after filtering

Everything starts with text, an enormous amount of it, scraped from the public web. Karpathy uses FineWeb as his worked example because Hugging Face documented exactly how it was built, and the honest surprise is how much of the internet gets discarded. The raw crawl comes from Common Crawl, which has been indexing the web since 2007 and holds billions of pages. What survives to become a training set is a filtered residue of roughly 44 terabytes of text, an amount you could fit on a single hard drive you can buy today.

The filtering pipeline is a series of unglamorous steps that each remove a lot:

What comes out the other end is not a knowledge base, it is a very large sample of how text tends to continue. Karpathy makes the point that when you look at a chunk of it you are looking at the actual substance of the model's world: recipes, forum arguments, documentation, news, fan fiction, code.

Tokenization: the model does not see letters

The network cannot consume raw text, and it does not consume raw bytes either, because a byte level sequence would be far too long. Instead text is compressed into a vocabulary of symbols using byte pair encoding, which repeatedly finds the most common adjacent pair of symbols and mints a new symbol for it. Do that enough times and you trade a longer sequence for a bigger vocabulary. GPT-4 lands on roughly 100,000 tokens. A token is often a word, often a word fragment, and crucially it usually includes the leading space, so "hello" and " hello" are different symbols.

This is the moment the model's blind spots are created, and Karpathy returns to it repeatedly later. You can play with it directly at Tiktokenizer. Everything downstream operates on these symbols, not on characters, which is why questions about spelling are questions the model is structurally bad at.

What training actually optimizes

Take a window of tokens, feed it in, and the network emits a probability for every token in the vocabulary as the next one. Compare that to what actually came next in the training data, nudge the weights to make the true continuation slightly more likely, repeat across the corpus. That is the whole objective. Karpathy points people at Brendan Bycroft's LLM visualization to see the transformer as a concrete machine with numbers moving through it, and at nanoGPT for the code.

Two properties matter for everything that follows. The network is a fixed function with no memory between calls, so a conversation only exists because the whole transcript is fed back in every time. And the weights are a lossy compression of the training corpus, which he describes as a vague recollection of the internet: things seen many times are recalled sharply, things seen once are hazy or reconstructed. That distinction, sharp memory versus hazy reconstruction, is the seed of hallucination.

On cost, he gives the useful anchor that reproducing GPT-2 (which cost on the order of tens of thousands of dollars in 2019) now costs roughly a hundred dollars of cloud compute, because both hardware and datasets improved. Frontier runs are of course a different universe of spend.

The base model is an internet document simulator

After pretraining you have a base model, and Karpathy is emphatic that this is not an assistant. It is a token autocomplete engine. Ask it a question and it may well continue with more questions, because that is what a page of questions looks like on the internet. Prompt it with the opening of a Wikipedia article and it will happily recite the article, sometimes verbatim if that page appeared often enough in training, which is regurgitation rather than reasoning.

He demonstrates two things with a base model that are easy to miss:

He also makes the point about knowledge cutoffs concrete: ask a base model who the current president is and you get an answer frozen at the last date in its data.

Stage two: supervised fine tuning, or where the persona comes from

To turn the document simulator into an assistant you continue training on a much smaller, much more curated dataset: conversations. Human labelers, following a long document of instructions from the company, write ideal assistant replies to prompts. The InstructGPT paper documented this and even published labeling instructions telling contractors to be helpful, truthful, and harmless.

Karpathy's reframing here is the most useful single idea in the video. When you talk to ChatGPT, you are not talking to a magical AI. You are talking to a statistical simulation of the kind of person who writes those labeled responses, an idealized human labeler following a company's instruction document. The tone, the hedging, the refusals, the formatting habits: all of it is imitation of that population.

Modern practice has shifted so that much of this data is now generated by models and curated by humans, with datasets like UltraChat as public analogues, but the shape holds. Conversations are also serialized into tokens with special separators so the model can tell whose turn it is.

1. Pretraining ~44 TB of filtered web text months, thousands of GPUs objective: predict next token base model document simulator 2. Fine tuning ideal conversations human labelers + instructions objective: imitate the labeler assistant helpful, truthful, harmless 3. Reinforcement practice problems try, score, keep what worked objective: get the answer right reasoning model discovers its own solution path

knowledge manners problem solving Each stage is smaller and more curated than the one before it.

Figure 1. The three stages, with what each one contributes. Karpathy's textbook analogy maps onto this exactly: pretraining is reading the exposition, fine tuning is studying worked examples, reinforcement learning is doing the practice problems.

LLM psychology, part one: hallucinations

Ask an assistant about a person who does not exist and older models would confidently invent a biography. The reason is mechanical. The fine tuning data is full of confident, well formed answers to questions, so the pattern the model learned is "when asked a question, produce a confident well formed answer." Nothing in that data ever taught it what its own ignorance feels like.

The fix that actually works is to teach it. You take facts the model demonstrably does not know, by interrogating it and checking which answers are wrong, then add training examples where the correct response to exactly those questions is an admission of not knowing. Now "I do not know" is inside the distribution of behaviors, tied to the internal state that accompanies uncertainty.

The second fix is tools. Rather than relying on the hazy recollection in the weights, the model emits a search query, the results come back into the context window, and it answers from text it can actually see. Karpathy's framing: the context window is working memory, directly accessible, while the weights are vague memory of something read a long time ago. If you want accuracy, put the material in working memory.

A related note on self knowledge. Asking a model "what model are you" is meaningless unless someone deliberately trained an answer in or put it in the system prompt. Otherwise it will pattern match to whatever assistant text dominated its training, which is why so many models used to claim to be built by OpenAI.

LLM psychology, part two: models need tokens to think

Every token is produced by a fixed and finite amount of computation. There is no way for the model to sit and think harder before emitting one. So if you demand the answer immediately, you are asking for the entire reasoning to happen inside a single forward pass, and it will guess.

The consequence is that good answers spread the work out. A response that lays out intermediate steps and arrives at the answer at the end is doing real computation across many forward passes. This is why chain of thought prompting works and why the formatting of training answers matters so much. It is also why, for anything arithmetic, the right move is to have the model use a tool: emit code, run it, read the result. The model is a bad calculator and an excellent programmer of calculators.

Two famous failures land here as well. Counting the letter r in "strawberry" is hard because the model sees tokens, not letters, and because counting is a serial task it is being asked to do in one shot. Comparing 9.11 to 9.9 goes wrong in a way that looks like software versioning or Bible verse ordering leaking in from the training data, and Karpathy notes that the internal activations show something odd happening around those tokens.

Stage three: reinforcement learning, and why DeepSeek R1 mattered

The textbook analogy carries the argument. Pretraining is background exposition. Fine tuning is worked examples from an expert. Reinforcement learning is the practice problem set, where you are given a problem and a known answer but not the path, and you have to find a path that gets there. Crucially, the path that works for a human expert is not necessarily the path that works for a model. Reinforcement learning lets it find its own.

Mechanically, the model attempts a problem many times, the attempts that reached the correct answer are kept, and training reinforces those token sequences. Do this at scale on problems with checkable answers, math and code above all, and something striking happens: the responses get longer on their own. The model discovers that backtracking, trying another approach, and checking its own work raise the odds of a correct answer. Nobody wrote those behaviors into a prompt template. That is the result the DeepSeek R1 paper published in the open, and it is why that paper hit so hard. Karpathy compares it to AlphaGo's move 37, the move no human would play, which came from the same place: a system allowed to search for its own strategies rather than imitate ours.

Then there is RLHF, which is what you do in domains where answers cannot be automatically checked, like writing a good joke or a good poem. You cannot score those with a script, so you train a separate reward model on human comparisons of outputs and optimize against it. This helps, but Karpathy is careful to mark it as different in kind from verifiable domain reinforcement learning, because a reward model is a lossy simulation of human preference and optimizing hard against it eventually games it. Run it too long and the model finds nonsense that the reward model loves and humans hate. So RLHF gets run for a limited number of steps, which means it is a fine tuning technique with a ceiling rather than a road to superhuman performance.

StageData it learns fromWhat it can be scored againstCeiling
PretrainingFiltered internet textThe next token that actually followedScales with data and compute
Supervised fine tuningIdeal conversations from labelersThe labeler's written answerBounded by the labelers
RL, verifiable domainsProblems with checkable answersAn automatic checkerCan exceed human strategies
RLHF, unverifiable domainsHuman preference comparisonsA learned reward modelGameable, so run briefly

Where it is going, and where to get the models

Karpathy closes forward looking. Models become natively multimodal, handling audio and images as tokens in the same stream rather than through bolted on adapters. Work moves from single answers to long running agentic tasks with a human supervising a fleet rather than typing every prompt. Models get more pervasive and more invisible, integrated into tools rather than visited in a chat box.

The practical closing advice, which is the reason to keep this page open:

Key takeaways

Where this sits in the LLM Learning track

This is the opening lecture for a reason: it is the only video in the track that touches every stage of the stack in one pass, so the rest have something to attach to. Chapter 6 of the 3Blue1Brown series next opens up the one component Karpathy treats as a box, and the Five Formulas tutorial supplies the quantitative frame. When you get to the later parts on reinforcement learning from human feedback and on interpretability, they are direct expansions of two sections in this video.

Resources mentioned

About this page

This reconstruction was built from the public record of the talk rather than from its caption track, because the machine that assembled it had no network route to YouTube. What that means in practice: the argument, the structure, and the specifics are here, but this page does not yet carry the verbatim transcript, the timestamped chapter map, or pull quotes, and those are the three things a normal page on this site carries. They get backfilled on the next run from a machine that can reach the source. Until then, watch it on YouTube alongside this page.