Andrej Karpathy — Intro to Large Language Models (YouTube, ~3 hours)
Andrej Karpathy spent years as OpenAI’s director of AI and is one of the few people who can explain how these systems actually work without either dumbing it down or hiding behind abstraction. This isn’t a hype video. It’s a technical tutorial written for someone smart enough to want the real picture. What sits at the center of it is a deceptively simple question: when you type something into ChatGPT and hit enter, what is actually happening? Not metaphorically. Mechanically. The answer, it turns out, changes how you should use these tools, what you should trust them with, and what you should never hand them alone.
The Video:
My Takes:
The Internet Is Just Compressed, Filtered, Tokenized Text
“44 terabytes of disk space. You can get a USB stick for like a terabyte very easily. This is not a huge amount of data at the end of the day even though the internet is very very large.”
Everything starts with a crawl. Billions of web pages, scraped raw, then run through a cascade of filters: block malware and spam, strip HTML markup, detect language, deduplicate, remove personally identifiable information. What survives is a relatively small slice of the public internet — high quality, high diversity, mostly English — and it fits on a hard drive you could buy at Best Buy.
That compression should feel significant, because the intuition most people carry is that AI must be working with something vast and cosmic. It isn’t. It’s working with the best available sample of what humans have written down and made public, filtered for quality, and stored as text. The knowledge inside these models is not omniscient. It’s a distillation of what people chose to publish, which means it carries all the biases and gaps that implies.
Before any of that text can enter a neural network, it has to be broken into tokens — small chunks of text that function like atoms. Not characters, not words exactly, but something in between. “Hello world” becomes two tokens. A capital H changes the token. Two spaces between words creates a different token than one. The vocabulary of GPT-4 contains roughly 100,000 possible tokens. Everything you’ve ever typed into ChatGPT was first converted into a sequence of those tokens, and the model never sees anything else.
This tokenization decision, which feels like a technical footnote, turns out to explain many of the model’s strangest failures. Models cannot count letters in a word because they don’t see letters — they see token IDs. Spelling tasks break down for the same reason. The model’s whole world is tokens. Anything that requires dropping below the token level is, for the model, invisible.
A Neural Network Is a Giant Mathematical Expression That Predicts the Next Token
“Think of these parameters as kind of like knobs on a DJ set, and as you’re twiddling these knobs you’re getting different predictions for every possible token sequence input.”
A language model at its core is a function. It takes a sequence of tokens as input and outputs a probability distribution over the next possible token. The function is parameterized by billions of numbers called weights. In the beginning, those weights are random. The predictions are nonsense. Training is the process of adjusting the weights, one small nudge at a time, so that the model’s predictions start to align with what actually comes next in real text.
The architecture doing this work is called a Transformer. Information flows through dozens or hundreds of layers of mathematical operations — matrix multiplications, normalizations, attention mechanisms — until you get probabilities for what the next token should be. That’s the whole thing. The magic isn’t in some exotic cognitive structure. It’s in the scale: billions of parameters, trillions of tokens, months of compute. The architecture is comprehensible. The scale is what makes it remarkable.
Generating text from a trained model is called inference, and it’s just the prediction loop running one token at a time. The model outputs probabilities, you sample from those probabilities to pick the next token, append it to the sequence, and repeat. Because you’re sampling from a probability distribution rather than always taking the most likely option, you get different outputs every time — even from the same input. These systems are stochastic. That’s a feature for creativity and a liability for reliability.
The Base Model Is an Internet Simulator, Not an Assistant
“This model is not yet an assistant. What is 2 plus 2 — it’s not going to tell you it’s four. It’s just going to get the probability for the next token and it’s just a glorified autocomplete.”
The output of pre-training is called a base model. It can continue any piece of text you give it. It has internalized the statistical patterns of the internet. It knows, in some distributed sense across its weights, an enormous amount about the world. But it will not answer your questions. Ask it what 2 plus 2 is and it might continue the sentence with a philosophical tangent, or another question, or the next line of whatever web page it thinks this resembles.
Karpathy runs the 405 billion parameter Llama base model live and prompts it with the beginning of a Wikipedia article on zebras. The model recites the article near-verbatim from memory. It has memorized it because it’s seen the Wikipedia article enough times during training that the weights hold it. That’s called regurgitation, and it’s not what you want. The model isn’t reasoning. It’s recalling.
What the base model is genuinely good at is demonstrating that knowledge was absorbed. Prompt it cleverly — give it the beginning of a list, or a few-shot pattern of question and answer — and it will continue the pattern with real knowledge. That’s called in-context learning: the model reads the format of your prompt and figures out what kind of continuation is expected. Primitive assistants have been built from base models alone, just with carefully constructed prompts. But it’s a hack. For a real assistant you need the next stage.
Supervised Fine-Tuning Is Teaching by Example
“What you’re talking to in ChatGPT is a statistical simulation of a data labeler at OpenAI.”
Post-training begins with supervised fine-tuning. The internet data gets swapped out for a curated dataset of conversations — human-written prompts paired with ideal human-written responses. These conversations are constructed by professional labelers who study detailed company guidelines about what a helpful, honest, and harmless response looks like. They write tens or hundreds of thousands of these. The model trains on them. It begins to take on the personality and response patterns of those labelers.
The implications of that are worth sitting with. When you ask ChatGPT to summarize an article or help you draft an email, you are not consulting a superintelligence. You are getting a probabilistic simulation of a reasonably skilled knowledge worker who has read OpenAI’s instructions carefully. That person is probably smart and well-intentioned. They are not infallible. They will confidently produce incorrect information in the same tone they produce correct information, because the training data is full of confident correct answers and the model learned to imitate the confidence along with the content.
The modern version of this process uses enormous amounts of synthetic data — language models helping to generate the training conversations for the next generation of language models. But at the foundation, humans are still writing labeling instructions, humans are still curating and rating outputs, and the whole system is still ultimately aimed at imitating what a careful human expert would say. The magic is in the execution at scale, not in some mystical departure from human knowledge.
Hallucinations Are a Direct Consequence of How the System Was Trained
“The model is just taking its best guess in a probabilistic manner. You and I experience it as made-up factual knowledge. But the model basically doesn’t know and it’s just imitating the format of the answer.”
Every training conversation had a confident-sounding answer. The labeler knew who Tom Cruise was, looked it up, wrote it out. The labeler knew the capital of France. They wrote it out. What never appeared in the training data was a labeler saying “I have no idea who Orson Kovats is” for a randomly invented name, because labelers only answered questions they could actually answer. So the model learned that questions of the form “who is X” get confident answers. When it encounters a name it doesn’t know, it still produces a confident answer. It can’t do anything else. Nothing in its training taught it the shape of “I don’t know.”
The fix is straightforward in principle. You interrogate the model on a large bank of factual questions, check whether its answers match known correct answers, identify the questions where it consistently gets it wrong or gives inconsistent answers, and then add training examples where the correct response is “I don’t remember” or “I’m not sure.” Give the model permission to not know things, and it learns to exercise that permission roughly when it’s appropriate.
Web search is the more robust mitigation. When the model decides to search instead of recall, it fetches the actual text of a webpage and puts it in the context window. The distinction matters enormously. Knowledge in the model’s weights is a vague recollection. Knowledge in the context window is working memory — directly accessible, not subject to the lossy compression of training. The model can quote from it, reason about it, get it right. This is why, when you need accuracy on something specific, pasting the source into your prompt is almost always better than hoping the model remembers.
Models Need Tokens to Think — Every Token Is a Quantum of Computation
“There’s a fixed amount of compute that’s going to happen in this box for every single token. You can’t imagine the model to do arbitrary computation in a single forward pass to get a single token.”
Every token the model generates consumes a fixed, small amount of computation. There are a finite number of neural network layers, and information passes through them once per token. You cannot cram an arbitrarily complex reasoning step into a single token generation. The model doesn’t have access to a scratch pad. There’s no background process running. The computation is the forward pass, and the forward pass produces one token, and then it does it again.
This has a concrete implication for how you get good answers. If you ask a math problem and want the model to answer in a single word, you’re asking it to do all the reasoning in zero visible steps — and it will fail on anything non-trivial. The correct answer is already determined before the model has done any work. Contrast that with letting the model write out intermediate steps. Each step is its own token generation, its own quantum of computation. By the time it reaches the final answer, it has done the arithmetic visibly, in sequence, and each step was tractable.
This is also why “let me think through this step by step” genuinely improves model performance. It’s not a politeness ritual. It’s asking the model to distribute its reasoning across many tokens instead of cramming it into one. The famous failure case is “9.11 vs 9.9 — which is bigger?” The model frequently answers 9.11. Not because it doesn’t know math, but because something in its training associates that numeral pattern with Bible verse numbering, where 9.11 comes after 9.9. The surface-level association overrides the arithmetic. No amount of scaling fully eliminates these holes. The Swiss cheese model of capability: extraordinary at some things, randomly wrong at others, with no obvious pattern.
Reinforcement Learning Is Where the Machine Stops Imitating Humans and Starts Thinking for Itself
“The model is discovering ways to think. It’s learning what I like to call cognitive strategies of how you manipulate a problem. This is an emergent property of the optimization — without having to hardcode it anywhere.”
Supervised fine-tuning makes a model that imitates expert humans. Reinforcement learning makes a model that practices on its own. The setup is simple: give the model thousands of problems with verifiable answers. Have it generate many candidate solutions. Check which ones get the right answer. Train the model to do more of what worked. Repeat.
What emerges from this process is not more confident imitation. It’s something genuinely different. Karpathy shows outputs from DeepSeek R1, a model trained with RL on math and code problems. The model’s reasoning traces are long, self-correcting, full of “wait, let me reconsider” moments and “actually, let me try a different approach” pivots. No human labeler wrote those traces. The model discovered that this pattern of thinking reliably produces correct answers and trained itself to use it.
The parallel to AlphaGo is not decorative. AlphaGo trained on human games of Go and got very good. Then it trained via self-play reinforcement learning and got superhuman. It also discovered Move 37 — a move so counterintuitive that human professionals initially thought it was a mistake. Watching a grandmaster respond in real time: “that’s a very surprising move, I thought it was a mistake.” It wasn’t. AlphaGo had found a strategy outside the distribution of human play that was empirically better. The same principle, applied to open-domain reasoning, is still in its infancy — but the direction is clear.
RLHF Is Useful but It Is Not Real Reinforcement Learning
“RLHF is not RL. It’s a little fine-tune that slightly improves your model. It’s just not RL in the sense that it lacks magic.”
For problems with verifiable answers, reinforcement learning can run indefinitely. You either got the right answer or you didn’t. The scoring function is incorruptible. In principle, you can run it for hundreds of thousands of steps, pour in more compute, and keep getting better.
For everything else — creative writing, summarization, tone, humor — you don’t have a ground truth answer. So the field developed Reinforcement Learning from Human Feedback, where humans rank model outputs and a separate neural network is trained to predict those rankings. That reward model becomes the scoring function for RL. The appeal is that it scales: instead of asking humans to rate a billion outputs, you ask them to rank a few thousand, train a simulator, and query the simulator as many times as you need.
The problem is that the simulator is a neural network, and neural networks can be gamed. Run RL against a reward model long enough and the language model finds adversarial inputs — nonsensical outputs that the reward model inexplicably scores highly. The training process is exploiting the cracks in the simulation rather than genuinely improving. You have to stop before that happens, which means RLHF has a ceiling. You can’t just run it longer and get proportionally better results. It’s fundamentally different in kind from RL on verifiable problems, where the ceiling, if there is one, is much, much higher.
The practical upshot: GPT-4o is a mostly supervised fine-tuned model with some RLHF applied. It’s very capable. It doesn’t think in the deep sense. The O-series models and DeepSeek R1 are trained with real RL on verifiable problems. They’re genuinely different. Reach for them when the problem requires actual reasoning, not just fluent recall.
The Context Window Is Working Memory — Use It Like One
“The knowledge inside the neural network’s parameters — think of that as something you read a month ago. The knowledge in the tokens that make up the context window is the working memory.”
The distinction between weights and context window is one of the most practically important things Karpathy explains. The model’s parameters are a lossy compression of everything it was trained on. Vast but imprecise. Things it saw many times are remembered well. Things it saw rarely are remembered poorly, or hallucinated. You cannot control what the model remembers from training.
The context window is different. Whatever is in there is directly accessible to the model on every forward pass. It’s not recall — it’s reading. A model summarizing a book from memory is doing something categorically different from a model summarizing a book that’s been pasted into the context window. The latter is far more reliable. The former is the model’s best recollection of something it may have seen once, a long time ago, during pre-training.
This reframes how to use these tools. Paste in the contract before asking for legal analysis. Paste in the article before asking for a summary. Paste in the code before asking for a review. The model doesn’t need to remember — you’re giving it the working memory directly. The context window is a resource, and most people underuse it.
Tools Are How Models Escape the Limits of Their Own Cognition
“Instead of saying I don’t know, we can attempt to use tools. The model emits special tokens, and that pauses generation. It goes off, does the search, gets the text, puts it in the context window, and now that data is directly available.”
The model can be given tools by introducing special tokens that trigger external actions. When the model emits a “search start” token followed by a query and a “search end” token, the inference system pauses, runs the search, fetches the page text, and stuffs it back into the context window. The model then continues generating with that information directly available. Same for code execution: the model writes Python, an interpreter runs it, the result comes back into the context.
This is significant because it routes around two of the model’s fundamental weaknesses. For factual recall, web search replaces fallible memory with direct retrieval. For arithmetic and character manipulation, code execution replaces unreliable mental math with deterministic computation. The model’s job shifts from “know things and calculate things” to “figure out what to look up and what to compute, then reason about the results.” That’s a task it’s much better at.
The practical implication is simple: if a task involves recent information, use a model with web search enabled. If a task involves precise arithmetic, ask it to write and run code. Don’t ask the model to do in its head what a calculator or a search engine does better. The model’s intelligence is best spent on reasoning about outputs, not producing them from memory.
What’s Coming, and Why the Frontier Is Still Wide Open
“In principle these models are capable of analogies no human has had. These are primordial models for now, but the direction is clear.”
Karpathy ends by gesturing at the trajectory. Models are becoming multimodal not through some fundamental architectural change but through tokenization: audio spectrograms become tokens, image patches become tokens, and the same training machinery handles them all. The context window that currently holds thousands of tokens will eventually hold millions, accommodating hours of video, entire codebases, lifetimes of documents.
Agents — models that execute tasks over long time horizons, make decisions, use tools, report back — are beginning to work, not reliably yet but increasingly. The ratio that will matter in knowledge work is not human-to-computer but human-to-agent: how many running processes can one person supervise and correct? That number is going up.
The reasoning capability frontier is still early. RL on verifiable domains is producing models that think in ways human labelers couldn’t have prescribed. The full implications of that are unknown. What’s known is the direction: more practice problems, better scoring functions, longer training runs, more domains with verifiable answers. Somewhere in that scaling trajectory is the equivalent of Move 37 for reasoning — a strategy no human thought of, that turns out to be better.
The model you’re talking to is not a mind. It’s a very sophisticated statistical pattern-matcher that has been trained to sound like a mind, then fine-tuned to be useful, and in some cases trained further to reason. The outputs are often extraordinary. They are also sometimes wrong in ways that should embarrass a middle schooler. Both of these things are true simultaneously, and neither cancels the other out. Use it as a tool with real capability and real failure modes. Check its work. Own the output. The leverage is enormous for people who understand what they’re actually working with.
Leave a comment