Week 7: Sequence Models & Attention
Discussion Topics — Use these prompts for class discussion, online forums, or personal reflection.
Analysis
1. The Attention Revolution: Why Did Self-Attention Replace Recurrence?
Recurrent neural networks (RNNs) and LSTMs were the dominant approach to sequence modeling for many years before the Transformer displaced them. The shift was not merely about accuracy — it was driven by fundamental architectural trade-offs around parallelism, long-range dependency capture, and gradient flow. Understanding why attention succeeded where recurrence struggled illuminates core principles of modern deep learning design.
- What specific failure modes of RNNs (vanishing gradients, bottleneck hidden states) does the self-attention mechanism directly address, and how?
- Self-attention has O(n²) complexity with respect to sequence length, while RNNs are O(n). In what scenarios might RNNs still be preferable despite Transformers' other advantages?
- If you were designing a new architecture for very long sequences (e.g., entire books or genomic sequences), what modifications to standard self-attention would you consider and why?
Try: Draw a side-by-side diagram of an RNN and a Transformer on the board, then ask students to annotate each node with its computational dependencies. This makes the parallelism gap concrete and visceral.
Evaluation
2. Interpreting Attention: What Does an Attention Head Actually Learn?
Researchers have visualized attention weights in trained Transformer models and observed that individual heads appear to specialize — some seem to track syntactic dependencies like subject-verb agreement, others focus on positional relationships, and others on semantic similarity. However, the field debates whether attention weights constitute a reliable explanation of model behavior or whether this interpretability is largely illusory.
- What is the difference between position attention and content attention, and why does this distinction matter for understanding what a model has learned?
- Attention weights show which tokens a given position attends to, but not how the value vectors at those positions contribute to the output. Does this limit the interpretability of attention? Explain your reasoning.
- If you found that pruning 60% of attention heads had no measurable effect on a model's performance, what would that imply about head specialization and redundancy?
Try: Show the class BertViz or another attention visualization tool applied to a sentence with a polysemous word. Ask small groups to form hypotheses about what each head is doing, then compare explanations.
Application
3. Static vs. Contextual Embeddings: When Does Context Actually Matter?
The move from static embeddings (Word2Vec, GloVe) to contextual embeddings (ELMo, BERT) was a defining shift in NLP. Contextual embeddings represent the same word token differently depending on its surrounding context, enabling models to handle polysemy, idioms, and pragmatic meaning. Yet static embeddings remain in use in resource-constrained settings and some retrieval systems. The trade-offs between the two approaches are worth examining carefully.
- Give two concrete examples of NLP tasks where contextual embeddings would significantly outperform static embeddings, and explain the mechanism behind the improvement.
- Static embeddings produce a fixed lookup table that can be precomputed once. What deployment constraints (latency, compute, storage) might make static embeddings the right engineering choice even when contextual embeddings are available?
- BERT generates different embeddings for the same word in different sentences. Could two sentences that are semantically opposite (e.g., "great" used sarcastically vs. sincerely) still produce similar embeddings? What does this imply about the limits of contextual representations?
Try: Poll the class on a deployment scenario (e.g., a mobile spell-checker with 50 ms latency budget) and have them vote for static vs. contextual. Use the split results to open a debate about where the threshold lies.
Analysis
4. Positional Encoding Design Choices and Their Consequences
The original Transformer used fixed sinusoidal positional encodings, while many subsequent models (e.g., BERT, GPT) switched to learned positional embeddings. More recent architectures (e.g., RoPE, ALiBi) use relative positional encodings that encode the distance between tokens rather than their absolute positions. Each design choice encodes different inductive biases about how position should influence attention.
- Sinusoidal encodings use alternating sine and cosine functions at different frequencies. Why might using multiple frequencies help the model learn both local and long-range positional relationships?
- A model trained with absolute positional encodings on sequences up to length 512 is asked to process a sequence of length 1024 at test time. What problem would arise, and how do relative positional encoding schemes address it?
- In tasks like sentiment classification of short sentences, does the precise encoding of word position matter as much as in machine translation? Justify your answer and consider what this implies for architecture choice.
Try: Have students sketch sine waves at three different frequencies on graph paper, then discuss how superimposing them creates unique patterns for each position — connecting the math to the intuition before returning to the code.
Synthesis/Creation
5. Multi-Head Attention: Hyperparameter Choices and Their Effects
The number of attention heads h and the per-head dimension d_k are critical hyperparameters in the Transformer. The original paper used h = 8 heads with d_k = 64 in a model of dimension d_model = 512. Large language models scale these dramatically — GPT-3 uses 96 heads with d_model = 12288. These choices govern the balance between model expressiveness, computational cost, and the diversity of representations each head can capture.
- If you double the number of attention heads while keeping d_model fixed, each head operates in a lower-dimensional subspace. What is the practical effect on what each head can learn, and is there a point of diminishing returns?
- Multi-head attention outputs are concatenated and then projected by a weight matrix W_O. What function does this output projection serve, and what would happen if it were removed?
- Some research suggests that not all heads learn distinct patterns — many are redundant and can be pruned without hurting performance. If you were designing a production system constrained by latency, how would you decide how many heads to keep?
Try: Give small groups a fixed parameter budget and ask them to design a Transformer (setting d_model, h, layers, FFN size). Compare designs and debate the trade-offs in a whole-class share-out.
Discussion Facilitation Tips
- Ground abstract attention mechanics by starting with a concrete example sentence. Ask students to manually compute which words they would attend to in order to understand an ambiguous word — this builds intuition before the math.
- The RNN vs. Transformer comparison is best handled as a structured debate. Assign half the class to defend RNNs for a given deployment scenario (e.g., low-resource edge inference) and the other half to argue for Transformers — then flip the scenario.
- Attention interpretability is an active research controversy. Encourage students to look up the "Attention is not Explanation" and "Attention is not not Explanation" papers and come prepared to take a side, which creates productive conflict in discussion.
- When discussing positional encoding choices, connect them to real model releases students may have heard of (BERT uses learned embeddings, RoPE is used in LLaMA). Naming specific systems makes the design space feel real rather than theoretical.