Skip to content
AI from Scratch
EN

Scripts for the video course

18 videos, ~6 hours of footage. Each script comes with: running time, what to show on screen, the narrative thread, and the key moment — that instant when the viewer suddenly understands something.


Principles running through the whole course

1. Run it live, do not show screenshots. The value of this material is that everything runs. If the viewer watches a number appear in your terminal, they believe it. If they see a slide, they do not.

2. Start with the problem, never with the solution. Every video opens with something that does NOT work. The solution only makes sense afterwards.

3. Show the failures. The three documented bugs in this project are worth more than any clean explanation.

4. One idea per video. If you need two, that is two videos.

5. End with an open question that the next video answers.


BLOCK 1 · Fundamentals (4 videos · 70 min)

V1 · What does "learning" actually mean? (18 min)

Run: etapas/00_calentamiento/01_que_es_aprender.py

TimeWhat
0:00Hook: "I am going to show you an entire AI in 90 lines of Python. No libraries."
1:00The data: 12 students, hours studied and grade
3:00The model grade = w·hours + b. "Two gaps. GPT-4 has 1.8 trillion"
6:00The loss. Why squared
9:00The derivative by hand, on paper or a whiteboard
12:00RUN IT. Watch the loss come down live
15:00The ASCII chart with the fitted line
16:00Key moment: point at w -= lr * dw — "these two lines are the engine of all modern AI"

Homework: change lr to 0.1 and see what happens.

V2 · Why depth is necessary (20 min)

Run: 03_xor_a_mano.py · Diagram: figure xor

TimeWhat
0:00Hook: "This sank AI for 17 years"
2:00XOR on the whiteboard. Try to separate it with a line. Fail
5:00RUN the linear model. It predicts 0.500 for everything. It gives up
8:00Minsky and Papert, 1969. The first winter
11:00The hidden layer. Backpropagation by hand, line by line
16:00RUN IT. 4/4
18:00Key moment: the table of hidden neurons. "Nobody told them what to detect"

V3 · The exact limit of the learning rate (15 min)

Run: 02_el_paisaje_de_la_perdida.py · Web demo: learning rate

TimeWhat
0:00Hook: "0.0417 works. 0.0443 destroys the model. I am going to show you why"
3:00The landscape in ASCII. A tilted valley, not a bowl
6:00The Hessian and 2/λmax — slowly, it is the only maths in the video
9:00RUN IT: converges · explodes. The exact boundary
13:00Key moment: "This is where warm-up and cosine decay come from"

V4 · Automating the derivatives (17 min)

Run: etapas/03_autograd/01_autograd_escalar.py and verificar_gradientes.py

TimeWhat
0:00Hook: "In video 2 we wrote 20 lines of derivatives for 17 parameters. With 800,000 it is impossible"
3:00The idea: every number remembers where it came from
7:00The local rules: addition copies, multiplication crosses over
11:00RUN IT: XOR solved WITHOUT writing a single derivative
14:00RUN verificar_gradientes.py: 34/34
16:00Key moment: "Now you can differentiate anything you write"

BLOCK 2 · Language (4 videos · 75 min)

V5 · How text gets in (20 min)

Run: all of stage 01 · Web demo: tokenizer

TimeWhat
0:00Hook: type "strawberry" and ask how many r's it has
2:00Unicode → UTF-8 → bytes
6:00BPE: merge the most frequent pair
10:00RUN IT: watch 'tion', 'ing', ' the' appear
13:00Key moment: "Nobody taught it grammar. It comes out of counting"
15:00LIVE DEMO: type into the tokenizer on the website
18:00Why it cannot count letters or add up

V6 · What a language model is (16 min)

V7 · Embeddings: breaking the wall (20 min)

V8 · Embeddings do NOT do what you think (19 min)

V8 is the video that sets this course apart. Almost nobody tells this story: you measure against chance and it turns out that in the INPUT matrix the vowels do not cluster (65.7% against 64.7%) and in the OUTPUT matrix they do (81.0%). Key moment: "If I had only shown you the picture, I would have convinced you of the opposite."


BLOCK 3 · The transformer (4 videos · 90 min)

V9 · Attention, derived from scratch (25 min)

Run: stage 05 · Diagrams: atencion, mascara

TimeWhat
0:00Hook: "My grandmother's house is RED / KIND. Which word does 'is' have to look at?"
4:00Averaging the past. It works and it is stupid
8:00Query, key, value. The database metaphor
14:00RUN IT: the 1/√dk. Without it, entropy 0.000
18:00Key moment: "One division. And the model goes from not training to training"
21:00The mask: why −infinity and not 0

V10 · Assembling the GPT (25 min)

V11 · Training it live (20 min)

Record the real 9-minute training run and speed it up. Let them see the loss come down and the text get better. Key moment: read the generated text out loud.

V12 · Looking inside (20 min)

Key moment: find the head (layer 3, head 3) that devotes 16.2% of its attention to the subject. "There is the circuit that decides whether it writes satisfecho or satisfecha."


BLOCK 4 · Making it actually work (3 videos · 60 min)

V13 · Why training runs break (22 min)

Key moment: the initialization table. With scale 0.02 and no residuals, the gradient at layer 1 is exactly 0.0. And the nuance almost nobody mentions: with a perfect init, a network without residuals does train. What residuals contribute is robustness, not magic.

V14 · Generating fast (20 min)

Key moment: greedy repeating the same sentence in a loop. Then the KV cache: 16.8× faster, the same logits (difference 2.5e-06).

V15 · Making it fit on your laptop (18 min)

Key moment: int4 per tensor destroys the model (+0.256). Int4 in groups of 64 holds up (+0.027). "The difference between working and not working is the group size. That is the K in Q4_K_M."


BLOCK 5 · From model to product (3 videos · 55 min)

V16 · From continuer to assistant (20 min)

Key moment: show the loss masking token by token. And then: training loss 0.0000, validation climbing to 7.62. "That is overfitting. And if I had only looked at the questions it had seen, I would have gone home delighted."

V17 · The complete journey of your message (20 min)

Diagram: figure viaje

Key moment: "The model has no memory. None. What you perceive as it remembering is the server resending it the entire conversation."

V18 · Tools: from 0% to 91% (15 min)

Key moment: the same network, the same operations. Doing the arithmetic in its head, 0%. Delegating to a calculator, 91%. "It has not got any smarter. It has stopped doing the thing it is bad at."


Resources per video

For each one, leave these downloadable:

  1. The exact command to run
  2. The matching course exercise
  3. The diagram in SVG
  4. 3 check questions with a collapsible answer

On recording

Terminal: large font (18pt+), dark background, wide window. The output of these scripts is designed for 78 columns: respect that or the tables break.

Pace: when you run something that takes more than 10 seconds, cut. Nobody wants to watch a progress bar.

What NOT to do: read the code line by line. Show the problem, run it, and explain only the part that matters.