Study the paper
Attention Is All You Need
Lessons, visuals, quizzes, flashcards, and resources—organized in teaching order.
30 activities
At a glance
Introduction to the Transformer ArchitectureIntroduction to the Transformer Architecture
LessonMotivation for the Transformer
Introduction to the Transformer ArchitectureRecurrent neural networks (RNNs) process sequences sequentially, computing a hidden state h t as a function of the previous hidden state h t-1 and the current input. This step-by-step alignment prevents parallelization within a single training example, leading to severe computational bottlenecks for long sequences.
FlashcardsIntroduction to the Transformer Architecture
Introduction to the Transformer Architecture2 cards for focused recall and explanation.
LessonScaled Dot-Product Attention
Scaled Dot-Product AttentionMathematical Formulation
LessonScaled Dot-Product Attention
Scaled Dot-Product AttentionThe Scaled Dot-Product Attention mechanism maps a set of query vectors, key vectors, and value vectors to an output. The output is computed as a weighted sum of the values, where the weight assigned to each value is computed by a compatibility function of the query with the corresponding key.
FlashcardsScaled Dot-Product Attention
Scaled Dot-Product Attention2 cards for focused recall and explanation.
VisualIllustrative teaching scenarios: attention scaling (not paper-reported)
Scaled Dot-Product AttentionCompare fixed illustrative teaching scenarios; these are not paper-reported results.
VisualIllustrative teaching scenarios: attention concentration (not paper-reported)
Scaled Dot-Product AttentionTrace fixed illustrative teaching scenarios; these are not paper-reported results.
VisualHow attention redistributes weight
Scaled Dot-Product AttentionIllustrative attention weights computed from a fixed teaching example; these are not paper-reported values.
VisualExplore attention score scaling
Scaled Dot-Product AttentionMove across fixed illustrative scenarios to see how score scaling changes concentration.
VisualScaled Dot-Product Attention: step by step
Scaled Dot-Product AttentionFollow the existing bounded walkthrough in its intended sequence.
LessonMulti-Head Attention Mechanics
Multi-Head Attention MechanicsMechanics of Multi-Head Attention
LessonMulti-Head Attention
Multi-Head Attention MechanicsThe Multi-Head Attention mechanism projects queries, keys, and values into multiple lower-dimensional subspaces, performs attention on each subspace in parallel, and then concatenates and projects the results back to the original dimension.
FlashcardsMulti-Head Attention Mechanics
Multi-Head Attention Mechanics2 cards for focused recall and explanation.
VisualMulti-Head Attention: step by step
Multi-Head Attention MechanicsFollow the existing bounded walkthrough in its intended sequence.
LessonSinusoidal Positional Encodings
Injecting Sequence Order via Positional EncodingsBecause the Transformer contains no recurrence and no convolution, it is entirely permutation-invariant. To make use of the order of the sequence, we must inject information about the relative or absolute position of the tokens. This is achieved by adding "positional encodings" of dimension d text model directly to the input embeddings.
FlashcardsInjecting Sequence Order via Positional Encodings
Injecting Sequence Order via Positional Encodings2 cards for focused recall and explanation.
LessonComputational Complexity of Layer Types
Comparing Self-Attention, Recurrent, and Convolutional LayersTo understand the computational advantages of self-attention, we compare its per-layer complexity, sequential operations, and maximum path length against recurrent and convolutional layers. Let n be the sequence length and d be the representation dimension.
LessonRestricted Self-Attention for Long Sequences
Comparing Self-Attention, Recurrent, and Convolutional LayersFor extremely long sequences, self-attention can be restricted to a local neighborhood of size r centered around each output position. This restricted self-attention reduces complexity per layer to O(r cdot n cdot d) while increasing the maximum path length to O(n/r) .
FlashcardsComparing Self-Attention, Recurrent, and Convolutional Layers
Comparing Self-Attention, Recurrent, and Convolutional Layers3 cards for focused recall and explanation.
LessonEmpirical Performance and Generalization
Empirical Evaluation and GeneralizationThe Transformer achieves state-of-the-art performance on translation tasks with significantly lower training costs. On the WMT 2014 English-to-German task, the big Transformer model achieves a BLEU score of 28.4, outperforming previous ensemble models while requiring only 2.3 cdot 10^ 19 FLOPs to train.
LessonTable 2: BLEU scores and training costs for translation tasks
Empirical Evaluation and GeneralizationThe Transformer model achieves state-of-the-art results on translation tasks. On the English-to-German (EN-DE) translation task, the Transformer (big) model achieves a BLEU score of 28.4, while the base model achieves 27.3. On the English-to-French (EN-FR) task, the Transformer (big) model achieves a BLEU score of 41.8, and the base model achieves 38.1.
LessonTable 4: F1 scores for English constituency parsing
Empirical Evaluation and GeneralizationThe Transformer generalizes well to English constituency parsing. When trained on WSJ only (discriminative setting), the 4-layer Transformer achieves an F1 score of 91.3. In the semi-supervised setting, the 4-layer Transformer achieves an F1 score of 92.7.
FlashcardsEmpirical Evaluation and Generalization
Empirical Evaluation and Generalization2 cards for focused recall and explanation.
VisualTable 4: F1 scores for English constituency parsing
Empirical Evaluation and GeneralizationExplore paper-reported results and reconciled deterministic comparisons.
VisualTable 4: F1 scores for English constituency parsing: WSJ 23 F1
Empirical Evaluation and GeneralizationCompare reconciled WSJ 23 F1 values reported by the paper.
QuizTest your understanding
Comprehensive Assessment12 questions grounded in this paper section.
VisualPaper concept map
Comprehensive AssessmentFollow how prerequisites and the paper’s main ideas connect in teaching order.
ResourceFurther learning
Comprehensive Assessment3 supplementary resources for this paper section.
ResourceResearch and implementation context
Comprehensive AssessmentExplore notable related work and public implementation context.