Positional Information: Absolute, Sinusoidal, and Rotary (RoPE)
Agent-Assisted Engineering Check
Prerequisites
Day 43 Attention and Day 47 Transformer Stacking.
Learning Objective
Explain why self-attention is permutation-equivariant without position encoding and compare learned vs sinusoidal vs Rotary Position Embeddings.
Instructions
Demonstrate that swapping token 1 and token 2 in self-attention produces correspondingly permuted outputs without position indicators. Define additive position embeddings x = tok_emb + pos_emb vs multiplicative RoPE rotation in complex space.
Practice & Prediction Log
1. Prove that vanilla dot-product attention has permutation equivariance.
2. In standard GPT-2, how are position vectors added to token vectors?
3. What key extrapolation advantage does RoPE provide over learned absolute embeddings?
Permutation matrix P satisfies (P Q)(P K)^T = P (Q K^T) P^T.
Permutation equivariance: without position information, attention weights permute identically with inputs, losing order. GPT-2 uses additive learned embeddings: x_t = C[tok_t] + W_pos[t]. RoPE encodes relative distance through 2D rotation of query and key pairs, generalizing more naturally across context lengths.
Articulates permutation equivariance and contrasts additive position vs RoPE.
Authoritative Source Resources & Provenance
Attention Is All You Need
Relevant Section / Range: Section 3.5 Positional Encoding
Verified Version & Date: arXiv:1706.03762v7 (Verified: 2026-10-30)
Foundational primary literature defining the Transformer architecture, multi-head attention, and scaled dot-product attention.
Matrix multiplication and basic neural network concepts from Days 22-24 and 34-36.
All mathematical formulas and structural definitions are self-contained in the lesson text.
Compared Candidate Sources & Selection Analysis (2)
High-level visual intuition, but Vaswani et al. provides the primary mathematical specifications needed for implementation.
Co-primary: PyTorch line-by-line implementation alongside the paper equations.
The Annotated Transformer
Relevant Section / Range: Positional Encoding (class PositionalEncoding)
Verified Version & Date: Updated PyTorch 2.0 edition (Verified: 2026-10-30)
Clear reference implementation of Transformer modules, residual connections, and layer normalization.
PyTorch tensor operations and attention theory.
All block assembly and normalization logic are provided in runnable local Python snippets.
Compared Candidate Sources & Selection Analysis (2)
Industrial scale with hundreds of model variations; Annotated Transformer is pedagogically focused on the core architecture.
Standard library implementation, but internal C++ bindings obscure the first-principles data flow.