Transformer Architecture and Attention
- 59Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
- spaceFlip card
- KI knew it
- DI didn't know it
- ←Previous card
- →Next card
What limitation can a shallow CNN have when relating distant parts of an input?
Because its filters process local regions, a shallow CNN may have no output neuron whose receptive field includes both distant inputs. It cannot then make a decision based on their joint configuration.
Or swipe the card
59 cards
What limitation can a shallow CNN have when relating distant parts of an input?
Because its filters process local regions, a shallow CNN may have no output neuron whose receptive field includes both distant inputs. It cannot then make a decision based on their joint configuration.
How does a CNN’s receptive field grow as convolutional layers are stacked?
It expands gradually: each additional layer lets information travel farther through the network. With a length-three filter, for example, the receptive field expands by one position on each side at each layer.
Why can locality be a useful inductive bias, and when can it be limiting?
Many important relationships are local, so locality can simplify learning. It can be limiting when a task depends on relationships between distant parts of the input.
How does a fully connected layer differ from a CNN in how it combines input information?
A fully connected layer lets each output use information from every input immediately; a CNN combines information locally and builds wider context across layers.
What is the central global-processing idea behind attention?
Allow tokens to draw information from relevant parts of the input, including distant parts, rather than relying only on local connections.
How does attention differ from connecting every input to every output with a fully connected layer?
Attention can consider tokens globally while using input-dependent weights to focus on relevant information. A fully connected layer uses learned weights that do not change with the particular input.
How could attention help answer “How many animals are in this image?”
It could assign high weights to image patches containing animals and combine information from those patches to estimate the count.
How could attention help answer “What is the color of the impala?”
It could focus on patches depicting the impala and combine their color information.
In this lecture’s terminology, what is a token?
A token is a vector-valued unit of information that a model processes as one encapsulated chunk. In a transformer, it is typically a vector.
How does the lecture’s meaning of “token” differ from the common NLP meaning?
Here, a token is a vector representing a chunk of information. In NLP, “token” often means a discrete vocabulary unit, such as a word or subword.
How are tokens represented in the matrix notation used in the lecture?
Tokens are rows of a matrix T with n tokens and d features per token, so T has shape n×d.
How are image patches commonly converted into transformer tokens?
The image is divided into patches, each patch is flattened into a vector of pixel values, and a linear projection maps it to the desired token dimension.
Do standard image-transformer patches usually overlap?
Usually not: standard approaches commonly use non-overlapping patches, although overlapping patches are possible.
How can language be divided into tokens for transformer processing?
It can be divided into discrete vocabulary units, commonly subword units such as byte-pair tokens. The tokenizer converts these units into vectors for the model.
What is the general domain-specific step in applying a transformer?
Convert the input into tokens that represent meaningful chunks for the domain. The transformer then processes those tokens with a largely domain-general recipe.
What is a linear combination of tokens?
It is a weighted sum of token vectors. With token matrix T and token weights w, it can be written as wT.
Why is a weighted combination of whole tokens less expressive than an unrestricted linear transformation of all their neurons?
The same weight is applied across the dimensions of each token, so the operation has a constrained, low-rank form compared with assigning independent weights to every neuron.
What is a token-wise nonlinearity?
The same nonlinear function is applied independently to every token. In transformers, this function is typically an MLP.
How is a token-wise nonlinearity related to a convolution?
It is analogous to applying a shared 1×1 convolution across tokens: each token is transformed independently using the same function.
What two basic operations form the token-network motif described in the lecture?
A weighted combination of tokens followed by a token-wise nonlinear transformation; the motif can be repeated across layers.
How is a transformer related to a graph neural network?
Both update vector-valued units by aggregating information and applying update functions. A transformer can be viewed as a graph network over a fully connected graph, with attention determining the aggregation weights.
How does a graph neural network determine which units exchange information?
The graph’s connectivity, represented by its adjacency structure, determines which units can contribute to each aggregation.
What roles do query, key, and value play in attention?
A query represents what a token is looking for; a key represents what another token can match against; a value represents the information that token contributes if selected.
How are queries, keys, and values typically produced from token vectors?
Each is produced by a learned linear projection of the token vector, using separate projection matrices for queries, keys, and values.
How does query-key matching determine attention scores?
A query is compared with each key using a dot product. The resulting score indicates how relevant that key is to the query.
What does a query-key dot product represent intuitively?
It measures how well the key matches the query in the learned representation space.
How are raw attention scores converted into weights?
A softmax is applied to the scores, producing normalized weights that sum to 1.
What does an attention layer combine after calculating its attention weights?
It takes a weighted sum of the value vectors. The attention weights determine each value’s contribution.
What is the scaled dot-product self-attention equation?
For query matrix Q, key matrix K, and value matrix V, the output is softmax(dkQK⊤)V, where dk is the key/query dimension.
Why is the query-key product divided by the square root of the key dimension?
The scaling is part of the standard attention calculation and helps keep the scores at a suitable scale before softmax.
Which parameters are learned in a standard attention layer?
The projection matrices that map token vectors to queries, keys, and values are learned. Attention weights themselves are computed from the current input.
Why not simply learn an independent attention matrix for every input sequence?
An independent matrix for n tokens requires n2 parameters. Learning query, key, and value projections instead makes the learned parameters depend on feature dimensions rather than sequence length.
What is self-attention?
Self-attention is attention in which the queries, keys, and values are produced from the same input set of tokens, allowing tokens to exchange information with one another.
How can self-attention help a token refine its representation?
A token can attend to related tokens and aggregate their information, helping it update or disambiguate its own representation.
What is multi-head self-attention?
It runs multiple attention operations in parallel and combines their results. Different heads can learn to focus on different relationships or features.
What are the main operations in a transformer block described in the lecture?
Self-attention, a token-wise MLP, residual connections, and normalization (commonly LayerNorm).
What does LayerNorm do to a token’s activations?
It normalizes the elements of the token vector using its mean and variance, typically making them have zero mean and unit variance.
What is the purpose of residual connections in a transformer block?
They provide an identity path around the block’s processing, adding the input representation to the transformed representation.
Are transformer layers required to share their weights across depth?
No. Standard transformers typically use separate weights at different depths, though sharing is possible.
How does this weight-sharing convention compare with many graph neural networks?
Graph neural networks often share weights across depth, while standard transformers typically use different weights in each layer.
Why are transformer computations well suited to modern accelerators?
Much of the computation can be expressed as matrix multiplications, which map efficiently to GPU hardware.
What does it mean for a transformer to be permutation equivariant?
If the input tokens are reordered, the output tokens are reordered in the corresponding way: permuting the input permutes the output.
Why is a transformer without positional information permutation equivariant?
Its token-wise functions treat tokens identically and independently, while attention is based on token content rather than row order.
What is positional encoding used for in a transformer?
It supplies information about where a token came from, allowing the model to use position or order rather than treating the input as an unordered set.
How can positional information be added to image tokens?
A positional encoding representing each patch’s location can be combined with the patch token. One approach represents coordinates using sine and cosine functions at different frequencies.
What is the intuition behind Fourier-style positional encodings?
They represent a location using values of sinusoidal functions, providing a position description in a basis other than raw Cartesian coordinates.
How might positional information be represented for data on a sphere?
Using latitude and longitude, potentially represented through spherical harmonics or sinusoidal functions on the sphere.
What positional encoding can be used for graph nodes?
Eigenvectors of the graph Laplacian can provide positional information, including smooth and higher-frequency patterns over the graph.
How does positional encoding provide an inductive bias?
It tells the model what position means for a particular domain and can encode useful notions of locality or spatial and sequential structure.
What is an autoregressive language model trained to predict?
It predicts the next token from the preceding tokens in a sequence.
How does autoregressive generation produce a sequence?
The model predicts a next token, appends it to the sequence, and repeats the prediction process using the expanded sequence.
How is an autoregressive language model trained?
It uses observed text sequences as training data and learns to predict the next token from the preceding context.
Why does an autoregressive transformer use causal masking?
Causal masking prevents a position from using future tokens, so its prediction depends only on the permitted preceding context rather than the answer itself.
Which tokens may a position attend to under causal masking?
It may attend to itself and earlier tokens, but not to later tokens in the sequence.
How does causal masking affect permutation equivariance?
It makes token order matter, so the masked model is not permutation equivariant in the same way as an unmasked set-processing transformer.
How can a causally masked transformer efficiently train predictions at multiple sequence positions?
The mask ensures each position can use only its allowed context, so the model can produce and supervise predictions across the sequence in parallel.
What is cross-attention in image captioning?
It lets text-generation tokens attend to a separate set of image tokens, so generated words can use information from the image.
How does an image-captioning transformer combine image processing with text generation?
It first represents image patches as tokens, then generates text autoregressively. Text tokens can attend to previous generated words and to image representations through cross-attention.
What does GPT stand for, and what kind of model is it?
GPT stands for Generative Pre-trained Transformer. It is a transformer used autoregressively to predict subsequent tokens.

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