Lab 2 of 3about 40 minutes
Attention, written by hand
It uses what you learned in Recurrent networks and their limit, Attention and Queries, keys, values and heads.
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.
- A first runRun it
- The loopYour turn
- The seal's row, by handYour turn
- Every token at onceYour turn
- Two ways to get it wrongRun it
- The second headYour turn
- On your own: a real headOn your own
curl -LsSf https://astral.sh/uv/install.sh | sh
cd learn-nlp-transformers/labs/nlp-lab-attention/starter
uv syncWhen 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 .
