Multi-head attention and Transformer block skeleton

Overview: what you’re building

You’ll build a small but real TransformerBlock in PyTorch:

  • It will take in a batch of token embeddings.
  • Run them through multi-head self-attention.
  • Then through a feedforward MLP.
  • Wrap each sublayer with residual connections and layer normalization.
  • End with a tiny script that runs this block on random data to prove it works.

We’ll walk through each core idea you need, then put it all together.

1 / 6