Transformer Attention Mechanism
- 25Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is the primary goal of a transformer model as described?
What is the primary goal of a transformer model as described?
25 questions
- 1
What is the primary goal of a transformer model as described?
- A
Classify text sentiment
- B
Translate languages
- C
Generate random text
- D
Predict the next word in a sequence
Correct answer
DPredict the next word in a sequence
Explanation
The text explicitly states 'The goal of the model that you and I are studying is to take in a piece of text and predict what word comes next.'
- A
- 2
How are tokens defined in the context of this transformer explanation?
- A
Words or pieces of words
- B
Subword units like bytes
- C
Only whole words
- D
Characters
Correct answer
AWords or pieces of words
Explanation
The text says tokens are 'words or pieces of words' but simplifies to words for examples.
- A
- 3
What does an initial embedding represent?
- A
A context-independent vector for the word
- B
A vector enriched by surrounding context
- C
A dictionary definition of the word
- D
Only the position of the word
Correct answer
AA context-independent vector for the word
Explanation
Initial embeddings are described as 'effectively a lookup table with no reference to the context'.
- A
- 4
In the attention mechanism, what is the purpose of the query vector?
- A
To provide information to be added to other embeddings
- B
To 'ask' which other tokens are relevant to this token
- C
To normalize the attention scores
- D
To compute the final output embedding
Correct answer
BTo 'ask' which other tokens are relevant to this token
Explanation
The query is described as encoding a question like 'are there any adjectives sitting in front of me?'
- A
- 5
What is the dimension of the key/query space relative to the embedding dimension in GPT-3?
- A
Exactly the same
- B
Variable depending on the head
- C
Larger (e.g., 15000)
- D
Smaller (128 vs 12288)
Correct answer
DSmaller (128 vs 12288)
Explanation
The text specifies the query vector has 'much smaller dimension' (128) compared to the embedding dimension (12288).
- A
- 6
How is relevance between tokens measured in attention?
- A
By computing cosine similarity
- B
By using a small neural network
- C
By computing the dot product between key and query vectors
- D
By computing Euclidean distance
Correct answer
CBy computing the dot product between key and query vectors
Explanation
The text states 'you compute a dot product between each possible key-query pair'.
- A
- 7
After computing dot products, what operation normalizes the attention scores for each column?
- A
Normalization by dividing by sum
- B
ReLU
- C
Softmax
- D
Sigmoid
Correct answer
CSoftmax
Explanation
The text says 'We compute a softmax along each one of these columns to normalize the values.'
- A
- 8
Why is masking applied in self-attention during training?
- A
To ignore unimportant tokens
- B
To reduce computational cost
- C
To make the attention pattern symmetric
- D
To prevent later tokens from influencing earlier ones
Correct answer
DTo prevent later tokens from influencing earlier ones
Explanation
Masking ensures 'later tokens to influence earlier ones' are forced to zero to avoid giving away the answer.
- A
- 9
How is masking implemented before softmax?
- A
Multiplying by a mask matrix of zeros
- B
Removing those entries from the computation
- C
Setting those entries to negative infinity
- D
Setting those entries to zero
Correct answer
CSetting those entries to negative infinity
Explanation
The text says 'before applying softmax, you set all of those entries to be negative infinity.'
- A
- 10
What does the size of the attention pattern scale with?
- A
The number of attention heads
- B
The number of layers
- C
The embedding dimension
- D
The square of the context size
Correct answer
DThe square of the context size
Explanation
The text states 'its size is equal to the square of the context size.'
- A
- 11
In the value matrix factoring, what is the purpose of the 'value down' matrix?
- A
To produce the final value vector
- B
To combine all attention heads
- C
To map embeddings from the large space to a smaller space
- D
To compute the attention pattern
Correct answer
CTo map embeddings from the large space to a smaller space
Explanation
The value down matrix maps 'the large embedding vectors down to a much smaller space.'
- A
- 12
How are the proposed changes from multiple attention heads combined for a given position?
- A
Averaged
- B
Concatenated and linearly transformed
- C
Selected by a gating mechanism
- D
Summed together
Correct answer
DSummed together
Explanation
The text says 'you sum together all of those proposed changes, one for each head, and you add the result to the original embedding.'
- A
- 13
In practice, the value up matrices from all heads are often combined into a single matrix called:
- A
The projection matrix
- B
The combination matrix
- C
The output matrix
- D
The merged matrix
Correct answer
CThe output matrix
Explanation
The text mentions 'these value up matrices for each head appear stapled together in one giant matrix that we call the output matrix.'
- A
- 14
What is the approximate number of parameters in a single attention head of GPT-3 (including all four matrices)?
- A
1.5 million
- B
6.3 million
- C
150 million
- D
600 million
Correct answer
B6.3 million
Explanation
The text calculates 'about 6.3 million parameters for one attention head.'
- A
- 15
How many attention heads are used per block in GPT-3?
- A
96
- B
12
- C
12288
- D
128
Correct answer
A96
Explanation
The text states 'GPT-3 for example uses 96 attention heads inside each block.'
- A
- 16
How many layers (blocks) does GPT-3 have?
- A
96
- B
12
- C
175
- D
128
Correct answer
A96
Explanation
The text says 'GPT-3 includes 96 distinct layers.'
- A
- 17
What is the total number of parameters devoted to attention in GPT-3?
- A
175 billion
- B
600 million
- C
58 billion
- D
6.3 million
Correct answer
C58 billion
Explanation
The text computes 'just under 58 billion distinct parameters devoted to all of the attention heads.'
- A
- 18
What fraction of GPT-3's total parameters come from the attention mechanism?
- A
About one half
- B
Almost all
- C
About two thirds
- D
About one third
Correct answer
DAbout one third
Explanation
The text says 'it's only about a third of the 175 billion that are in the network in total.'
- A
- 19
What distinguishes cross-attention from self-attention?
- A
Keys and queries come from different data sets
- B
Only a single head is used
- C
No softmax is applied
- D
Masks are never used
Correct answer
AKeys and queries come from different data sets
Explanation
In cross-attention, 'the key and query maps act on different data sets.' Self-attention uses the same data.
- A
- 20
Why is the attention mechanism highly parallelizable?
- A
It does not require sequential processing of tokens
- B
It only involves simple arithmetic operations
- C
It uses matrix multiplications that can be computed simultaneously on GPUs
- D
Both of the above
Correct answer
DBoth of the above
Explanation
The text highlights 'extremely parallelizable, meaning that you can run a huge number of computations in a short time using GPUs.'
- A
- 21
In training, how do transformers use each input sequence efficiently?
- A
By using data augmentation on the input
- B
By using contrastive learning with negative samples
- C
By predicting the next token for every possible initial subsequence
- D
By masking random tokens and predicting them
Correct answer
CBy predicting the next token for every possible initial subsequence
Explanation
The text describes that you simultaneously predict every possible next token following each initial subsequence, making each training example act as many.
- A
- 22
What happens to the embedding of 'mole' in the initial step of a transformer?
- A
It is replaced by a contextual embedding immediately
- B
It is set to a zero vector
- C
It becomes context-dependent based on the surrounding words
- D
It is the same for all three phrases (e.g., 'American shrew mole', 'one mole of CO2')
Correct answer
DIt is the same for all three phrases (e.g., 'American shrew mole', 'one mole of CO2')
Explanation
The initial token embedding is a lookup table with no context, so 'the vector that's associated with mole would be the same in all of these cases.'
- A
- 23
After the attention block, what is the embedding of a word like 'creature' in 'a fluffy blue creature' expected to represent?
- A
The position of the word in the sentence
- B
The word plus context from relevant words like 'fluffy' and 'blue'
- C
A generic concept of an animal
- D
Only the word 'creature' without context
Correct answer
BThe word plus context from relevant words like 'fluffy' and 'blue'
Explanation
The attention block updates embeddings so that nouns 'ingest the meaning from their corresponding adjectives.'
- A
- 24
What is the dimension of the embedding space in GPT-3?
- A
128
- B
175
- C
12288
- D
96
Correct answer
C12288
Explanation
The text mentions the embedding dimension as 12,288 (e.g., '12,288 columns' for key/query matrices).
- A
- 25
What is the role of the value matrix in attention?
- A
To produce a vector that is added to other embeddings
- B
To normalize the attention scores
- C
To compute which tokens attend to which
- D
To compress the embeddings into a smaller space
Correct answer
ATo produce a vector that is added to other embeddings
Explanation
The value matrix produces a vector that 'you add to the embedding of the second word.'
- A

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