AIAny

The Annotated Transformer

A line-by-line PyTorch reimplementation of the Transformer paper as a runnable notebook, where each part of the paper sits next to the code that implements it — turning a dense architecture into something you can read and run end to end.

Introduction

Reading the Transformer paper and actually understanding it are two different things — the gap is the implementation detail the paper compresses into a handful of equations. The Annotated Transformer closes that gap by interleaving the paper's own text with a complete, working PyTorch version, so the abstract math and the concrete tensor operations sit side by side. It is the resource many people credit for finally making attention click.

What Sets It Apart
  • Paper and code, line by line. Each part of the original paper appears next to the code that realizes it, so you see exactly how multi-head attention or positional encoding becomes tensors — no hand-waving between theory and implementation.
  • A runnable notebook, not a writeup. The whole document executes as a working implementation you can train and modify, which makes it a far faster way to learn than reading prose alone.
  • Maintained, not bit-rotted. The Harvard NLP group's 2022 rewrite modernizes the original so it stays usable with current PyTorch.
Great Fit / Look Elsewhere

Great fit if you have read or skimmed 'Attention Is All You Need' and want to internalize it by building it, or you simply learn best from code you can run. Look elsewhere if you want a high-level conceptual overview without implementation detail, or a production-grade Transformer library — this is a teaching implementation, optimized for clarity over performance.

Information

  • Websitenlp.seas.harvard.edu
  • OrganizationsHarvard University
  • AuthorsAlexander Rush
  • Published date2022/05/02

More Items

GitHub

Practical, full-stack tutorial for building Retrieval-Augmented Generation (RAG) systems—covers data preprocessing, vector embedding and indexing, hybrid and multimodal retrieval, generation integration, evaluation and production-ready engineering. Includes hands-on projects and examples for developers with Python experience.

GitHub

Provides end-to-end PyTorch scripts to download/prepare data, implement a transformer from scratch, train LLMs (13M→billion-scale) and generate text. Emphasizes educational clarity and single‑GPU experiments; useful for researchers or hobbyists, but large-scale training still requires substantial compute and engineering.

GitHub

Hands-on coding tutorial series for large language models with slides and runnable notebooks covering fine-tuning, prompting, RLHF, safety, steganography, watermarking, multimodal models, GUI agents, and deployment. Community-maintained, free course materials for students and researchers.