Andrej Karpathy on Language Modeling
Karpathy treats language modeling as repeated next-token prediction that scales from simple count tables to Transformers and, in the process, learns useful structure about language and the world.
- Language modeling is predicting the next token from prior context.
- Small models make the core idea visible: bigrams, MLPs, and character RNNs all learn sequence statistics.
- As context and scale grow, simple tables fail and neural nets with embeddings and recurrence or attention generalize better.
- Pretraining compresses large text corpora into weights, and generation is repeated sampling from the next-token distribution.
- These systems are tools, not selves, and they work best when the needed information is present in context.
Language modeling is next-token prediction
Karpathy’s starting point is simple: a language model learns a probability distribution over what token should come next given the tokens so far. GPT-style systems generate by repeating that step again and again, which is why text generation can be understood as sequence completion rather than a mysterious separate process.12
That setup also explains the core autoregressive constraint: the model predicts using only prior context, not future tokens. In GPT-style models this is enforced structurally, so generation is always conditioned on the left context already in the sequence.1
Small language models reveal the whole game
Karpathy repeatedly uses tiny educational models because they expose the essential mechanics without the scale. In a character-level setting, a bigram model counts transitions between characters, turns those counts into probabilities, and samples from them to produce new strings.4
This is useful precisely because its limitations are obvious. With only one-character context, predictions are weak, and extending count tables to longer contexts quickly becomes impractical because the number of possible contexts grows explosively.45
For Karpathy, these toy systems are not a different idea from modern LLMs; they are the same objective in a simpler form. The forward pass becomes more sophisticated, but the training machinery and the goal of improving next-token predictions stay the same.4

“None of this will fundamentally change. The only thing that will change is the way we do the forward pass where we take in some previous characters and calculate the logits for the next character in a sequence. That will become more complex, and, uh, but we'll use the same machinery to optimize it. And, um, it's not obvious how we would have extended this bigram approach into the case where there are many more characters at the input because eventually these tables would get way too large because there's way too many combinations of what previous characters, uh, could be.”Podcast/video interview, 2020-11 · full transcript →
Neural networks matter because they generalize beyond lookup tables
Once raw counting breaks down, Karpathy moves to embeddings and neural nets. His key point is that embeddings let models share statistical strength across similar contexts, so the system is not memorizing every possible sequence as a separate case.65
That is why an MLP can outperform a naive table-based approach on character prediction: it can use multiple previous tokens while learning distributed representations that transfer across contexts. In his framing, this is the first clear step from brittle memorization toward generalization in language modeling.67
The same broad story appears in recurrent models. RNNs process variable-length sequences by reusing the same computation at each step, which makes them natural sequence models even though plain RNNs often need LSTM or GRU improvements to work well in practice.
Language models learn structure that was not hand-coded
A major part of Karpathy’s view is that sequence prediction can induce surprisingly rich internal structure. In character-level RNNs, the model begins to infer higher-level regularities such as word boundaries and other recurring patterns directly from raw sequences.
This is why language modeling is more than autocomplete in a narrow sense. By trying to predict what comes next across many examples, the model can pick up latent structure in text and support open-ended generation across domains like poetry, code, and other symbolic sequences.
At larger scale, he extends the same intuition to world knowledge: pretraining appears to build some internal knowledge store because predicting the next token across internet-scale text forces the model to absorb broad regularities about facts, style, and relations.
Transformers scale the same objective far better
For GPT-style language models, Karpathy treats the Transformer as the neural network that makes large-scale next-token prediction work well. The architecture replaces recurrence with self-attention and feed-forward computation, but it still serves the same autoregressive objective.141
He describes decoder-only GPT as a model built specifically for unconditioned text generation: no encoder, no cross-attention, just masked self-attention and feed-forward blocks stacked repeatedly. That masking preserves the left-to-right property required for language modeling.1
He also presents the practical side clearly: a large language model can be thought of as learned weights plus code to run them, and pretraining is the hard part because scaling this objective requires substantial compute and infrastructure.16
Use language models as tools shaped by context
Karpathy is careful not to anthropomorphize language models. Even when they appear fluent, he frames them as fixed learned functions that operate over a token context window and produce next-token probabilities, not as persistent selves.
That leads to a practical rule: models do best when the needed information is in context already. If the answer can be assembled from what is present in the window, performance is much stronger than when users expect stable internal state or hidden long-term memory beyond the current interaction.
His product-level advice follows from that view. These systems are most useful when treated as tools that can be directed, scaffolded, and given the right context rather than treated as autonomous beings.
Where to watch
Andrej Karpathy on GPT From Scratch: How ChatGPT Works2022 · 116 min · full transcriptBest single walkthrough of language modeling from tokenization and tiny datasets to the GPT autoregressive setup.
Andrej Karpathy on Character-Level Language Modeling: Building makemore2020 · 118 min · full transcriptShows the simplest working language model—bigram character prediction—so you can see probabilities, sampling, and evaluation directly.
Andrej Karpathy on MLPs for Language Modeling: makemore2020 · 76 min · full transcriptExplains why count tables stop scaling and how embeddings plus an MLP let language models generalize.
Andrej Karpathy on Recurrent Neural Networks: LSTMs and Captioning2017 · 70 min · full transcriptGives the recurrent-model view of language modeling and why sequence state helps with variable-length inputs.
Andrej Karpathy on Large Language Models: from pretraining to agents2024 · 60 min · full transcriptConnects small educational models to modern LLMs by framing pretraining as compression and generation as repeated sampling.
Andrej Karpathy on GPT-2 Reproduction: Rebuilding 124M From Scratch2022 · 241 min · full transcriptBest for seeing how a real GPT-2 language model is assembled in code from attention, MLP, and decoder-only blocks.
Questions people ask
- What did Andrej Karpathy say changes when you move from bigram models to transformers?
- Why did Andrej Karpathy say bigram language models break down with more context?
- Why did Andrej Karpathy say the model he built is decoder-only?
- How does Andrej Karpathy compare GPT-3 scale to the model he built in the lecture?
- How does Andrej Karpathy sample from a trained language model?
- What did Andrej Karpathy say about whether reasoning models can generalize beyond math and code?
Sources
Every quote above, word for word from the transcripts. Numbers match the text.
“What we implemented here is a decoder-only Transformer. So there's no component here — this part is called the encoder — and there's no cross-attention block here. Our block only has a self-attention and the feed-forward, so it is missing this third in-between piece here. This piece does cross-attention, so we don't have it, and we don't have the encoder; we just have the decoder. And the reason we have a decoder-only, uh, is because we are just uh generating text and it's unconditioned on anything. We're just—we're just blabbering on according to a given data set. What makes it a decoder is that we are using the triangular mask in our uh Transformer, so it has this autoregressive property where we can just uh go and sample from it.”
“…this network then dreams internet documents…”
“None of this will fundamentally change. The only thing that will change is the way we do the forward pass where we take in some previous characters and calculate the logits for the next character in a sequence. That will become more complex, and, uh, but we'll use the same machinery to optimize it. And, um, it's not obvious how we would have extended this bigram approach into the case where there are many more characters at the input because eventually these tables would get way too large because there's way too many combinations of what previous characters, uh, could be.”
“That the predictions from this model are not very good because you only take one character of context. So the model didn't produce very name-like sounding things. Now, the problem with this approach, though, is that if we are to take more context into account when predicting the next character in the sequence, things quickly blow up, and this table—the size of this table—grows, and in fact it grows exponentially with the length of the context. Because if we only take a single character at a time, that's 27 possibilities of context. But if we take two characters in the past and try to predict the third one, suddenly the number of rows in this matrix, you can look at it that way, is 27 * 27. So there's 729 possibilities for what could have come in the context.”
“…you can transfer knowledge through that embedding, and you can generalize in that way.”
“…the model now works much better.”
“Transformer is the neural net that actually does all the heavy lifting under the hood…”
“But otherwise, these hyperparameters should be fairly recognizable to you, and the architecture is actually like nearly identical to what we implemented ourselves. But of course, it's a massive infrastructure challenge to train this. You're talking about typically thousands of GPUs having to, you know, talk to each other to train models of this size. So that's just a pre-training stage now.”
How this guide was made: drafted with AI from the full transcripts of the recordings cited, then checked: every quotation must match a transcript word for word and be the speaker's own words, and an independent review gates accuracy. Methodology and corrections.

