Why did Andrej Karpathy say the model he built is decoder-only?

Andrej Karpathy said it is decoder-only because it is generating text without conditioning on any separate input. He explained that the triangular mask makes the model autoregressive, so it can sample from the past tokens while predicting the next one. That is why it matches GPT-style language modeling rather than an encoder-decoder translation system.

“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.”
— Andrej Karpathy, Conference keynote, 2022 · at 1:42:46
Andrej Karpathy: Andrej Karpathy on GPT From Scratch: How ChatGPT Works

Key takeaways

  • Use a decoder-only Transformer when you want unconditional text generation.
  • The triangular mask is what makes autoregressive language modeling possible.
  • Encoder-decoder models are for conditional tasks like translation.

Context

Near the end of the keynote, Karpathy stepped back from the code to explain the GPT architecture and how it differs from the original Transformer paper. The quote above is taken word for word from the recording's transcript.

In the transcript

…I think uh, that kind of like concludes the programming section of this video. We basically kind of uh did a pretty good job and um of implementing this Transformer, uh, but the picture doesn't exactly match up to what we've done. So what's going on with all these digital parts here? So let me finish explaining this architecture and why it looks so funky. Basically, what's happening here is

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.

triangular mask to mask out the attention makes it a decoder, and it can be used for language modeling. Now the reason that the original paper had an encoder-decoder architecture is because it is a machine translation paper, so it is concerned with a different setting. In particular, it expects some uh tokens that encode, say for example, French, and then it is expecting to decode the translation in English.…

Read the full transcript of Conference keynote, 2022

Topics

What others said about artificial intelligence

More questions about Andrej Karpathy

All Andrej Karpathy answers · All Andrej Karpathy recordings

How this answer was made: the quote is checked word for word against the transcript of the recording and confirmed as the speaker's own words; the summary above it was drafted with AI from that transcript and quality-checked. Methodology and corrections.

Search every transcript
Open the full search page →