Andrej Karpathy on Transformers
Karpathy treats Transformers as the core computation behind GPT: a fixed next-token predictor that builds rich representations through attention, MLPs, and tokenized context.
- Transformers are the main neural network doing the work inside GPT-style models.
- For GPT, Karpathy emphasizes the decoder-only Transformer: autoregressive, masked, and built to predict the next token from prior context.
- He explains Transformer blocks as a loop where attention lets tokens communicate and the MLP processes each token individually.
- Tokenization is not a side detail; it shapes model behavior and causes many failures people wrongly blame on the Transformer itself.
- He places Transformers inside a broader software shift: learned behavior from data and prompts rather than hand-written rules.

“Transformer is the neural net that actually does all the heavy lifting under the hood…”Conference keynote, 2022 · 2:12
Transformers are the engine inside GPT
Karpathy’s basic framing is straightforward: GPT is a language model that predicts the next token, and the Transformer is the neural network that performs that prediction. He repeatedly presents the Transformer as the core computation layer under the product surface of systems like ChatGPT.12
He also strips away mystique around the model. In his explanation, a large language model can be understood operationally as learned weights plus the code that runs them, which makes the Transformer less like a hidden mind and more like a concrete machine for sequence prediction.23
That view matters because it keeps attention on mechanism. If you want to understand what GPT can and cannot do, Karpathy thinks you should inspect the architecture, the context window, the tokenization, and the training setup instead of imagining a persistent self behind the interface.41

“Transformer is the neural net that actually does all the heavy lifting under the hood…”Conference keynote, 2022 · full transcript →
GPT uses a decoder-only Transformer with causal masking
Karpathy emphasizes that GPT is not just any Transformer. It is a decoder-only Transformer, which means the model is set up for autoregressive generation: each position can use earlier tokens but not future ones.56
His compact way to express that rule is that future tokens cannot send information backward. That causal constraint is what makes next-token prediction possible and turns the architecture into a text generator rather than a bidirectional reader.65
He also makes this practical: once you understand the decoder-only setup, many GPT behaviors become easier to reason about. The model continues a sequence based on available context, so performance depends heavily on what is already present in the prompt and token window.45

“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.”Conference keynote, 2022 · full transcript →
Attention and MLPs divide the work of communication and computation
Karpathy gives a useful mental model for Transformer blocks. Attention is the part where tokens exchange information, while the MLP is the part where each token processes what it has gathered.7
He describes the architecture as a repeated pattern: attention first aggregates relevant context, then the feed-forward network transforms each position’s representation. Over many blocks, this repeatedly refines the residual stream into something useful for predicting the next token.7
This framing helps explain why Transformers are powerful without making them mystical. Their strength comes from stacking simple operations that let information move across the sequence and then be reworked locally again and again.73

“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-11 · full transcript →
Tokenization quietly shapes what Transformers can do well
Karpathy is unusually emphatic that tokenization is central to understanding Transformer behavior. He warns that many apparent model failures are actually caused upstream by how text is chopped into tokens.8910
That has direct consequences for spelling, string manipulation, non-English text, whitespace, arithmetic quirks, and structured formats. In his view, if you ignore tokenization, you will misdiagnose the model.910
He also pushes the idea into practice. Token efficiency affects cost, context usage, and prompt design, so choices like formatting data more compactly can matter in real systems. At the same time, he clearly hopes the field eventually finds a way beyond today’s tokenization bottlenecks.11

“So tokenization is at the heart of a lot of weirdness in large language models, and I would advise that you do not brush it off. A lot of the issues that may look like just issues with the neural network architecture or the large language model itself are actually issues with the tokenization and fundamentally trace back to it. So if you've noticed any issues with large language models — can't, you know, not able to do spelling tasks very easily — that's usually due to tokenization. Simple string processing can be difficult for the large language model to perform natively. Non-English languages can…”Talk / tutorial presentation, 2019 · full transcript →
Transformers matter because they changed how software is built
Karpathy connects Transformers to a broader shift in programming. He calls the learned-model paradigm software 2.0, where behavior is defined less by explicit code and more by data, optimization, and model weights.142
On top of that, he argues that prompting has become a real programming interface. When language is the interface to a Transformer, good context and instructions become part of engineering, not just UX copy.1516
That is why he treats Transformers as both a scientific and practical object. Understanding their internals helps you reason about limits and failure modes, but understanding their interface helps you build better systems around them.1615
Karpathy on transformers, in his own words
“Transformer is the neural net that actually does all the heavy lifting under the hood…”
“The future cannot communicate with the past…”
“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.”
Where to watch
Andrej Karpathy on GPT From Scratch: How ChatGPT Works2022 · 116 min · full transcriptBest conceptual walkthrough of how GPT maps from text sequences to a decoder-only Transformer with attention and masking.
Andrej Karpathy on GPT-2 Reproduction: Rebuilding 124M From Scratch2022 · 241 min · full transcriptBest for seeing the Transformer block concretely in GPT-2: embeddings, attention, MLPs, layer norms, and implementation details.
Andrej Karpathy on Tokenization: Building GPT's Tokenizer2019 · 134 min · full transcriptBest for understanding why tokenization strongly affects Transformer behavior, capabilities, and failures.
Andrej Karpathy on Large Language Models: How ChatGPT Works2022 · 211 min · full transcriptBest general-audience explanation of how Transformer-based LLMs work in practice and how to use them effectively.
Andrej Karpathy on Large Language Models: from pretraining to agents2024 · 60 min · full transcriptBest short practical overview of pretraining, inference, assistants, and how Transformer models fit into products.
Andrej Karpathy on AI Engineering: Programming Is Changing Fast2024 · 69 min · full transcriptBest for how Transformers change programming itself through software 2.0 and prompt-based interfaces.
Questions people ask
- What did Andrej Karpathy say about why tokenization causes strange LLM behavior?
- 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?
- What did Andrej Karpathy say about JSON versus YAML token efficiency?
- What did Andrej Karpathy say about attention and MLPs in Transformers?
- What did Andrej Karpathy say about the risks of tokenization?
Sources
Every quote above, word for word from the transcripts. Numbers match the text.
“Transformer is the neural net that actually does all the heavy lifting under the hood…”
“…a large language model is just two files…”
“…everything here is just the other weights and biases and everything else of this Transformer…”
“…the answer is already created, it's already in the token window…”
“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.”
“The future cannot communicate with the past…”
“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.”
“…tokenization is my least favorite part of working with large language models…”
“A lot of the issues that may look like just issues with the neural network architecture or the large language model itself are actually issues with the tokenization…”
“So tokenization is at the heart of a lot of weirdness in large language models, and I would advise that you do not brush it off. A lot of the issues that may look like just issues with the neural network architecture or the large language model itself are actually issues with the tokenization and fundamentally trace back to it. So if you've noticed any issues with large language models — can't, you know, not able to do spelling tasks very easily — that's usually due to tokenization. Simple string processing can be difficult for the large language model to perform natively. Non-English languages can…”
“More efficient in tokens. Um, so for example, these are the same in JSON and in YAML. The JSON is 116 and the YAML is 99, so quite a bit of an improvement. And so in the token economy, where we are paying per token in many ways, and you are paying in the context length, and you're paying in, um, dollar amount for the cost of processing all this kind of structured data, when you have to, um, so prefer to use the YAML over JSON. And in general, kind of like, the tokenization density is something that you have to, um, sort of care about and worry about at all times and try to find efficient encoding schemes, and spend a lot of time in the tokenizer, and measure the different token efficiencies of different formats and settings and so on.”
“I call it software 2.0.”
“The hottest new programming language is English.”
“…use it as a tool in a toolbox…”
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.
