← Course home

Lesson 02 of 07

Eight lectures that reach GPT

A map of Karpathy's eight Zero to Hero lectures, and a clear gate before you move to the tokenizer repo.

Agent brief (llms.md)

micrograd answers how a network learns. It does not show you how you get to a GPT. That path is nn-zero-to-hero, a course of eight lectures. The official syllabus is on karpathy.ai/zero-to-hero.html. The notebooks live in the repo under lectures/.

Hao's advice is to watch lecture 1 alongside the micrograd stop, because lecture 1 is the spelled-out build of that engine. The rest of the series then moves into language models. This lesson is a map, not a substitute for the videos. Do not try to finish all eight in one sitting.

The first two lectures

Lecture 1 builds micrograd. It assumes basic Python and a vague memory of high-school calculus. Video: The spelled-out intro to neural networks and backpropagation. Notebooks: lectures/micrograd.

flowchart LR
  L1["Lecture 1: micrograd"] --> Engine["A working autograd engine"]
      

Lecture 2 starts language modelling. It builds a character-level bigram model, introduces torch.Tensor, and sets up the loop you will keep seeing: train, sample, and evaluate a loss such as negative log likelihood. Video: The spelled-out intro to language modeling. Notebook: makemore_part1_bigrams.ipynb. Related repo: makemore.

flowchart LR
  L1["Lecture 1: micrograd"] --> L2["Lecture 2: bigram language model"]
  L2 --> Loop["Train, sample, evaluate a loss"]
      

The makemore lectures

Lectures 3 to 6 stay with character-level language models and make the net more capable, one idea at a time.

flowchart TD
  L1["1 micrograd"] --> L2["2 bigram model"]
  L2 --> L3["3 MLP"]
  L3 --> L4["4 activations, BatchNorm"]
  L4 --> L5["5 manual backprop"]
  L5 --> L6["6 WaveNet-style net"]
  L6 --> L7["7 GPT"]
  L7 --> L8["8 tokenizer"]
      

GPT, then the tokenizer

Lecture 7 builds a Generatively Pretrained Transformer, following Attention Is All You Need and OpenAI's GPT-2 and GPT-3. Video: Let's build GPT: from scratch, in code, spelled out. Karpathy recommends the earlier makemore videos first, so the language-modelling loop and torch.nn already feel familiar.

Lecture 8 builds the tokenizer used in the GPT series. A tokenizer is a separate stage, with its own training set and its own algorithm, Byte Pair Encoding. After training it exposes two functions: encode, which maps strings to token IDs, and decode, which maps IDs back to strings. Video: Let's build the GPT Tokenizer. Code: minbpe, which is the next stop. Colab: lecture notebook.

Hao's gate still holds. If you can rebuild micrograd's engine without looking, you are ready for stop 3, the tokenizer repo. You do not have to finish lectures 2 to 8 first. Those lectures will make stops 3 and 4 much easier, and lecture 8 is the spoken version of minbpe. Use the map, then go as deep as you have time for.

Key concepts

  • nn-zero-to-hero is eight lectures. The official syllabus is on karpathy.ai/zero-to-hero.html.
  • Lecture 1 builds micrograd. Watch it with lesson 1 of this course.
  • Lectures 2 to 6 build character-level language models, then stronger nets, better training practice, manual backprop, and a WaveNet-style architecture.
  • Lecture 7 builds a GPT. Lecture 8 builds the GPT tokenizer, and leads into the minbpe repo.
  • Hao's suggested gate: if you can rebuild the micrograd engine without looking, you are ready for the tokenizer stop.

Takeaways