Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 06 · AI · GPT, built from scratch · with code: Python · about 21 min to read

Play it as a journeyTutor comes with a plan

The GPT Block

From Transformer to LLM
From Transformer to LLM · Open board

The From Transformer to LLM board draws the stack of identical layers inside a language model. This lesson builds that stack at toy size: the fifth of six lessons that end with a small GPT built from scratch.

Before you start. A weight is one adjustable number inside a model, and training nudges every weight, again and again, to shrink the loss, one number for how wrong the guesses were. Validation loss is that same score measured on text held back from training. In The MLP Language Model a model that read the last eight characters of a returns-desk reply scored 0.1784 on it. From Tokens & Embeddings: an embedding is a short list of numbers that stands for one piece of text, looked up by its id. From What a Neural Network Is: a hidden layer is a row of neurons between input and answer, each adding up its inputs times weights, and ReLU after it turns every negative total into zero. From The Maths Floor, Part 2: Probability, Softmax and Temperature: softmax turns a list of scores into shares that add to 1. From Attention by Hand: in attention, each position in the text scores every earlier position, turns the scores into shares, and takes a blend of what those positions offer, weighted by the shares. Each copy running side by side is a head.

Lesson 63 of 83 in AI

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • December 2015: ResNet, when a deeper network did worse
  • The residual connection: add a note, never rewrite the file
  • Layer norm: rescale the file before each clerk reads it
  • The feed-forward layer: each file, thought about alone
  • The transformer block, stacked four deep
  • The whole tiny GPT, trained
  • One clerk pair, one file
  • Building the whole desk
  • The run, and what each number says
  • All of it in code

Terms it explains: From Transformer to LLM, residual connection, residual stream, layer norm, feed-forward layer, transformer block, alignment, autoregressive, base model, Chinchilla, decoder-only, distribution, emergent ability, in-context learning, logits, next-token prediction, parameters / data / compute, pretraining, scaling laws, self-supervised.

Related papers

Review AI