
Build GPT: a tutorial for the next stage
HackerTube viewing guide · Source-checked November 2, 2026
Before you press Play
Choose this when you can already train and evaluate a small language model and want to understand why attention changes the context it can use. Starting here with no tensor background makes the mechanics harder to separate from the syntax.
Makemore’s first lecture predicts from one previous character. This lecture develops a longer-context Transformer. It is a training implementation, not a tutorial on calling a hosted chat API.
Work toward these outcomes
- Develop a character-level next-token model from a bigram baseline.
- Explain causal self-attention, multi-head attention and the main Transformer block components.
- Train and sample from a small GPT-style model while distinguishing this exercise from building a production ChatGPT service.
Bring these foundations
- The earlier makemore lessons: the author explicitly recommends them.
- Comfort with tensor dimensions, matrix multiplication, loss evaluation and torch.nn.
- Use the original notebook or code; full training cost depends on your model size and hardware.
A useful readiness check
Before scaling up, explain the shape of the attention-score matrix and why future positions are masked. Compare training and validation loss, rather than treating fluent-looking samples as proof of generalization.
Build GPT tutorial chapters
Selected landmarks from the creator’s chapter list (1:56:20 total). Choose a timestamp to load the YouTube player at that point; without JavaScript, the link opens YouTube.
- 9:28tokenization, train/val split
- 22:11simplest baseline: bigram language model, loss, generation
- 47:11the trick in self-attention: matrix multiply as weighted aggregation
- 1:02:00THE CRUX OF THE VIDEO: version 4: self-attention
- 1:21:59multi-headed self-attention
- 1:26:48residual connections
- 1:32:51layernorm (and its relationship to our previous batchnorm)
- 1:46:22super quick walkthrough of nanoGPT, batched multi-headed self-attention
See every chapter in the creator’s description
Creator corrections to keep beside the video
- Creator correction at 57:00: tokens from the future cannot communicate; “past” was a verbal slip.
- Creator correction at 1:20:05: attention normalization should use head_size, not C.
- The lecture repository notes an initialization limitation and slower convergence. Read that note before assuming the lecture code is the current nanoGPT implementation.
Original course files and resources
- Neural Networks: Zero to Hero syllabus
- Original lecture code and author’s initialization note
- Original lecture notebook (Colab)
- nanoGPT implementation
Next in your learning path
About this video
Andrej Karpathy builds a GPT from scratch in code, following Attention Is All You Need and GPT-2/3, in about two hours using PyTorch. He connects it to ChatGPT and assumes familiarity with his earlier makemore videos.
Why it appears in the archive
It is the go-to recommendation for learning how transformers and LLMs actually work, praised for its clarity and Karpathy's teaching.
AI-generated summary and labels from the source dataset; verify important details against the video. Source & credits.
From the Hacker News discussion
Great compilation, would be great to see Vision Transformer (ViT) included. Andrej Karpathy's GPT video is a must have companion for this [VIDEO] I was going nuts trying to grok Key, Query,Position and Value until Andrej broke it down for me.
Read original comment ↗Very impressive. Recently I watched this really amazing lecture on building GPT from scratch from Karpathy, I was blown away: [VIDEO]
Read original comment ↗Andrej Karpathy, the director of AI at tesla, published an AMAZING video about how the current models are built which I think everyone in the tech space should watch. It is intuitive, easy to follow and quite frankly the best video I have seen on the topic. Here is the link: [VIDEO] If you conclude, after watching this, that this is all intelligence is - namely cascading optimization and data structure problems chained in a row, then you and a fair number of people here wont ever find common ground. That is not to say that you're wrong, it just seems as if there is a missing component here that we haven't yet discovered.
Read original comment ↗+1, Andrey is an amazing educator! I'd also recommend his [VIDEO] and checking out his github repos. MinGPT, for example, implements a small gpt model that's compatible with HF API, whereas more modern nanoGPT shows how to use newer features such as flash attention. The quality of every video, every blog post is just so high.
Read original comment ↗I recommend this video on the subject. "Let's build GPT: from scratch, in code, spelled out." [VIDEO]
Read original comment ↗I think you are taking a very major assumption that LLMs are deterministic infact they are exactly opposite. They are probabilistic systems. - They do not transpile Rough English to Deterministic English. Infact they do not do any transpiling at all. - LLMs learn the probabilities of words in the dataset for all contexts from that dataset (context is a ordered set of words). This is called training. - Once training is done, LLMs can generate text given a prompt and the probabilities that it has learned. The analogy of LLMs being auto-complete on steroids is very apt. - Whether the text generated by LLMs is factual or not is purely coincidental. I would highly recommend watching and working though the code (if possible) of NanoGPT by Andrej Karpathy. [VIDEO] A lot of things which seem like magic about LLMs will get demystified. Now one can argue that LLMs are showing human like reasoning/intelligence/sentience as an emergent behavior. This is hard to argue against because all these terms are extremely hard to define. IMO, the only emergent behavior that LLMs are showing is the output they generate looks like it might have been generated by a human which should not be surprising given that LLMs like ChatGPT has trained on a large amount of human written text available on internet.
Read original comment ↗Here are a few resources that might help get you started: 1. A thread explaining the internal working of transformers: [LINK] 2. Paper by DeepMind which provides pseudo-code for important algorithms for Transformer models: [LINK] 3. Another thread specifically on large language models: [LINK] Once again these are not courses per se, but do provide intuitive explanations for how transformers work. There is also the nanoGPT series of videos by Karpathy on youtube. First video here: [VIDEO]
Read original comment ↗I agree that Karpathy's YouTube video is an excellent resource for understanding Transformers from scratch. It provides a hands-on experience that can be particularly helpful for those who want to implement the models themselves. Here's the link to the video titled "Let's build GPT: from scratch, in code, spelled out": [VIDEO] Additionally, for more comprehensive resources on Transformers, you may find these resources useful: * The Illustrated Transformer by Jay Alammar: [LINK] * MIT 6.S191: Recurrent Neural Networks, Transformers, and Attention: [LINK] * Karpathy's course, Deep Learning and Generative Models (Lecture 6 covers Transformers): [LINK] ... These resources cover different aspects of Transformers and can help you grasp the underlying concepts and mechanisms better.
Read original comment ↗