You will write a recurrent network's step and attention's steps by hand, hold each against PyTorch's own with `torch.allclose`, and read one row of a real model's attention.

About 40 minutes. You do it on your own computer. You need your own computer, with uv (free); Windows, Linux or a Mac with Apple silicon, since PyTorch no longer ships for Intel Macs; for the last step, about 3 GB of free memory and 1.2 GB of disk for Qwen3-0.6B-Base, which comes from the Hugging Face Hub with no account.

  1. A first runRun it
  2. The loopYour turn
  3. The seal's row, by handYour turn
  4. Every token at onceYour turn
  5. Two ways to get it wrongRun it
  6. The second headYour turn
  7. On your own: a real headOn your own
Terminal
curl -LsSf https://astral.sh/uv/install.sh | sh
cd learn-nlp-transformers/labs/nlp-lab-attention/starter
uv sync

See it on GitHub

When you have run it

After step 7, which token does " seal" give the biggest share to, in layer 7, head 16?

Run on macOS on an M1 Max, uv 0.11.15, Python 3.12, PyTorch 2.15.0, Transformers 5.25.0. Checked on .