Save this video free

Let's build GPT: from scratch, in code, spelled out.

Andrej Karpathy · 1:56:20 · Watch on YouTube

These notes were made with YouTube Collector. Paste any YouTube link and get the same: a summary, chapters and a searchable transcript.

Overview

Andrej Karpathy builds a decoder-only GPT in PyTorch from an empty file, training a character-level model on roughly one million Tiny Shakespeare characters and explaining each step from tokenization and batching to causal self-attention, multi-head blocks, residual connections, layer normalization, and dropout. The resulting model has about 10 million parameters and reaches a validation loss near 1.48; Karpathy then connects the implementation to nanoGPT and explains how large-scale pretraining differs from the supervised fine-tuning and preference-optimization stages used to make ChatGPT an assistant.

Key takeaways

Chapters

0:00 ChatGPT as a Probabilistic Language Model
7:53 Tiny Shakespeare, nanoGPT, and the Build Plan
10:30 Character and Subword Tokenization
12:46 Train and Validation Data, Context Windows, and Batches
22:13 The Bigram Baseline and Cross-Entropy Loss
29:00 Autoregressive Generation from the Model
34:49 Training the Bigram Model with Adam
38:02 A Reusable Training Script and Evaluation Loop
42:13 Causal Averaging as a Model of Token Communication
58:24 Vectorized Attention Weights and Positional Embeddings
1:02:00 Queries, Keys, and Data-Dependent Self-Attention
1:11:34 Values and Attention as a Communication Mechanism
1:17:00 Why Scaled Dot-Product Attention Divides by Square Root of Head Size
1:19:13 Implementing a Causal Self-Attention Head in PyTorch
1:22:01 Multi-Head Attention Runs Communication Channels in Parallel
1:24:27 Feed-Forward Networks Add Per-Token Computation
1:26:49 Transformer Blocks and Residual Connections
1:32:51 Layer Normalization and the Pre-Norm Transformer
1:37:21 Scaling the GPT with Dropout and a Longer Context
1:42:24 Why GPT Uses a Decoder-Only Transformer
1:46:24 How nanoGPT Relates to the From-Scratch Implementation
1:48:55 ChatGPT Pretraining, Supervised Fine-Tuning, and RLHF
1:54:32 What the GPT Build Demonstrates and Leaves Out

Keep these chapters and the full searchable transcript in your own library.

Transcript excerpt

0:00 hi everyone so by now you have probably heard of chat GPT it has taken the world and AI Community by storm and it is a system that allows you to interact with an AI and give it text based tasks so for example we can ask chat GPT to write us a small Hau about how important it is that people understand Ai and then they can use it to improve the world and make it more prosperous so when we run this AI knowledge brings prosperity for all to see Embrace its power okay not bad and so you could see that chpt went from left to right and generated all these words SE sort of sequentially now I asked it already the exact same prompt a little bit earlier and it generated a slightly different outcome ai's power to grow ignorance holds us back learn Prosperity weights so uh pretty good in both cases and

0:49 slightly different so you can see that chat GPT is a probabilistic system and for any one prompt it can give us multiple answers sort of uh replying to it now this is just one example of a problem people have come up with many many examples and there are entire websites that index interactions with chpt and so many of them are quite humorous explain HTML to me like I'm a dog uh write release notes for chess 2 write a note about Elon Musk buying a Twitter and so on so as an example uh please write a breaking news article about a leaf falling from a tree uh and a shocking turn of events a leaf has fallen from a tree in the local park Witnesses report that the leaf which was previously attached to a branch of a tree attached itself and

This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.

Related notes

Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Andrej Karpathy.

Want the full transcript?

Save this video in YouTube Collector to get its complete searchable transcript, your own AI summaries, and a library that keeps every video you collect in one place.