Transformers & Attention
All 9 cards in this deck
Tokens, attention, and the architecture under every modern LLM. Answer each question before you open it — then run the review above, which schedules every card with spaced repetition so it comes back right before you would forget it.
What does scaled dot-product attention compute?
softmax(QKᵀ/√d)·V — each query pulls a weighted blend of the value vectors, weighted by how much its query matches each key.
Why divide the attention scores by √d?
To keep the dot products from growing with dimension and pushing the softmax into tiny gradients — it stabilizes training.
What is multi-head attention?
Running attention several times in parallel with different learned projections, so the model attends to different relationships at once.
Why do Transformers need positional encodings?
Attention is order-agnostic — it sees a set, not a sequence — so position must be injected to model word order.
What does Layer Normalization do?
Re-centers and re-scales a vector to mean 0 / variance 1, then applies learned gamma/beta — keeping activations well-behaved so deep nets train.
Tokens vs characters — what does a model read?
Tokens (sub-word chunks from a tokenizer like BPE), not characters — which is why models miscount letters in a word.
What does the softmax at the output do?
Turns raw logits into a probability distribution over the next token that sums to 1.
What is the residual (skip) connection for?
It adds a sub-layer’s input to its output, giving gradients a shortcut so very deep stacks stay trainable.
Encoder-only vs decoder-only Transformers?
Encoder-only (BERT) sees the whole input at once for understanding; decoder-only (GPT) predicts left-to-right for generation.