Skip to main content
Primary: Phase 6Used in Phases 5, 6Video LectureAdvancedFree Learning Material
Andrej Karpathy

Let's Build GPT: From Scratch

Standalone 2-hour hands-on video lecture building and training a generative pretrained Transformer (GPT) from an empty Python script.

In this famous standalone coding lecture, Andrej Karpathy starts with a blank file, loads the TinyShakespeare dataset, constructs a baseline bigram language model, writes the training and evaluation loop, and incrementally builds up self-attention, multi-head causal attention, feed-forward blocks, residual connections, LayerNorm, and autoregressive token generation.

Resource Tracking

Course status is tracked independently from roadmap topic checkboxes so you can mark external courses without altering your topic mastery percentage.

Suggested Learning Position

Phase 5–6 Bridge Video Lecture (Building & Training GPT End-to-End)

Documented Duration:1h 56m video lecture
Language:English
Access & Link Verification

100% free full-length video lecture on YouTube with open-source Colab notebook and GitHub code (`ng-video-lecture`).

Status: Verified (2026-11-09)

What You Will Learn from This Resource

  • Write a clean batch sampler, training loop, and validation loss estimator for causal language modeling.
  • Assemble a complete decoder-only Transformer and verify loss decreases at each architectural step.
  • Generate new text autoregressively from your trained checkpoint.

Recommended Prerequisites

Review these foundations before starting so you get the most out of this material:

  • PyTorch fundamentals and autoregressive language modeling (Phases 3 & 4).

Topics & Keywords

Andrej KarpathyGPTVideo LecturePretrainingPyTorchFrom Scratch
Curriculum Integration

How This Resource Fits Into Your AI & LLM Roadmap

Open Interactive Roadmap

Phase-Specific Study Recommendations (1)

Phase 6 · Resource 6.2Additional Learning

Let's Build GPT: From Scratch

In Phase 6: Train Your Own LLM

Follow along and code every line before scaling up your Phase 6 pretraining pipeline (`MyLLM v1`).

Continue Exploring
Browse Full Library
Phases 3, 4, 5Recommended StartVideo Series
Andrej Karpathy
IntermediateFree Learning Material

Neural Networks: Zero to Hero

A code-first introduction to neural networks covering automatic differentiation, backpropagation, language models, and GPT implementations.

Used across:Phase 3 (3.1)Phase 4 (4.3)Phase 5 (5.1)
Andrej KarpathyMicrogradMakemoreBackpropagationAutograd
Your Status:
Phases 5, 6GitHub Repository
Andrej Karpathy
AdvancedFree Learning Material

nanoGPT

The simplest, fastest, and most readable open-source repository for training and fine-tuning medium-sized GPT language models (~300 lines of model code and ~300 lines of training loop).

Used across:Phase 5 (5.4)Phase 6 (6.3)
nanoGPTAndrej KarpathyGPT-2PyTorchPretraining
Your Status:
Phases 5, 6, 8Recommended StartUniversity Course Materials
Stanford University
AdvancedFree Learning Material

CS336 — Language Modeling from Scratch

Graduate-level Stanford course walking through every aspect of building language models from scratch: Transformer architecture, tokenization, pretraining data pipelines, GPU systems, parallelism, and scaling laws.

Used across:Phase 5 (5.2)Phase 6 (6.1)Phase 8 (8.1)
StanfordCS336Language ModelingPretrainingScaling Laws
Your Status: