ARENA 1.1, Transformers from scratch

· arena

AI disclosure: I used ChatGPT to extract takeaways from my original notes. Substantial clarifications and additions appear in labeled blockquotes.

I already felt comfortable with the math of transformers, but I wanted one coding exercise where I implemented a model myself. I was mostly just confused about some of the tensor dimensions and how they interact. This exercise was useful for clearing that up, and for starting to connect the implementation to interpretability.

Key takeaways and insights

Open questions and things to revisit

References


  1. Belrose et al., Eliciting Latent Predictions from Transformers with the Tuned Lens. ↩︎

  2. Geva et al., Transformer Feed-Forward Layers Are Key-Value Memories. ↩︎

  3. PyTorch LayerNorm documentation. ↩︎

  4. OpenAI’s GPT-2 implementation, which uses the token embedding table again for the final output projection. ↩︎

  5. Holtzman et al., The Curious Case of Neural Text Degeneration. ↩︎

  6. Hugging Face’s guide to generation methods. The beam-search counterexample above corrects the guide’s overly strong claim that beam search always finds a higher-probability output than greedy search. ↩︎

  7. Carlini et al., Extracting Training Data from Large Language Models. ↩︎