Intuition What this page is
The parent topic note taught you the method — the
three passes, the checklist. This page is the drill hall . We walk through every kind of
situation a paper reproduction throws at you, one fully-worked example per case, so that when you
sit down with a real PDF you have already met the shape of the problem before.
Read each example's Forecast line and actually pause — guess the answer — before scrolling.
That single habit is what turns reading into understanding.
Before any symbol appears, a promise: every quantity that shows up in a formula here will first be
named in plain words. If you see d k , you will already know it means "how many numbers are in one
query vector". Nothing is assumed.
When you reproduce a paper, the difficulties fall into a handful of repeating cell classes . Think
of this table as a checklist of "have I met this monster before?"
Cell
Class of situation
What makes it tricky
Example that covers it
A
Normal happy path
Everything stated, you just rebuild it
Ex 1
B
Missing detail (paper omits init / LR)
You must infer an unstated choice
Ex 2
C
Degenerate input — zero / empty / length-1
Formula must not divide by zero or crash
Ex 3
D
Sign / direction case — gradient can grow OR vanish
Same formula, opposite behaviour
Ex 4
E
Limiting behaviour — a quantity → 0 or → ∞
What happens at the extreme
Ex 5
F
Numbers don't match — you're off from the paper
Is it a bug or noise?
Ex 6
G
Real-world word problem — "should I even reproduce?"
Cost/benefit decision, not maths
Ex 7
H
Exam-style twist — a subtle trap in the formula
The "gotcha" they test you on
Ex 8
Each example below is tagged with its cell. Together they touch every row.
Recall Which cell is the scariest and why?
Cell F (numbers don't match) ::: because you cannot tell from the number alone whether it is a real bug or ordinary random variation — you need a statistical answer, not a guess.
Worked example Ex 1 (Cell A) · Rebuild scaled dot-product attention output size
A paper says: "queries Q , keys K , values V each have shape (sequence length = 4 , key
dimension d k = 8 ). We compute softmax ( Q K ⊤ / d k ) V ." What is the shape of the
final output?
First, in plain words: sequence length = 4 means there are 4 tokens (say 4 words). Key
dimension d k = 8 means each token is described by 8 numbers. Q , K , V are therefore
each a grid of 4 rows by 8 columns.
Forecast: guess the output shape before reading on — rows? columns?
Look at the figure below: it traces the shapes through the pipeline like water through pipes. Even
without seeing the image, here is what it shows in words — a Q , K , V box of shape 4 × 8 flows
right into a Q K ⊤ box of shape 4 × 4 (pair scores), then into a scale-and-softmax box
still 4 × 4 (row weights), then into a final × V box that returns to 4 × 8 — the
same shape it started with .
Steps.
Compute Q K ⊤ . Why this step? K ⊤ (the transpose) flips K from 4 × 8 to
8 × 4 , so the shared "8" lines up and can be summed away. A ( 4 × 8 ) ⋅ ( 8 × 4 )
multiply gives a 4 × 4 grid — one similarity score for every pair of tokens.
Divide by d k = 8 ≈ 2.828 . Why? This is the variance-taming step from
the parent note; it changes the values , never the shape . Still 4 × 4 .
Apply softmax across each row. Why? Softmax turns each row of raw scores into a set of
weights that sum to 1 — "how much does token i pay attention to each token". Shape unchanged: 4 × 4 .
Multiply by V (4 × 8 ). Why? ( 4 × 4 ) ⋅ ( 4 × 8 ) : the shared "4" cancels,
leaving 4 × 8 — a new 8-number description for each of the 4 tokens.
Answer: 4 × 8 — same shape as we started with. Attention rewrites each token, it does
not change how many there are or how long each is.
Verify: matrix shape rule ( m × n ) ( n × p ) = ( m × p ) applied twice:
( 4 × 8 ) ( 8 × 4 ) = 4 × 4 , then ( 4 × 4 ) ( 4 × 8 ) = 4 × 8 . ✓
Worked example Ex 2 (Cell B) · The paper never states the initialization
You are reproducing a deep convolutional net that uses ReLU activations. The paper gives every
hyperparameter except how the weights are first randomised. Your net trains to only 71% where
the paper reports 76%. What unstated choice is the likely culprit, and what value should you use?
Forecast: is this a training-loop bug, or a starting-point problem?
Steps.
Recall what initialization means: before training, every weight is a random number. Why care?
If those random numbers are too big, signals explode; too small, they vanish — training stalls
before it starts.
Note the activation: ReLU (outputs the input if positive, else 0). Why does this matter?
ReLU throws away half the signal on average, so a scheme built for symmetric activations
under-supplies variance.
Choose Kaiming (He) initialization , whose variance is n in 2 where
n in is the number of inputs to a neuron. Why the factor 2? It exactly compensates
for the "half the signal killed by ReLU" effect. (Xavier init uses n in 1 and
is right for tanh, wrong for ReLU.)
Sanity-scale check for a layer with n in = 512 : standard deviation
= 2/512 ≈ 0.0625 .
Answer: switch from the (wrongly assumed) Xavier to Kaiming init , std ≈ 0.0625 for a
512-input layer. See Model Debugging for how to confirm this closes the gap.
Verify: 2/512 = 0.00390625 = 0.0625 exactly. ✓
Lesson for the matrix: when a paper is silent, the default that matches the activation is
almost always the intended choice.
Worked example Ex 3 (Cell C) · The two degenerate sequences: empty and length-1
Same attention formula. Two edge inputs a real batch can hand you: (i) an empty sequence —
length 0 , zero tokens; and (ii) a length-1 sequence — a single token, d k = 8 . Does the
formula survive each, or does something divide by zero / crash?
Forecast: which of the two is the real danger — the empty one or the single-token one?
Case (i): the empty (zero-length) sequence.
Q , K , V are each 0 × 8 — a grid with no rows at all. Compute Q K ⊤ :
( 0 × 8 ) ( 8 × 0 ) = 0 × 0 . Why flag this? There is no row to apply softmax to.
Softmax over an empty row would compute ∑ (nothing) e (nothing) —
a sum over zero terms = 0 , so we divide by zero. Why this is the true crash case: unlike
length-1, the empty sequence produces a genuine 0/0 . Real frameworks either return an empty
0 × 8 tensor or raise an error, so you must guard against empty batches explicitly
(filter them out, or skip the block). This is the degenerate cell's real teeth.
Case (ii): the length-1 sequence.
Q , K , V are each 1 × 8 . Compute Q K ⊤ : ( 1 × 8 ) ( 8 × 1 ) = 1 × 1 — a
single number, the token's similarity with itself.
Divide by 8 . Why still safe? d k depends on d k = 8 , not on sequence
length, so there is no division by zero even though the sequence is minimal.
Softmax over a row of length 1. Why is this the crux? Softmax of a single value s is
e s e s = 1 — always exactly 1, regardless of s : the denominator is a sum over
one term, never zero.
Multiply the weight 1 by V (1 × 8 ): output = V unchanged.
Answer: length-1 is perfectly well-defined (the lone token attends to itself with weight 1.0 ,
output = V ); the empty sequence is the dangerous case — a 0/0 softmax — so guard against
zero-length inputs before the attention block. Run both as sanity checks.
Verify: softmax of a single element s : e s / e s = 1 for every s ; and the empty-sequence
softmax denominator is a sum over zero terms = 0 . ✓
Worked example Ex 4 (Cell D) · Residual connection: does the gradient grow, vanish, or exactly cancel?
The parent note gave the residual gradient
∂ x ∂ L = ∂ H ∂ L ( ∂ x ∂ F + I ) .
In plain words: L is the loss (how wrong we are), x is a layer's input,
H is the block output — the full thing the residual block produces, H ( x ) = F ( x ) + x ,
so ∂ L / ∂ H just means "how the loss changes when the block's output
changes"; F is the learned "residual" part (what the layer adds ); and I is
the identity (leave-it-alone) term. Suppose in one layer the learned part contributes a gradient
factor ∂ F / ∂ x of 0.1 (near-vanishing), in another it contributes
− 0.9 , and in a third — the nasty edge case — it contributes exactly − 1 .
Forecast: which is more dangerous — a small positive residual gradient, a negative one, or an
exact − 1 ?
Look at the figure below: two "gradient highways", one with a weak on-ramp, one with a subtractive
ramp. In words, it shows the learned path (+ 0.1 or − 0.9 ) running alongside the identity path
(+ I ), and the two adding to give 1.1 and 0.1 respectively — both non-zero.
Steps.
Case + 0.1 : the bracket is 0.1 + 1 = 1.1 . Why does this matter? Even though the learned
path is almost dead, the + I keeps the total at 1.1 — the gradient still flows. This
is exactly the vanishing-gradient rescue.
Case − 0.9 : the bracket is − 0.9 + 1 = 0.1 . Why check the negative sign? A residual path
can work against the identity. Here it nearly cancels it, leaving only 0.1 — the gradient
shrinks, but critically it is still non-zero and finite .
Edge case − 1 : the bracket is − 1 + 1 = 0 . Why call it out? This is the one value where a
single residual block does zero out the gradient — the learned part exactly opposes the
identity. In practice ∂ F / ∂ x landing on exactly − 1 is
vanishingly unlikely and never persists across many layers/dimensions, which is why residual nets
are safe in aggregate — but you should know the failure point exists.
Compare to a plain (non-residual) layer where the bracket would just be 0.1 or − 0.9 with
no + 1 : over 50 stacked layers, 0. 1 50 is astronomically tiny — dead. With + 1 , each layer
is near 1, so the product stays healthy.
Answer: the + I term dominates whenever the learned part is small (case + 0.1 → 1.1 ),
buffers even an adversarial part (case − 0.9 → 0.1 ), and vanishes only at the exact knife-edge
∂ F / ∂ x = − 1 (case − 1 → 0 ). See Attention Mechanisms and
Transfer Learning where the same "keep a direct path" trick recurs.
Verify: 0.1 + 1 = 1.1 , − 0.9 + 1 = 0.1 (both non-zero), and − 1 + 1 = 0 (the exact cancel). ✓
Worked example Ex 5 (Cell E) · What happens as
d k → ∞ without scaling?
The parent note showed Var ( Q K ⊤ ) = d k when query/key entries are standard random
numbers (mean 0, variance 1). "Variance" here just means how spread out the dot-product values
are . Take d k = 2 , then d k = 128 , then imagine d k → ∞ . Track the spread with and
without the d k divide.
Forecast: without scaling, does softmax get sharper or flatter as d k grows?
Look at the figure below: it plots two curves against d k . In words — the unscaled spread
d k climbs steeply (1.4 at d k = 2 up past 11 at d k = 128 ), while the scaled spread
sits flat on the line 1 for every d k .
Steps.
Unscaled spread (standard deviation) = d k . For d k = 2 : 2 ≈ 1.41 . For
d k = 128 : 128 ≈ 11.3 . Why standard deviation not variance? Std is in the same
units as the scores themselves, so it directly tells us how large the scores fed into softmax get.
As d k → ∞ , d k → ∞ : scores become enormous. Why is that bad? Softmax of
very large gaps sends almost all weight to a single token — the distribution collapses to a hard
one-hot, and its gradient becomes almost zero (saturation). Learning freezes.
Scaled version: divide scores by d k , so the spread becomes d k / d k = 1
for every d k . Why this exact divisor? It is the one number that cancels the growth,
holding the spread constant no matter how big the model gets.
Answer: unscaled, the limit d k → ∞ drives softmax into total saturation (flat gradients);
the d k divide pins the spread at 1 forever. That is why the scaling exists.
Verify: 128 ≈ 11.31 and 128 / 128 = 1 . ✓
Worked example Ex 6 (Cell F) · Is my 0.4-point gap a bug or noise?
The paper reports a translation score (BLEU) of 27.3 . You reproduce and get 26.9 — off by
0.4. You run your model with 5 different random seeds and get scores 26.7, 27.1, 26.8, 27.2, 26.9.
Is your reproduction broken , or is 26.9 within normal random variation?
Forecast: with a spread that big across seeds, will 27.3 look like an outlier or a plausible draw?
Steps.
Compute your mean: ( 26.7 + 27.1 + 26.8 + 27.2 + 26.9 ) /5 = 134.7/5 = 26.94 . Why the mean? A single
run is a coin flip; the mean estimates your method's true score.
Compute the spread (sample standard deviation). Deviations from 26.94:
− 0.24 , 0.16 , − 0.14 , 0.26 , − 0.04 . Squared: 0.0576 , 0.0256 , 0.0196 , 0.0676 , 0.0016 , sum = 0.172 .
Divide by n − 1 = 4 : 0.043 ; square root ≈ 0.2074 . Why n − 1 ? Using n − 1 (not n )
corrects the slight under-estimate you get from measuring spread around your own sample mean.
How many standard deviations away is the paper's 27.3? ( 27.3 − 26.94 ) /0.2074 ≈ 1.74 .
Why this ratio? It is a "z-score" — a distance measured in units of your own noise. Under 2 is
the usual "plausibly the same" threshold.
Answer: the paper's 27.3 is about 1.74 standard deviations above your mean — inside the
normal seed-to-seed wobble, so this is noise, not a bug . Do a proper significance test
before declaring failure, and log every seed with Experiment Tracking and Versioning .
Verify: mean = 26.94 ; sample std ≈ 0.2074 ; z ≈ 1.736 , which is < 2 . ✓
Worked example Ex 7 (Cell G) · Should you even reproduce this paper?
A paper claims a 0.3% accuracy gain on a benchmark. Reproducing it needs, by your estimate,
40 hours of your time plus 8 GPU-days of compute. Your actual goal is a product where a
0.3% gain is invisible to users, but the paper also introduces a new data-augmentation trick you
could reuse. Reproduce fully, partially, or skip?
Forecast: is the headline number the thing worth your 40 hours?
Steps.
Separate the claim from the tool . Why? Pass-1 reading (parent note) asks "is the
improvement relevant to my work?" Here the 0.3% headline is not — but the augmentation
trick might be a reusable building block, independent of the headline benchmark.
Estimate value-per-hour of each part. Why? Time is your scarcest resource; you rank tasks by
(value gained) ÷ (cost). Full reproduction of the headline: high cost (40h + 8 GPU-days), near-zero
product value → a terrible ratio. The augmentation trick alone: perhaps 4 hours to lift into your
pipeline, reusable across many future products → a strong ratio.
Apply the 80/20 rule from the parent note. Why? A small slice of a paper (here, one
augmentation routine) usually carries most of the reusable value; chasing the full benchmark is
the low-value 80% of effort.
Decide and log the decision . Why log it? So future-you (and teammates) know the reproduction
was skipped on purpose, not forgotten — record it in Experiment Tracking and Versioning .
Answer: don't reproduce the headline result; extract and unit-test only the augmentation trick
(~4h), skip the full-benchmark chase. This is a cost/benefit call, not a maths problem — and it is
the most common real decision. When you later have your own results worth reporting, see
Paper Writing and Publication .
Verify: decision rule "reproduce a component only if (reuse value) > (its build cost)" —
augmentation: 4h cost, reusable across products → net positive; headline: 40h+8 GPU-days, zero
product value → net negative. Logical check holds. ✓
Worked example Ex 8 (Cell H) · The softmax axis trap
An exam gives you attention scores as a 3 × 3 grid (3 query tokens, 3 key tokens) and asks:
"apply softmax." A careless student softmaxes over the wrong direction. Given the first query
row of raw scores [ 2 , 0 , − 2 ] (already scaled), compute its correct attention weights, and
state which axis softmax must run along and why.
Forecast: should the three numbers in one query's row add up to 1, or should each column add to 1?
Steps.
Identify the axis. Why the last axis (across keys)? Each query must produce a probability
distribution over the keys it looks at — so the numbers in one query's row must sum to 1.
Softmaxing down columns would wrongly make each key sum to 1 across queries. This is the classic trap.
Exponentiate the row [ 2 , 0 , − 2 ] : e 2 ≈ 7.389 , e 0 = 1 , e − 2 ≈ 0.1353 .
Why exponentiate? It turns any real scores into positive numbers whose ratios encode the gaps,
and it makes the largest score dominate smoothly.
Sum = 7.389 + 1 + 0.1353 = 8.524 . Divide each: 7.389/8.524 ≈ 0.867 , 1/8.524 ≈ 0.1173 ,
0.1353/8.524 ≈ 0.01587 . Why divide by the sum? That normalises them to add to exactly 1.
Answer: weights ≈ [ 0.867 , 0.117 , 0.0159 ] , which sum to 1 across the row (over keys).
The twist tested: softmax runs along the key axis (last dim), per query.
Verify: the three weights sum to 1 (up to rounding), and the largest raw score gets the
largest weight. ✓
Recall Rapid-fire scenario recall
Attention output shape given input ( 4 , d k ) ? ::: ( 4 , d k ) — attention rewrites tokens, keeps count and width.
Softmax of a single-element row equals? ::: exactly 1 , for any value.
Which degenerate sequence actually crashes attention? ::: the empty (zero-length) one — its softmax is a 0/0 ; length-1 is safe.
The + I in the residual gradient fails to protect the gradient only when? ::: the learned part's gradient equals exactly − 1 , which cancels the identity.
Divisor that pins attention-score spread to 1 for all d k ? ::: d k .
A 1.74-sigma gap from the paper means? ::: within normal seed noise — not a bug.
Softmax over which axis in attention? ::: the key axis (last dim), so each query's row sums to 1.
Mnemonic The reproduction monster list
A ll-good, B lank-detail, C ollapsed-input, D irection-sign, E xtreme-limit,
F ail-to-match, G o/no-go, H idden-trap → "A Big Cat Danced Every Friday, Gladly Hidden."