Transformer Neural Networks Explained
- 22Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
- spaceFlip card
- KI knew it
- DI didn't know it
- ←Previous card
- →Next card
What is a Transformer neural network primarily used for?
Sequence-to-sequence tasks such as translation (e.g., English to Spanish) and is the foundation of models like ChatGPT.
Or swipe the card
22 cards
What is a Transformer neural network primarily used for?
Sequence-to-sequence tasks such as translation (e.g., English to Spanish) and is the foundation of models like ChatGPT.
How are input words converted into numbers for a Transformer?
Using word embedding, a neural network that takes a one-hot encoded token and outputs a vector of embedding values.
What is a token in the context of word embedding?
A token is any input unit in the vocabulary, which can be a word, word fragment, or special symbol like EOS (end of sentence).
Are the word embedding weights reused for each token in the input?
Yes, the same set of weights is used for every token, allowing flexibility for different sentence lengths.
How are word embedding weights determined?
Through backpropagation during training, using known input-output pairs (e.g., English-Spanish translations). Weights start random and are optimized step by step.
What is the purpose of positional encoding in a Transformer?
To keep track of word order in a sequence, since the model otherwise treats words as a bag.
How are positional encoding values generated?
Using alternating sine and cosine functions of different frequencies, providing a unique set of values for each position.
How is positional encoding combined with word embeddings?
The positional encoding values are added element-wise to the word embedding values.
What is the role of self-attention in a Transformer?
To capture relationships between words in the same sequence, e.g., associating 'it' with 'pizza'.
What are queries, keys, and values in self-attention?
Queries, keys, and values are linear projections of the input embeddings, computed using learned weight matrices. The dot product of query and keys gives similarity, and values are aggregated based on these similarities.
How is similarity between a query and a key computed in the basic self-attention?
Using the dot product: multiply corresponding elements and sum.
What does the softmax function do in self-attention?
It converts the similarity scores into probabilities between 0 and 1 that sum to 1, determining how much each word contributes to the encoding of the current word.
What are the final self-attention values for a word?
They are the weighted sum of the value vectors of all words, weighted by the softmax probabilities.
Are the self-attention weights (for Q, K, V) reused for each word in the sequence?
Yes, the same weight matrices are applied to each word, enabling parallel computation.
What is multi-head attention?
Stacking multiple self-attention cells (e.g., 8) with different weight sets to capture different relationships among words.
What are the main components of the Transformer encoder?
Word embedding, positional encoding, self-attention (multi-head), and residual connections.
What is a residual connection in the Transformer?
Adding the input of a layer (e.g., positional encoding) to its output (e.g., self-attention output).
How does the Transformer decoder start?
It begins with an EOS (end of sentence) token as the initial input, which is embedded and position-encoded.
What is the purpose of encoder-decoder attention?
To allow the decoder to attend to the encoder's output, ensuring important words from the input are not lost in translation.
How does the decoder select the output token?
It runs the encoded representation through a fully connected layer to produce scores for each token in the output vocabulary, then passes them through a softmax to pick the highest probability token.
What additional techniques are commonly used in Transformers besides the basic components?
Normalization after each step (e.g., after positional encoding and self-attention), scaled dot-product attention (divide by sqrt of embedding dimension), and additional neural networks with hidden layers.
Why is the dot product divided by the square root of the embedding dimension in scaled dot-product attention?
To prevent large dot products that could push softmax into regions with very small gradients, aiding training stability.

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