Attention and Transformers
- 73Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
- spaceFlip card
- KI knew it
- DI didn't know it
- ←Previous card
- →Next card
What kinds of sequence-processing tasks become possible with recurrent neural networks (RNNs) beyond one-to-one problems?
Tasks such as one-to-many image captioning, many-to-one sequence classification, and sequence-to-sequence translation.
Or swipe the card
73 cards
What kinds of sequence-processing tasks become possible with recurrent neural networks (RNNs) beyond one-to-one problems?
Tasks such as one-to-many image captioning, many-to-one sequence classification, and sequence-to-sequence translation.
What is a one-to-many problem in neural networks?
A problem with one input and a sequence of outputs, such as generating a textual image caption from one image.
What is a many-to-one problem in neural networks?
A problem with a sequence of inputs and one output, such as classifying a sequence of video frames.
What is a sequence-to-sequence problem?
A problem in which one sequence is mapped to another sequence, such as translating an English sentence into Italian.
Why are RNNs suitable for machine translation?
They can process a variable-length input sequence and generate a variable-length output sequence one element at a time.
What are the two main topics introduced in the lecture?
Attention, a neural-network primitive operating on sets of vectors, and transformers, architectures built around self-attention.
Why have transformers become important in deep learning?
They are widely used in large, state-of-the-art models for images, text, audio, generation, and classification.
How do RNN-based sequence-to-sequence models encode an input sequence?
An encoder RNN processes the input sequentially and uses its final hidden state as a summary of the entire input.
What is the role of the encoder in an RNN sequence-to-sequence model?
It processes the input sequence and summarizes its content into a representation used by the decoder.
What is the context vector in a basic RNN encoder-decoder model?
A fixed-length vector, often the encoder's final hidden state, intended to summarize the entire input sequence.
What inputs does the decoder RNN typically receive at each time step?
The previous output token, the previous decoder hidden state, and the context vector.
What is the role of the decoder in an RNN sequence-to-sequence model?
It generates the target sequence one token at a time using its previous state, previous output, and the encoded input.
What is the communication bottleneck in a basic RNN encoder-decoder?
The entire input sequence must communicate with the decoder through one fixed-length context vector.
Why does the fixed-length context vector become problematic for long sequences?
It becomes increasingly difficult to compress all information from a paragraph, book, or corpus into one fixed-size vector.
What central problem motivated the development of attention?
The need to let the decoder access relevant parts of the entire input sequence instead of relying on one fixed-length summary.
How can an RNN decoder avoid the fixed-vector bottleneck?
At every decoding step, it can look back at all encoder hidden states and compute a step-specific context vector.
What is an alignment score in an attention mechanism?
A scalar measuring how well a decoder state matches a particular encoder hidden state.
How can alignment scores be computed in the original RNN attention mechanism?
A learned function can concatenate a decoder hidden state with an encoder hidden state and transform them into a scalar.
Why is softmax applied to alignment scores?
It converts arbitrary scores into nonnegative attention weights that sum to one.
What do attention weights represent?
The relative importance assigned to each input vector when producing the current output.
How is an attention context vector computed?
It is a weighted linear combination of the encoder hidden states, using the attention weights.
Why does attention compute a new context vector at every decoder time step?
Different output tokens require information from different parts of the input sequence.
Does attention require explicit supervision of input-output word alignments?
No. The attention mechanism can learn alignments end to end through gradient descent on the output prediction loss.
What loss is typically used to train an attention-based sequence-to-sequence model?
Cross-entropy loss over the predicted output tokens.
How can attention weights help interpret a neural network?
Visualizing them shows which input positions the model emphasizes while producing each output.
What does a diagonal pattern in a translation attention matrix often indicate?
An approximately one-to-one correspondence between input and output words in the same order.
What can non-diagonal patterns in an attention matrix indicate?
Different word orders or more complex correspondences between the input and output sequences.
What are the data vectors in the generalized attention operator?
Vectors containing information to be summarized, such as encoder hidden states.
What is a query vector in attention?
A vector representing the information needed to produce a particular output.
What does the general attention operator compute?
For each query, it compares the query with data vectors, forms attention weights, and produces a weighted summary vector.
What similarity function is commonly used in scaled dot-product attention?
The dot product divided by the square root of the key/query dimension.
Why is the dot product scaled by the square root of the vector dimension?
To reduce excessively large scores and help prevent vanishing gradients through the softmax.
How can attention process many query vectors in parallel?
By representing queries and data vectors as matrices and computing all pairwise similarities with matrix multiplication.
What does the attention score matrix represent?
The pairwise similarity between every query vector and every data vector.
How are output vectors computed from the attention score matrix?
A softmax-normalized score distribution is used to form a weighted combination of the data vectors.
Why are keys and values introduced in attention?
They separate the representation used for matching queries from the representation used to produce outputs.
What is the role of a key vector?
A learned projection of a data vector that is compared with queries to compute attention scores.
What is the role of a value vector?
A learned projection of a data vector that is combined according to the attention weights to produce the output.
How are keys and values obtained from data vectors?
Separate learned linear projections transform each data vector into a key and a value.
What is the search-engine analogy for queries, keys, and values?
The query is what is being sought, the key is what is matched against it, and the value is the information returned.
What is cross-attention?
An attention layer in which queries and data vectors come from two potentially different sets of inputs.
What is self-attention?
An attention layer in which one set of input vectors is projected into queries, keys, and values.
How does self-attention transform an input sequence?
It projects each input vector into a query, key, and value, computes query-key similarities, and combines the values using the resulting weights.
When is cross-attention preferable to self-attention?
When a task naturally involves two distinct sets of objects, such as an image and a generated caption or an input and output sentence.
When is self-attention preferable to cross-attention?
When there is one set of objects to process internally, such as the patches of an image in image classification.
What does permutation equivariance mean for self-attention?
If the input vectors are permuted, the output vectors are permuted in the same way.
Why is self-attention considered an operator on sets rather than sequences?
Because its outputs are unchanged in content by reordering the inputs; only the output order changes correspondingly.
What is a positional embedding?
Additional information appended or incorporated into each input vector to indicate its position in a sequence.
What is masked self-attention?
Self-attention in which selected query-key interactions are blocked by replacing their scores with negative infinity before softmax.
Why is masked self-attention used for autoregressive language modeling?
To prevent each position from attending to future tokens and thereby cheating during prediction.
What is multi-headed self-attention?
Running multiple independent self-attention heads in parallel and combining their outputs with a learned projection.
Why use multiple attention heads?
They provide additional parameters and computation, allowing the model to learn multiple relationship patterns in parallel.
How can multi-headed self-attention be computed efficiently?
Using batched matrix multiplications rather than a sequential loop over attention heads.
What are the main matrix-multiplication stages in a self-attention operator?
Projection to queries, keys, and values; query-key similarity computation; value weighting; and output projection.
How do RNNs, convolutions, and self-attention differ in their input structure?
RNNs process ordered one-dimensional sequences, convolutions process multidimensional grids locally, and self-attention processes sets of vectors with global interactions.
Why are RNNs difficult to parallelize across a sequence?
Each hidden state depends on the previous hidden state, creating an inherently sequential computation.
What is a major advantage of convolution over RNNs?
Different kernel positions can be computed in parallel.
What is a limitation of convolution for long-range interactions?
Building a large receptive field requires large kernels or many stacked convolutional layers.
What is a major advantage of self-attention over convolution for global interactions?
Every input vector can interact directly with every other vector in a single layer.
What is the main computational disadvantage of standard self-attention?
Its attention matrix requires quadratic computation and memory with respect to sequence length.
Why is parallelizability important for large neural networks?
It allows computation to be distributed across many processors instead of relying on one increasingly fast processor.
What is the core computational primitive of a transformer?
Self-attention.
What is the purpose of a residual connection in a transformer block?
It adds a layer's input to its output to improve optimization and information flow.
Why is layer normalization used in transformer blocks?
It helps stabilize training by normalizing activations within the architecture.
What is the role of the MLP or FFN sublayer in a transformer?
It performs learned computation independently on each vector.
How do self-attention and the MLP complement each other in a transformer?
Self-attention lets vectors communicate with one another, while the MLP transforms each vector independently.
What is a transformer block?
A module containing self-attention and an MLP, typically combined with residual connections and layer normalization.
How is a transformer architecture constructed?
By stacking a sequence of transformer blocks.
How can transformers be applied to images?
An image is divided into patches, each patch is projected into a vector, and the vectors are processed by a transformer.
How can a transformer produce an image-classification prediction?
The output vectors corresponding to image patches are pooled and passed to a linear classifier.
How can transformers be used for language modeling?
They process token vectors with self-attention, using masking when necessary to prevent access to future tokens.
Why are transformers highly scalable?
Their main operations are matrix multiplications that can be parallelized and efficiently distributed across hardware.
What broad kinds of data can transformer architectures process?
They can process language, images, audio, and other data represented as vectors.

Ask anything
We've read this whole study set, so questions about it get the best answers.