11/09/26: Lect-11
Overview
Joseph Zambreno connects recurrent neural network encoder-decoder models to Bahdanau attention and the Transformer, showing how attention addresses the information bottleneck created when an RNN compresses a long input into one final hidden state. He explains encoder and decoder roles, teacher forcing, query-key-value attention, additive versus dot-product scoring, and how the 2017 paper Attention Is All You Need removed recurrence to enable more parallel computation.
Key takeaways
- A basic RNN encoder-decoder passes only its final hidden state to the decoder, creating an information bottleneck that makes earlier input tokens increasingly difficult to recover.
- Bahdanau attention addresses that bottleneck by letting each decoder step score and combine all encoder hidden states rather than relying only on the final encoder state.
- In additive attention, a decoder hidden state serves as the query, encoder states serve as keys and values, and softmax-normalized scores determine the weighted context passed to the decoder.
- Teacher forcing trains a decoder with the correct preceding target token, reducing cascading prediction errors during training even though generation must use the model’s own prior outputs.
- Attention matrices make token alignments visible: sequence reversal produces an anti-diagonal pattern, while translation commonly produces approximate diagonal patterns with many-to-one alignments.
- The 2017 Transformer insight was that attention could carry sequence relationships without recurrent connections, enabling more parallel computation and establishing the foundation for later large language models.
Chapters
- Joseph Zambreno approved all mini-project proposals, but recommended that some teams refine datasets, model choices, or evaluation rubrics and resubmit by the end of the week.
- A random train-test split of adjacent video-game frames can leak near-duplicates, such as training on frames 1 through 50 and testing on frame 51.
- Teams should use lab time with teaching assistants and plan for project work outside the scheduled three-hour sessions.
- RoBERTa represents an encoder-only model trained with masked tokens to learn sequence representations; GPT-2 is a decoder-only model that predicts continuations.
- Encoder-decoder models combine input representation with output generation, clarifying the lineage from earlier sequence models to Transformers.
- The lecture builds on softmax, backpropagation, optimization, normalization, and generalization, while noting that smaller models can offer better cost, memory, and power tradeoffs than large language models.
- In “The chip overheated because it…,” resolving “it” means identifying which earlier token matters for predicting a continuation.
- The Winograd-style example “The trophy didn’t fit in my suitcase because it was too small” requires world knowledge to resolve “it” to suitcase, not just grammatical rules.
- Attention formalizes the question of where a model should look in the preceding sequence when determining the next token.
- RNN tasks include sequence-to-one classification, such as fault detection from sensor values, one-to-sequence image captioning, and sequence-to-sequence translation.
- At each timestep, an RNN combines the current input token with the prior hidden state to compute an updated hidden state.
- A basic RNN exposes only its final hidden state as the sequence representation, even though intermediate states are retained for backpropagation through time.
- A sequence-to-sequence translation model connects an encoder RNN to a decoder RNN, passing the encoder’s final hidden state as the decoder’s initial context.
- Source and target sequences can have variable lengths, with special end-of-sequence and beginning-of-sequence tokens marking boundaries.
- For an input of T tokens and hidden size 32, the encoder computes T times 32 hidden values but passes only the final 32-value state to the decoder.
- During training, teacher forcing shifts the known target sequence by one token and feeds those correct prior tokens to the decoder.
- Using the ground-truth previous token prevents an early prediction error from cascading through every later decoder step.
- The Hands-On Machine Learning diagram also shows token embeddings, decoder softmax predictions, and encoder outputs that are computed but not used by the basic encoder-decoder connection.
- The basic encoder-decoder design compresses the entire source sentence into one final hidden state, limiting how much earlier sequence information reaches the decoder.
- An experiment regresses random input digits from the final hidden state: the latest token is easiest to recover, while accuracy drops for tokens farther back.
- Increasing hidden size improves recovery, but longer sequences still make the single-context-vector bottleneck a problem for translation.
- Bahdanau, Cho, and Bengio’s attention approach keeps the encoder’s intermediate hidden states instead of discarding them after computing the final state.
- For each decoder step, the decoder hidden state acts as the query, while encoder hidden states provide the keys and values in the original formulation.
- The mechanism scores how relevant each encoder position is to the decoder’s current output, then uses those scores to assemble a context from the input sequence.
- Additive, or concatenative, attention transforms the decoder query and each encoder state, combines them with a tanh network, and projects the result to a scalar relevance score.
- A softmax converts the raw scores into attention weights that sum to one across the encoder positions.
- The decoder receives a weighted sum of encoder hidden states, allowing a token such as “it” to emphasize “chip” when resolving “The chip overheated because it…”
- In the alternative textbook diagram, encoder states are labeled as outputs such as Y-hat values, while the decoder hidden state and encoder states enter a dense alignment model.
- An attention weight such as alpha at decoder position 3 and encoder position 2 measures how much that input position contributes to the fourth generated token.
- For translating “I like soccer” into Spanish, a high weight on “soccer” while generating “fútbol” illustrates learned cross-language alignment.
- Attention weights form a two-dimensional matrix: each output token has a weight for every input token.
- A model trained to reverse 1, 2, 3, 4, 5 into 5, 4, 3, 2, 1 learns an anti-diagonal attention pattern.
- Translation heatmaps tend to show roughly diagonal alignments, with multiple input words sometimes contributing to one output word, as in French “la destruction.”
- Einstein summation in NumPy and PyTorch can express batched attention-value multiplication, mapping batch-by-query-by-key weights and batch-by-key-by-value vectors to batch-by-query-by-value outputs.
- Dot-product, or multiplicative, attention scores query-key compatibility directly instead of using the additive attention network.
- The simpler computation avoids additive attention’s learned projection matrices and feed-forward scoring network, and maps naturally to matrix multiplication.
- Dot-product scoring became widely used, although practical variants can still transform or rescale queries and keys before taking the product.
- Bahdanau attention improves an RNN encoder-decoder but retains sequential computation across the source sequence.
- Vaswani and coauthors’ 2017 paper found that attention carried much of the useful relationship between input and output tokens, motivating removal of recurrence.
- Transformers add self-attention, so tokens within an encoder or decoder sequence can attend to one another, and process sequence positions more in parallel than RNNs.
- Attention Is All You Need established the Transformer architecture as an evolution of sequence-to-sequence models, setting up the next topic of scaling models into large language models.
Transcript excerpt
0:00 Let's go ahead and get started. It actually took a while to get to this point in the semester. Um, the goal is really to, you know, open the box of the models that you're learning and using already in lab six. Just a small administrative point you might or might not have seen my my Canvas Discord announcement message. Uh, you know, I looked at all the the mini project project proposals on Saturday. I liked what I saw. Certainly I didn't see a single project where I thought, well, no, you can't do that. That's not a good idea. So the overall thumbs up is provided for every project. You should be making progress and getting basically started on your projects. I I do want to just reoffer the fact that I'm giving effectively every team an opportunity to kind of think about their rubric a bit more. Now you've slept on it for a couple of days. Um, for some of them
0:47 they're just a little bit undercooked in terms of, you know, what data sets you're going to be using, what models that might make sense for you to use, and then scoring things appropriately in your proposal. I provided pretty high level, pretty brief feedback. I'll admit I didn't write paragraphs of paragraphs. Some of you I kind of put it in bold, please resubmit or you must, I don't know how I wrote it, please resubmit this. Others I suggested that you may want to. Just feel free to get that done by the end of this week. You should just be able to resubmit it in Canvas on the same assignment. And then for almost everybody the focus is on just making sure I have that table for the end of the semester evaluation.
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Joseph Zambreno.