Skip to content
Stanford CS25: V2 I Introduction to Transformers w/ Andrej Karpathy
This video isn’t embeddableWatch on YouTube →
Stanford OnlineStanford Online

Stanford CS25: V2 I Introduction to Transformers w/ Andrej Karpathy

January 10, 2023 Introduction to Transformers Andrej Karpathy: https://karpathy.ai/ Since their introduction in 2017, transformers have revolutionized Natural Language Processing (NLP). Now, transformers are finding applications all over Deep Learning, be it computer vision (CV), reinforcement learning (RL), Generative Adversarial Networks (GANs), Speech or even Biology. Among other things, transformers have enabled the creation of powerful language models like GPT-3 and were instrumental in DeepMind's recent AlphaFold2, that tackles protein folding. In this speaker series, we examine the details of how transformers work, and dive deep into the different kinds of transformers and how they're applied in different fields. We do this by inviting people at the forefront of transformers research across different domains for guest lectures. More about the course can be found here: https://web.stanford.edu/class/cs25/ View the entire CS25 Transformers United playlist: https://www.youtube.com/playlist?list=PLoROMvodv4rNiJRchCzutFw5ItR_Z27CM 0:00 Introduction 0:47 Introducing the Course 3:19 Basics of Transformers 3:35 The Attention Timeline 5:01 Prehistoric Era 6:10 Where we were in 2021 7:30 The Future 10:15 Transformers - Andrej Karpathy 10:39 Historical context 1:00:30 Thank you - Go forth and transform

Andrej Karpathyguest
May 19, 20231h 11mWatch on YouTube ↗

Summaries, chapters, transcripts, and FAQs on this page are made by uListen, not YouTube.

At a glance

WHAT IT’S REALLY ABOUT

Karpathy Explains Transformers: History, Attention Mechanics, NanoGPT Code, and Why They Dominate

  1. The instructors open the course by presenting a timeline from RNNs and LSTMs through the 2017 Attention Is All You Need paper to generative models and ChatGPT, and by listing open challenges such as long-term memory, quadratic attention cost, and controllability.
  2. Karpathy describes how AI went from fragmented, hand-engineered pipelines and separate vocabularies per subfield to a single converged architecture that gets copy-pasted across vision, language, speech, and RL.
  3. He traces attention's lineage from early neural language models and sequence-to-sequence encoders to the soft-search attention paper, including an email from its first author about how translation exercises inspired it.
  4. He frames attention as a communication phase (data-dependent message passing between nodes using queries, keys, and values) alternating with an MLP computation phase, then walks through a roughly 300-line NanoGPT implementation covering decoder-only, encoder, and cross-attention variants.
  5. He argues transformers succeed because they are expressive, optimizable, and efficient on GPUs, and he discusses in-context learning, flexibility across modalities, and ideas like scratchpad memory in the Q&A.

IDEAS WORTH REMEMBERING

5 ideas

Architectures converged into one reusable design

Karpathy says that after 2012 neural nets unified toolkits across AI fields, and the 2017 transformer went further by making the architecture itself nearly identical everywhere, with only data handling changing.

Attention was born from fixing the encoder bottleneck

Packing a whole source sentence into one vector was seen as too limiting, so the soft-search paper let the decoder look back at encoder states via a weighted sum; its author said the idea was inspired by gaze shifting between source and target when translating.

Attention is communication; the MLP is computation

Each node emits a query, key, and value; query-key dot products are softmaxed into weights that sum values from nodes pointing to it, and the MLP then processes each node individually.

Encoder, decoder, and cross-attention differ only in small details

A decoder-only model masks future tokens with negative infinity before softmax, an encoder simply deletes that mask, and cross-attention takes keys and values from the top of the encoder while queries come from the decoder.

The 2017 architecture has proven remarkably resilient

Karpathy notes that GPTs are basically the 2017 design, with only changes like pre-norm layer norm placement and rotary or relative positional encodings sticking, while many other tweaks did not.

WORDS WORTH SAVING

5 quotes

Transformer is a ResNet.

— Andrej Karpathy

I probably would've called the transformer a general purpose efficient optimizable computer instead of, uh, attention is all you need.

— Andrej Karpathy

When I sample text, I don't go chunk, chunk, chunk and commit. I, uh, I do a draft one, and then I do a better draft two, and that feels like a diffusion process.

— Andrej Karpathy

in deep learning scale matters. And so the size of the network that you can train, uh, uh, gives you, uh, is extremely important. And so if it's efficient on the current hardware, then we can make it bigger.

— Andrej Karpathy

It's just like human learning to use a, a notepad, right? You don't have to keep it in your brain. So keeping things in your brain is kind of like the context line for the transformer. But maybe we can just give it a notebook, and then it can query the notebook, uh, and read from it and write to it.

— Andrej Karpathy

Transformer timeline and future directionsEncoder bottleneck and origin of attentionAttention as message passing (queries, keys, values)NanoGPT decoder-only implementationSelf-attention vs cross-attention and maskingTransformers across vision, speech, RL, and biologyIn-context learning and efficiency on GPUs

High quality AI-generated summary created from speaker-labeled transcript.

Get more out of YouTube videos.

Read along on your phone, search it beside the video, or ask your favorite AI app what was said.