Topic guide · 7 recordings · 16 verbatim quotes

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.

In short
  • 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.
Watch: Karpathy on transformersThe key moments, back to back, in his own words
5 moments · 4 min
1 / 5
“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

Andrej Karpathy, Conference keynote, 2022
“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

Andrej Karpathy, Conference keynote, 2022
“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

Andrej Karpathy, OpenAI / online talk, 2022-11
“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

Andrej Karpathy, Talk / tutorial presentation, 2019
“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…”
Conference keynote, 2022
“The future cannot communicate with the past…”
Conference keynote, 2022
“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 →

Where to watch

  1. 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.
  2. 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.
  3. Andrej Karpathy on Tokenization: Building GPT's Tokenizer2019 · 134 min · full transcriptBest for understanding why tokenization strongly affects Transformer behavior, capabilities, and failures.
  4. 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.
  5. 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.
  6. 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

Go deeper · free courseThe Andrej Karpathy Course13 chapters on everything Karpathy taught, with a certificate at the end.Start learning →

Sources

Every quote above, word for word from the transcripts. Numbers match the text.

1
“Transformer is the neural net that actually does all the heavy lifting under the hood…”
Conference keynote, 2022
2
“…a large language model is just two files…”
Intro to Large Language Models, YouTube interview, 2024
3
“…everything here is just the other weights and biases and everything else of this Transformer…”
OpenAI / online talk, 2022-11
4
“…the answer is already created, it's already in the token window…”
Deep Dive into LLMs like ChatGPT, 2022
5
“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, 2022answer page →
6
“The future cannot communicate with the past…”
Conference keynote, 2022
7
“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 →
8
“…tokenization is my least favorite part of working with large language models…”
Talk / tutorial presentation, 2019
9
“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…”
Talk / tutorial presentation, 2019
10
“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, 2019answer page →
11
“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.”
Talk / tutorial presentation, 2019answer page →
14
“I call it software 2.0.”
Stanford lecture, 2024
15
“The hottest new programming language is English.”
Stanford lecture, 2024
16
“…use it as a tool in a toolbox…”
Deep Dive into LLMs like ChatGPT, 2022

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.

All 7 recordings of Andrej Karpathy on Transformers

Andrej Karpathy on Large Language Models: How ChatGPT Works3:31:24

Andrej Karpathy on Large Language Models: How ChatGPT Works

2022 · 10M views

Karpathy explains how ChatGPT-like models are built, trained, and used, plus their limits and implications. Deep Dive into LLMs like ChatGPT, 2023.

Andrej Karpathy on GPT From Scratch: How ChatGPT Works1:56:20

Andrej Karpathy on GPT From Scratch: How ChatGPT Works

2022 · 8.3M views

Karpathy builds a GPT-style Transformer from first principles, explains tokenization, attention, and how ChatGPT differs from pretraining and fine-tuning, in a 2022 keynote.

Andrej Karpathy on Large Language Models: from pretraining to agents59:48

Andrej Karpathy on Large Language Models: from pretraining to agents

2024 · Interview · 4.4M views

Karpathy explains how LLMs work, how they’re trained and fine-tuned, and where tools, multimodality, and agents are headed in 2024.

Andrej Karpathy on Tokenization: Building GPT's Tokenizer2:13:35

Andrej Karpathy on Tokenization: Building GPT's Tokenizer

2019 · 1.3M views

Karpathy explains how LLM tokenizers work, why they cause odd behavior, and how GPT-2/GPT-4 tokenization differs in a tutorial presentation.

Andrej Karpathy on GPT-2 Reproduction: Rebuilding 124M From Scratch4:01:26

Andrej Karpathy on GPT-2 Reproduction: Rebuilding 124M From Scratch

2022 · 1.2M views

Karpathy rebuilds GPT-2 124M from scratch, explaining the architecture, training setup, and speedups like Torch Compile and Flash Attention at an OpenAI talk in 2022.

Andrej Karpathy on AI and Robotics: Models, Agents, and Education44:17

Andrej Karpathy on AI and Robotics: Models, Agents, and Education

2024 · Interview · 244K views

Karpathy discusses self-driving, humanoid robots, LLMs, synthetic data, and education in a No Priors interview from Feb. 2024.

Andrej Karpathy on AI Engineering: Programming Is Changing Fast1:08:31

Andrej Karpathy on AI Engineering: Programming Is Changing Fast

2024 · 6K views

Karpathy explains software 1.0, 2.0, and 3.0, prompt engineering, and why LLMs are changing programming, in a Stanford lecture from 2024.

Search every transcript
Open the full search page →