Transformer Neural Networks Explained
- 29Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is the primary purpose of word embedding in a Transformer neural network?
What is the primary purpose of word embedding in a Transformer neural network?
29 questions
- 1
What is the primary purpose of word embedding in a Transformer neural network?
- A
To calculate similarity between words
- B
To convert words into numerical vectors
- C
To determine word order in a sentence
- D
To generate output tokens
Correct answer
BTo convert words into numerical vectors
Explanation
Word embedding converts each word (or token) into a vector of numbers that can be processed by the neural network.
- A
- 2
In the simple word embedding network described, what happens when an input token's value is 0?
- A
It produces a large output
- B
It multiplies weights by 1
- C
It is ignored entirely
- D
It sends zeros to the activation functions
Correct answer
DIt sends zeros to the activation functions
Explanation
When the input value is 0, all products with weights become 0, so only zeros are passed to the activation functions.
- A
- 3
What type of activation function is used in the word embedding example?
- A
Sigmoid function
- B
ReLU function
- C
Tanh function
- D
Identity function
Correct answer
DIdentity function
Explanation
The example uses identity activation functions, meaning output equals input.
- A
- 4
How is the word embedding network reused for multiple input tokens?
- A
Different weights are used for each token
- B
A separate network is created for each token
- C
The same weights are used for each token
- D
Weights are randomly sampled for each token
Correct answer
CThe same weights are used for each token
Explanation
The transformer reuses the same word embedding weights for every token, allowing flexibility with input length.
- A
- 5
What does a token include in the vocabulary of a Transformer?
- A
Only individual letters
- B
Words, word fragments, and symbols
- C
Only complete words
- D
Only sentence boundaries
Correct answer
BWords, word fragments, and symbols
Explanation
The vocabulary can be a mix of words, word fragments (subwords), and special symbols like EOS.
- A
- 6
Why does a Transformer need positional encoding?
- A
To convert words into numbers
- B
To keep track of word order
- C
To normalize the output
- D
To calculate attention scores
Correct answer
BTo keep track of word order
Explanation
Positional encoding adds information about the position of each word in the sequence, since transformers process words in parallel and don't inherently know order.
- A
- 7
How are positional encoding values generated in the described method?
- A
Using the word embedding values themselves
- B
Using a sequence of alternating sine and cosine functions
- C
Using the softmax function
- D
Using random numbers
Correct answer
BUsing a sequence of alternating sine and cosine functions
Explanation
Positional encodings are created from sine and cosine functions of different frequencies, one for each embedding dimension.
- A
- 8
What ensures that each word in a sentence gets a unique sequence of positional encoding values?
- A
The sine and cosine squiggles have different frequencies for different embedding positions
- B
The softmax function is applied
- C
The weights are trained
- D
The activation functions are non-linear
Correct answer
AThe sine and cosine squiggles have different frequencies for different embedding positions
Explanation
As the embedding dimension increases, the sine/cosine waves become wider, giving each position a unique combination of values.
- A
- 9
When the order of words in a sentence is reversed, what happens to the positional encoding?
- A
The positional values are recalculated using different sine/cosine functions
- B
The positional encoding is no longer needed
- C
The positional values for the first and third words are swapped
- D
The positional values for each word remain the same
Correct answer
CThe positional values for the first and third words are swapped
Explanation
Positional values are tied to positions, not words. Swapping words swaps which word gets which position's encoding values.
- A
- 10
What is the purpose of self-attention in a Transformer?
- A
To convert words to numbers
- B
To determine word order
- C
To select the output token
- D
To keep track of relationships between words in the input
Correct answer
DTo keep track of relationships between words in the input
Explanation
Self-attention calculates how much each word should influence the encoding of every other word, capturing context.
- A
- 11
In self-attention, what are the three types of vectors created for each token?
- A
Embedding, Position, Context
- B
Input, Output, Hidden
- C
Query, Key, Value
- D
Encoder, Decoder, Loss
Correct answer
CQuery, Key, Value
Explanation
Queries, keys, and values are computed from the input using learned weight matrices. They are used to compute attention scores and weighted sums.
- A
- 12
How is the similarity between a query and a key calculated in the basic self-attention described?
- A
Dot product
- B
Euclidean distance
- C
Cosine similarity
- D
Cross-correlation
Correct answer
ADot product
Explanation
The dot product of the query and key vectors gives a scalar similarity score.
- A
- 13
What is the role of the softmax function in self-attention?
- A
To normalize the output values
- B
To select the maximum similarity score
- C
To convert similarity scores into probabilities that sum to 1
- D
To add non-linearity
Correct answer
CTo convert similarity scores into probabilities that sum to 1
Explanation
Softmax converts raw dot products into probabilities (0 to 1, sum=1) that determine how much each value contributes to the output.
- A
- 14
How are the value vectors used in self-attention?
- A
They are scaled by the softmax probabilities and summed to produce the self-attention output
- B
They are directly added to the query vectors
- C
They are ignored
- D
They replace the key vectors
Correct answer
AThey are scaled by the softmax probabilities and summed to produce the self-attention output
Explanation
Each value vector is multiplied by its corresponding softmax weight, then all weighted values are summed to form the final self-attention output for that token.
- A
- 15
Why can self-attention calculations be performed in parallel for all tokens?
- A
The tokens are processed sequentially
- B
The positional encoding is done afterwards
- C
The softmax function requires all similarities at once
- D
The same weights are reused for each token, allowing independent computation
Correct answer
DThe same weights are reused for each token, allowing independent computation
Explanation
Because the same set of weights is used for every token, the queries, keys, and values for all tokens can be computed simultaneously, enabling parallel processing.
- A
- 16
What is multi-head attention?
- A
Stacking multiple self-attention cells with different weight sets
- B
Using multiple queries per token
- C
Combining encoder and decoder attention
- D
Attention across multiple sentences
Correct answer
AStacking multiple self-attention cells with different weight sets
Explanation
Multi-head attention runs several self-attention operations in parallel (each with its own weights) to capture different types of relationships.
- A
- 17
How many self-attention cells were stacked in the original Transformer manuscript?
- A
4
- B
16
- C
8
- D
12
Correct answer
C8
Explanation
The original Transformer paper used 8 attention heads (multi-head attention with 8 parallel self-attention cells).
- A
- 18
What is the purpose of residual connections in a Transformer?
- A
To allow each sublayer to focus on its task without preserving all information
- B
To compute positional encoding
- C
To replace softmax
- D
To increase the number of parameters
Correct answer
ATo allow each sublayer to focus on its task without preserving all information
Explanation
Residual connections add the input of a sublayer to its output, so the sublayer only needs to learn the residual change, making training easier.
- A
- 19
What is the purpose of encoder-decoder attention in a Transformer?
- A
To normalize the values
- B
To compute self-attention in the encoder
- C
To encode the output sequence
- D
To allow the decoder to keep track of important words in the input
Correct answer
DTo allow the decoder to keep track of important words in the input
Explanation
Encoder-decoder attention helps the decoder focus on relevant parts of the input sentence during translation.
- A
- 20
In encoder-decoder attention, where do the queries, keys, and values come from?
- A
Queries from the decoder, keys and values from the encoder
- B
Queries from the encoder, keys and values from the decoder
- C
All from the decoder
- D
All from the encoder
Correct answer
AQueries from the decoder, keys and values from the encoder
Explanation
The decoder provides queries, while the encoder provides keys and values. This allows the decoder to attend to the input sequence.
- A
- 21
How does encoder-decoder attention help when translating a sentence like "Don't eat the pizza"?
- A
It focuses on the last word
- B
It ignores unimportant words
- C
It translates each word independently
- D
It emphasizes the word "Don't" to ensure negation is captured
Correct answer
DIt emphasizes the word "Don't" to ensure negation is captured
Explanation
By attending to the input, the decoder can give more weight to important words like "Don't" to preserve the meaning.
- A
- 22
In the decoding example shown, which token is used to initialize the decoder?
- A
PAD (Padding)
- B
EOS (End of Sequence)
- C
SOS (Start of Sequence)
- D
UNK (Unknown)
Correct answer
BEOS (End of Sequence)
Explanation
The example uses the EOS token to start decoding, though SOS is also commonly used.
- A
- 23
After the first translated word is selected, what does the decoder do next?
- A
It applies a softmax to the encoder output
- B
It recalculates word embeddings for all input words
- C
It stops immediately
- D
It feeds that word back into the decoder to generate the next word
Correct answer
DIt feeds that word back into the decoder to generate the next word
Explanation
The decoder uses the previously generated word as input to produce the next word, repeating until an EOS token is output.
- A
- 24
What determines when the decoding process stops?
- A
After a fixed number of steps
- B
When all input words are translated
- C
When the decoder outputs an EOS token
- D
When the softmax probability is above 0.5
Correct answer
CWhen the decoder outputs an EOS token
Explanation
The decoder outputs an EOS token to signal the end of the translated sequence.
- A
- 25
How are the weights in a Transformer initially set before training?
- A
Random values
- B
Calculated from word frequency
- C
All zeros
- D
Pre-determined from a dictionary
Correct answer
ARandom values
Explanation
Weights are initialized randomly and then optimized through backpropagation during training.
- A
- 26
What process is used to optimize the weights of a Transformer during training?
- A
Gradient ascent
- B
Forward propagation
- C
Random search
- D
Backpropagation
Correct answer
DBackpropagation
Explanation
Backpropagation computes gradients of the loss with respect to weights, and gradient descent updates the weights to minimize the loss.
- A
- 27
What technique did the original Transformer use to prevent values from growing too large?
- A
Early stopping
- B
Weight decay
- C
Normalization after each step
- D
Dropout
Correct answer
CNormalization after each step
Explanation
Layer normalization is applied after each sublayer (e.g., after self-attention and feed-forward networks) to stabilize training.
- A
- 28
How was the dot product similarity scaled in the original Transformer?
- A
Divided by the square root of the number of embedding values per token
- B
Raised to a power
- C
Multiplied by the number of tokens
- D
Added to a bias term
Correct answer
ADivided by the square root of the number of embedding values per token
Explanation
The dot product is divided by sqrtdk (where dk is the dimension of keys) to prevent large values in the softmax.
- A
- 29
How can a Transformer be given more capacity to fit complex data?
- A
By increasing the learning rate
- B
By reducing the vocabulary size
- C
By adding additional neural networks with hidden layers
- D
By using only one attention head
Correct answer
CBy adding additional neural networks with hidden layers
Explanation
Extra feed-forward layers or more attention heads increase the number of parameters, allowing the model to learn more complex patterns.
- A

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