Free self-study · No account needed · Progress stays in this browser. Back it up before clearing site data or changing devices.

← All weeks

Understanding Modern AI / Week 03

Transformers and Language Models

Build a causal decoder block and tokenizer study. Combine the token, attention, and decoder exercises into one runnable component.

Your lessons

  1. 01

    Turning text into model inputs

    60 minutes planned · 7 sections
    Start →
  2. 02

    Calculating causal attention

    60 minutes planned · 7 sections
    Start →
  3. 03

    Building a transformer block and generating tokens

    60 minutes planned · 7 sections
    Start →

// Put it into practice

A causal decoder block and tokenizer study

  1. Download week03.py from a lesson's practice section. Follow its setup instructions before running it.
  2. Lesson 1: Tokenize two short texts and trace the resulting tensor shapes.
  3. Lesson 2: Implement attention on a three-token example and deliberately break the causal mask.
  4. Lesson 3: Assemble a tiny decoder block, calculate a next-token loss, and generate a short sequence.
  5. Run the supplied assertions and record actual results; a simulated contract check does not certify real model quality.
Download week 3 Python lab ↓

Read the script’s setup instructions and run it on your own computer. The website does not execute code or verify your results.

// Independent work

W03-LAB

Week 3: A causal decoder block and tokenizer study

Combine the token, attention, and decoder exercises into one runnable component.

Extend the guided artifact rather than start a second project. A future-token perturbation cannot change earlier outputs; document shape and token-count checks.

What to produce

  • A causal decoder block and tokenizer study
  • Setup commands, data or generation procedure, versions, and recorded outputs
  • Acceptance results and a precise limitation

Check your work

  • A future-token perturbation cannot change earlier outputs; document shape and token-count checks.
  • Each claimed execution is supported by actual saved output.
  • Fixture results and real model results are identified separately.
  • Setup and reproduction use the taught tools without private credentials.
Self-assessment rubric
Technical correctness · 35 points
Implementation or analysis follows the relevant technical mechanism and handles the stated case.
Evaluation and evidence · 30 points
Reproducible tests, appropriate baseline, and accurate interpretation.
Engineering quality · 20 points
Clear structure, safe boundaries, and usable reproduction instructions.
Explanation and reflection · 15 points
Explains tradeoffs, limitations, and next experiment with evidence.

// Retrieve before you reread

Week 3 knowledge check

Try all 6 questions. Check your answers, review the explanations, and retry whenever you like. Answers are checked on this device.

1. A batch has three sequences of five tokens, with embedding width twelve. What shape follows lookup?
2. A model receives identifiers from another tokenizer with a different vocabulary order. What can fail?
3. An allowed attention row has four equal scores. What weights should normalization produce?
4. Changing token five changes the output at token two in a claimed causal decoder. What should be investigated?
5. For sequence [P,Q,R,S], what input and target pairing trains next-token prediction?
6. A decoder branch expands hidden width from 8 to 32 before a residual addition to width 8. What is needed?

Next: week 4 →