Transformers & Attention Questions with Answers

7 practice questions on Transformers & Attention (Generative AI & LLMs) with answers and step-by-step solutions. Try 7 samples below, then practise all 7 free in the AptiNest app.

Sample questions

Question 1Easy

What key mechanism did the Transformer architecture introduce in place of recurrence?

  1. Recurrent gating only
  2. Self-attention
  3. Decision trees
  4. Convolutional pooling

Answer: B. Self-attention

Explanation

Self-attention lets every token directly weigh every other token, enabling parallel training over the sequence instead of step-by-step recurrence.

Step-by-step solution

  1. Older sequence models (RNNs, LSTMs) processed tokens one step at a time.
  2. The Transformer replaced recurrence with self-attention, where each token directly weighs every other token.
  3. This lets training run in parallel over the whole sequence.

Why the other options are wrong

  • A. Gating is a feature of LSTMs and GRUs, the recurrent models the Transformer replaced.
  • C. Decision trees are unrelated classical ML models.
  • D. Convolution and pooling come from CNNs, not the Transformer's key idea.

Tip: Transformer key idea: attention replaces recurrence.

Question 2Medium

In self-attention, the query, key and value vectors for each token are produced by:

  1. Randomly sampling them afresh on each forward pass
  2. Copying the same embedding three times without any change
  3. Looking them up in a fixed dictionary
  4. Multiplying the token's representation by three learned weight matrices

Answer: D. Multiplying the token's representation by three learned weight matrices

Explanation

Q = XW_Q,
K = XW_K,
V = XW_V. Queries are compared with keys to get weights, which then mix the values.

Step-by-step solution

  1. Each token has a representation vector x.
  2. Three learned matrices give q = x W_Q, k = x W_K, v = x W_V.
  3. Queries are compared with keys to get weights, which then mix the values.

Why the other options are wrong

  • A. The projections are learned weights, fixed after training, not random each pass.
  • B. If Q, K and V were identical copies, attention would lose flexibility; separate matrices are learned.
  • C. They are computed from the token's current representation, not looked up.

Tip: Q asks, K answers the match, V carries the content.

Question 3Medium

What is the benefit of multi-head attention?

  1. It guarantees the model never hallucinates
  2. It makes the model process exactly one token at a time
  3. Different heads can attend to different kinds of relationships in parallel
  4. It removes the need for any feed-forward layers in the block

Answer: C. Different heads can attend to different kinds of relationships in parallel

Explanation

Each head has its own Q, K, V projections; their outputs are concatenated and projected, capturing e.g. syntax and coreference simultaneously.

Step-by-step solution

  1. Each head has its own Q, K and V projections.
  2. So different heads can learn different patterns, such as grammar links or which noun a pronoun refers to.
  3. Their outputs are concatenated and projected back together.

Why the other options are wrong

  • A. No architecture choice guarantees zero hallucination.
  • B. Heads run in parallel over all tokens, not one token at a time.
  • D. Transformer blocks still contain feed-forward layers.

Tip: Multi-head = several attention patterns in parallel.

Question 4Medium

Why do Transformers need positional encodings (or positional embeddings)?

  1. Self-attention alone ignores token order, so position must be added
  2. To store the model's weights compactly in fewer bytes of memory
  3. To speed up tokenization of long inputs
  4. To reduce the vocabulary size by merging tokens that often appear next to each other

Answer: A. Self-attention alone ignores token order, so position must be added

Explanation

Without positional information, "dog bites man" and "man bites dog" would look like the same set of tokens to attention.

Step-by-step solution

  1. Self-attention compares tokens as a set; shuffling the input gives the same weights.
  2. So 'dog bites man' and 'man bites dog' would look identical.
  3. Positional encodings add order information to each token's representation.

Why the other options are wrong

  • B. Positional encodings are about word order, not weight storage.
  • C. They have nothing to do with tokenization speed.
  • D. Merging frequent pairs is what tokenizers like BPE do.

Tip: No positions, no word order.

Question 5Medium

In scaled dot-product attention, softmax(QK^T / sqrt(d_k))V, why divide by sqrt(d_k)?

  1. To stop large dot products from saturating softmax and shrinking gradients
  2. To make attention causal by hiding all future positions from each query token
  3. To normalise the attention output so that it always sums to exactly 1
  4. To reduce the number of trainable parameters

Answer: A. To stop large dot products from saturating softmax and shrinking gradients

Explanation

Dot products of d_k-dimensional vectors have variance proportional to d_k. Scaling keeps softmax in a range where gradients flow well.

Step-by-step solution

  1. Q.K is a sum over d_k products, so its variance grows with d_k.
  2. Large scores push softmax into a near one-hot output.
  3. In that saturated region gradients become tiny and learning slows.
  4. Dividing by sqrt(d_k) brings scores back to a moderate range.

Why the other options are wrong

  • B. Causality comes from masking future positions, not from scaling.
  • C. Softmax already makes weights sum to 1; scaling does not do that.
  • D. Scaling by a constant adds no and removes no parameters.

Tip: Scale fixes saturation; mask fixes causality.

Question 6Hard

Standard self-attention computes a score for every pair of tokens. If the sequence length doubles, roughly how does the size of the attention score matrix change?

  1. It doubles
  2. It becomes 4 times larger
  3. It stays the same
  4. It becomes 8 times larger

Answer: B. It becomes 4 times larger

Explanation

The score matrix is n x n, so cost is O(n^2) in sequence length:
(2n)^2 = 4n^2. This is why long contexts are expensive.

Step-by-step solution

  1. The attention score matrix has one entry per pair of tokens: n x n.
  2. Doubling the length gives (2n) x (2n) = 4n^2.
  3. So the matrix is 4 times larger.

Why the other options are wrong

  • A. That would be linear growth; pairs grow with the square of length.
  • C. The matrix size depends directly on sequence length.
  • D. 8 times would be cubic growth.

Tip: Attention cost: double the length, four times the work.

Question 7Hard

In a decoder-only (GPT-style) Transformer, what does causal masking ensure?

  1. Each position attends only to itself and earlier positions
  2. Each token attends only to the token immediately after it
  3. Padding tokens receive the largest attention weights
  4. The encoder output is ignored, so only the decoder's weights are ever trained

Answer: A. Each position attends only to itself and earlier positions

Explanation

Masking the upper triangle of the attention matrix prevents the model from peeking at the tokens it is learning to predict.

Step-by-step solution

  1. A decoder-only model is trained to predict each next token.
  2. If a position could see later tokens, it could just copy the answer.
  3. The causal mask blocks attention to future positions, so each token sees only itself and earlier tokens.

Why the other options are wrong

  • B. That is the opposite: the mask hides future tokens.
  • C. Padding tokens are masked out so they get almost no attention.
  • D. Decoder-only models have no encoder at all.

Tip: Causal mask = no peeking ahead.

Practise all 7 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all Generative AI & LLMs topics · All topics