4.1.12 · D5Transformer Architecture

Question bank — The original - Attention is All You Need - architecture

1,719 words8 min readBack to topic

True or false — justify

Every item is a claim. Decide true or false, then say why — the reveal gives the reasoning, not just the verdict.

The Transformer removes recurrence, so it has no notion of word order at all.
False. Attention itself is order-blind, but the Positional Encoding (PE) from Positional Encoding is added to embeddings before the first layer, injecting order back in. Remove that and it truly loses order.
Layer normalization normalizes across the batch dimension like batch norm does.
False. Layer Normalization computes across the feature dimensions of a single token — so it works identically at batch size 1 and needs no running statistics.
The encoder uses masked self-attention just like the decoder.
False. Only the decoder's first sub-layer is masked. The encoder sees the whole input at once, so every token may attend to every other token — no Attention Masking.
Multi-head attention with heads costs roughly 8× the compute of single-head attention of the same .
False. Each head uses dims, so the total projected width stays . The cost is comparable — heads split the dimensions, they don't multiply them.
Residual connections are optional polish; the architecture works fine without them.
False. With 6 encoder + 6 decoder layers (many sub-layers deep), Residual Connections are what let gradients flow back without vanishing. Removing them typically breaks training entirely.
The scaling in is there to keep the output values small.
False. It keeps the softmax input in a well-conditioned range. Dot products grow like in variance; without scaling, softmax saturates and gradients vanish — see Scaled Dot-Product Attention.
Positional encodings are learned parameters trained by backprop.
False (in the original paper). The sine/cosine Positional Encoding is a fixed function of position — no parameters. The paper tested learned ones and found them roughly equal, choosing sinusoids for length extrapolation.
Cross-attention in the decoder uses the decoder's own output as keys and values.
False. In encoder–decoder attention, comes from the decoder but and come from the encoder output. That's exactly how the decoder reads the source sentence.
The FFN sub-layer mixes information between different token positions.
False. The position-wise FFN is applied independently to each position with shared weights — no cross-position interaction. Only attention mixes positions.
Softmax attention weights in one row can be negative if the scores are negative.
False. Softmax outputs are always non-negative and sum to 1 per row. Negative scores just become small positive weights, never negative ones.

Spot the error

Each line contains a deliberately wrong statement. Name the error and correct it.

"We scale by inside the attention softmax."
The scale inside softmax is , not . The factor scales the embeddings, a different place entirely.
"Masking sets future scores to 0 before softmax."
It sets them to , not 0. After softmax becomes weight 0; a raw 0 would still get positive weight — see Attention Masking.
"The decoder mask blocks position from seeing positions ."
Backwards. It blocks (the future) while allowing (past and present). Autoregressive generation needs the past, not blocks it.
"Each encoder layer has three sub-layers."
The encoder has two (self-attention + FFN). The decoder has three (masked self-attn + cross-attn + FFN). Easy to swap them.
"Layer norm is applied, then the residual is added: ."
In the original post-norm design it is — the residual is added first, then normalized together.
" means the FFN outputs 2048-dimensional vectors."
is the hidden width. The FFN expands from up to 2048, applies ReLU, then projects back to on output.
"Different heads are forced to learn different relationships by an explicit loss term."
There is no such loss. Heads differ only because their projection matrices start from different random inits and specialize during training — see Multi-Head Self-Attention.

Why questions

Answer the "why" — the reveal gives the mechanism.

Why multiply embeddings by before adding PE?
Embeddings start with variance but the Positional Encoding is bounded in . Scaling by lets the semantic content dominate early so PE nudges position without drowning meaning.
Why use sine and cosine rather than just one?
The sin/cos pair lets be written as a fixed linear (rotation) transform of , so the model can learn relative offsets easily.
Why give each dimension a different frequency (the term)?
It creates a spectrum of wavelengths: high-frequency dims flip fast (fine position), low-frequency dims change slowly (coarse position). Together they encode position uniquely across scales.
Why does the decoder need masking during training but not (in the same way) at inference?
In training with Teacher Forcing the whole target is fed at once, so masking prevents peeking at future tokens. At inference tokens are generated one at a time, so the future doesn't exist yet.
Why attention instead of recurrence for long-range dependencies?
Any two tokens connect in a single attention step (path length 1), whereas an RNN needs steps, degrading the signal. Attention makes distant relations as cheap as adjacent ones.
Why an FFN at all if attention already mixes information?
Attention is a weighted sum — essentially linear per output. The FFN's ReLU adds the non-linearity and extra capacity needed to transform each token's representation.

Edge cases

Boundary and degenerate scenarios — the answer explains what actually happens.

What does self-attention output for a sequence of length ?
With one token, its query attends only to itself, softmax gives weight 1, and the output is just its own value vector (transformed). Attention becomes an identity-like pass.
What about a totally empty sequence, ?
There are no tokens, so are empty () matrices and is a matrix — attention is dimensionally undefined and has nothing to output. Real pipelines guard against this: an all-padding batch is either dropped or a start token is required, so always holds.
What happens to the causal mask at the very first decoder position?
Position 1 may attend only to position 1 — every other entry in its row is . Its softmax row is a single 1, so it depends on nothing but itself, as it should.
If two tokens have identical embeddings and identical positions, can attention tell them apart?
No. Identical query/key/value vectors produce identical attention behaviour. In practice positions differ, so Positional Encoding breaks the tie — that's part of its job.
What if all scaled scores in a row are equal?
Softmax then gives a uniform distribution ( each), so the output is the plain average of all value vectors — attention "abstains" from focusing.
Does the sinusoidal PE break for a position longer than any seen in training?
No — that's the point. Since PE is a fixed continuous function of , it extrapolates to unseen lengths, unlike a learned table which has no entry beyond its trained range.
What happens if in LayerNorm and a token's features are all equal?
Then and you divide by zero. The small inside exists precisely to keep this degenerate constant-feature case numerically safe.
Recall Fast self-test

One decoder layer has how many sub-layers, and which one is masked? ::: Three sub-layers; only the first (self-attention) is causally masked. Where do and come from in cross-attention? ::: From the encoder output, while comes from the decoder. What do and count, respectively? ::: counts tokens (sequence length); counts numbers inside one token's vector (feature width).