🌍 Deep Learning · subject
Deep Learning Transformers and Attention Syllabus
Every chapter and topic of Transformers and Attention examined in Deep Learning — 5 chapters, 20 topics, plus 58 flashcards written against it.
Transformers and Attention syllabus — full chapter and topic list
Expand any chapter to see its topics and sub-topics. This is the whole examinable outline for Transformers and Attention in Deep Learning, not a summary of it.
-
The Transformer Architecture
4 topics- Self-Attention
- Multi-Head Attention
- Positional Encoding
- Encoder and Decoder Stacks
-
Pretrained Language Models
4 topics- BERT and Masked Language Modeling
- GPT and Autoregressive Models
- T5 and Encoder-Decoder Models
- Tokenizers (BPE, WordPiece, SentencePiece)
-
Large Language Models
5 topics- Scaling Laws and Emergent Abilities
- In-Context Learning and Prompting
- Fine-Tuning and Alignment
- Parameter-Efficient Fine-Tuning
- Retrieval-Augmented Generation
-
Vision and Multimodal Transformers
3 topics- Vision Transformers (ViT)
- CLIP and Contrastive Pretraining
- Multimodal Architectures
-
Efficient Attention
4 topics- FlashAttention
- Sparse and Linear Attention
- KV Caching
- Mixture of Experts
Transformers and Attention flashcards for Deep Learning
20 of 58 cards from the Transformers and Attention deck — real questions with worked answers.
What is self-attention, and what three vectors are computed for each input token?
Self-attention lets each token attend to all tokens in the sequence to build context-aware representations. For each token it computes a Query ($Q$), Key ($K$), and Value ($V$) vector by multiplying the input embedding with learned weight matrices $W_Q$, $W_K$, $W_V$.
Write the scaled dot-product attention formula.
$$\text{Attention}(Q,K,V) = \text{softmax}\!\left(\frac{QK^{T}}{\sqrt{d_k}}\right)V$$ where $d_k$ is the dimension of the key vectors.
Why is the dot product scaled by $\frac{1}{\sqrt{d_k}}$ in attention?
For large $d_k$, the dot products grow large in magnitude, pushing the softmax into regions with extremely small gradients. Dividing by $\sqrt{d_k}$ keeps the variance around 1, stabilizing gradients and training.
What is the time and memory complexity of standard self-attention with respect to sequence length $n$?
$O(n^{2}\,d)$ time and $O(n^{2})$ memory, because every token attends to every other token, producing an $n \times n$ attention matrix.
What is multi-head attention and why is it used?
Multi-head attention runs $h$ separate attention operations (heads) in parallel on different learned linear projections of $Q$, $K$, $V$, then concatenates and projects the results. It lets the model jointly attend to information from different representation subspaces and positions.
Give the formula for multi-head attention.
$$\text{MultiHead}(Q,K,V) = \text{Concat}(\text{head}_1,\dots,\text{head}_h)W^{O}$$ where $\text{head}_i = \text{Attention}(QW_i^{Q}, KW_i^{K}, VW_i^{V})$.
In the original Transformer, with model dimension $d_{model}=512$ and $h=8$ heads, what is the dimension per head?
Each head uses $d_k = d_v = \frac{d_{model}}{h} = \frac{512}{8} = 64$. This keeps total computation similar to single-head attention at full dimensionality.
Why do Transformers need positional encoding?
Self-attention is permutation-invariant and has no inherent notion of token order. Positional encodings inject information about the absolute or relative position of tokens so the model can use sequence order.
Write the sinusoidal positional encoding formulas from the original Transformer.
$$PE_{(pos,2i)} = \sin\!\left(\frac{pos}{10000^{2i/d_{model}}}\right), \quad PE_{(pos,2i+1)} = \cos\!\left(\frac{pos}{10000^{2i/d_{model}}}\right)$$ where $pos$ is the position and $i$ is the dimension index.
Contrast absolute, learned, and relative (e.g., RoPE) positional encodings.
Absolute (sinusoidal) uses fixed functions of position; learned encodings train a position embedding table; relative encodings (e.g., RoPE, ALiBi) encode the distance between tokens rather than absolute positions, generalizing better to longer sequences.
What are the two main sublayers in each Transformer encoder block, and how are they wrapped?
Each encoder block has (1) a multi-head self-attention sublayer and (2) a position-wise feed-forward network. Each sublayer is wrapped with a residual (skip) connection followed by layer normalization: $\text{LayerNorm}(x + \text{Sublayer}(x))$.
How does a Transformer decoder block differ from an encoder block?
A decoder block has three sublayers: (1) masked multi-head self-attention (causal masking prevents attending to future tokens), (2) cross-attention over the encoder outputs, and (3) a feed-forward network, each with residual connections and layer norm.
What is the position-wise feed-forward network in a Transformer, and its typical hidden size?
It is applied identically to each position: $$\text{FFN}(x) = \max(0, xW_1 + b_1)W_2 + b_2$$ Typically the inner dimension is $4\times$ the model dimension (e.g., $2048$ for $d_{model}=512$).
What is causal (autoregressive) masking in decoder self-attention?
A mask sets the attention scores for all future positions to $-\infty$ before the softmax, so position $i$ can only attend to positions $\leq i$. This preserves the autoregressive property during training and generation.
Compare Pre-LN and Post-LN Transformer architectures.
Post-LN (original) applies LayerNorm after the residual addition; it can be unstable and needs warmup. Pre-LN applies LayerNorm inside the residual branch before the sublayer, giving more stable gradients and easier training of deep models, at a slight quality cost.
What is BERT and what is its architectural type?
BERT (Bidirectional Encoder Representations from Transformers) is an encoder-only Transformer that produces bidirectional contextual representations. It is pretrained then fine-tuned for downstream tasks like classification and question answering.
Describe the Masked Language Modeling (MLM) objective used to pretrain BERT.
Randomly mask ~15% of input tokens and train the model to predict the original tokens from bidirectional context. Of the chosen tokens, 80% are replaced with [MASK], 10% with a random token, and 10% kept unchanged.
What was BERT's second pretraining objective, and what did later work find about it?
Next Sentence Prediction (NSP): predict whether sentence B follows sentence A. Later work (e.g., RoBERTa) found NSP largely unhelpful and removed it, training only with MLM on longer sequences.
What special tokens does BERT use and what are their roles?
[CLS] is prepended and its final hidden state is used for classification/pooling; [SEP] separates sentence segments and marks the end; [MASK] marks masked tokens; segment embeddings distinguish sentence A from B.
What is GPT and what pretraining objective does it use?
GPT (Generative Pretrained Transformer) is a decoder-only autoregressive model trained with causal language modeling: predict the next token given all previous tokens, maximizing $$\sum_{t} \log P(x_t \mid x_{<t}).$$
Planning Transformers and Attention for Deep Learning
Transformers and Attention is about 19% of the Deep Learning syllabus by topic count — 20 of 103 topics, spread over 5 chapters. At roughly 45 minutes per topic plus 12 minutes per sub-topic, a first pass runs to about 15 hours.
The heaviest chapters are Large Language Models (5 topics), The Transformer Architecture (4 topics), Pretrained Language Models (4 topics) . Front-load those while your energy is high; the short chapters are better revision filler later.
Work top-down: read the chapter, then tick topics off individually rather than marking the whole chapter done. Sub-topics are where silent gaps hide.
Transformers and Attention (Deep Learning) FAQ
What is in the Deep Learning Transformers and Attention syllabus?
Transformers and Attention is split into 5 chapters — The Transformer Architecture, Pretrained Language Models, Large Language Models, Vision and Multimodal Transformers and Efficient Attention, containing 20 topics and 0 sub-topics in total.
How many chapters are there in Transformers and Attention for Deep Learning?
5 chapters. Transformers and Attention accounts for about 19% of the topics in the whole Deep Learning syllabus (20 of 103).
How long should I spend on Transformers and Attention for Deep Learning?
Budget around 15 hours for a first pass through Transformers and Attention — about 45 minutes per topic plus 12 minutes per sub-topic across its 20 topics. Add revision cycles on top.
Are there flashcards for Deep Learning Transformers and Attention?
Yes — a 58-card Transformers and Attention deck. Sample cards are printed on this page, and the full deck is free in the Examius app with spaced repetition scheduling.