3.1.2 · D3Neural Network Fundamentals

Worked examples — Multi-layer perceptron architecture

3,002 words14 min readBack to topic

This page is the "hands dirty" companion to the MLP parent note. There we built the machinery: the neuron equation , the activation , and the three output styles (sigmoid, softmax, linear). Here we run that machinery through every kind of input the topic can hand you — every sign, every degenerate case, every limit — so nothing surprises you later.

Before anything, one thing the parent note used but never pictured: what a single neuron actually is. The figure below lays out the whole flow left-to-right.

Figure — Multi-layer perceptron architecture

The scenario matrix

Every example below is tagged with the cell it covers. First, here is what each verbal label means, so the label→example mapping is never ambiguous:

  • "all-positive" = every input and the resulting , so ReLU passes it straight through (the plain, no-surprises case).
  • "mixed signs" = the weights and inputs combine to a negative , so ReLU clips it to 0 — the normal on/off switching of a healthy ReLU.
  • "zero input" = every , so only the bias is left.
  • "dead / dying ReLU" = is negative for every possible input, so the neuron is stuck at 0 forever (not just once).
  • "saturation (limit)" = is huge, pushing sigmoid to its flat tails near 0 or 1.
  • "overflow" = softmax logits so large that would break a computer.
  • "degenerate softmax" = all logits equal, forcing a uniform output.
Cell What makes it tricky Covered by
A — all-positive plain forward pass, ReLU stays "on" Ex 1
B — mixed signs some contributions negative, ReLU clips a negative to 0 Ex 2
C — zero input , only the bias survives Ex 3
D — dead / dying ReLU always , neuron outputs 0 forever Ex 4
E — sigmoid saturation (limit) $ z
F — softmax + numerical overflow large logits, explodes, need the shift trick Ex 6
G — degenerate softmax (all equal) every logit identical uniform output Ex 7
H — real-world word problem build architecture + count parameters Ex 8
I — exam twist (linear collapse) remove , prove layers merge into one Ex 9

Example 1 — Cell A: the all-positive warm-up

Forecast: everything here is positive. Guess now — will ReLU change the answer or leave it alone?

  1. Compute the pre-activation . Why this step? is the neuron's "vote total" — every input scaled by how much the neuron cares, plus the bias nudge. Everything downstream depends on this one number. Notice every weight and every input is positive, so every term adds — this is exactly what "all-positive" means.

  2. Apply ReLU. Why this step? ReLU asks "is the vote positive?" Here yes, so it passes through untouched.

Verify: , so ReLU is the identity — output equals . Sanity: all four contributions () are positive and simply add up, no clipping possible. Answer . ✓


Example 2 — Cell B: mixed signs, ReLU clips

Forecast: the third weight is and its input is — that's a big negative pull. Will survive?

  1. Compute . Why this step? Negative weight positive input negative contribution. The neuron is voting against this pattern. The signs mix, and the negatives win — that is what "mixed signs" means here.

  2. Apply ReLU. Why this step? ReLU asks "positive vote?" — no. So it outputs exactly 0. The neuron stays silent for this input.

Verify: ReLU floors it to 0. This is the normal, healthy behaviour of ReLU: silent on inputs it dislikes, active on ones it likes. (Contrast with Cell D below, where it's stuck silent forever.) Answer . ✓

The figure below plots the ReLU curve and marks both of these cases on it — the orange dot is Example 1's positive passing straight through, and the magenta dot is this example's negative getting flattened to 0. Notice the sharp "elbow" at where ReLU switches from "off" (flat at 0) to "on" (rising line).

Figure — Multi-layer perceptron architecture

Example 3 — Cell C: zero input, only the bias survives

Forecast: every input is zero. Does the neuron output zero too?

  1. Compute . Why this step? Every weighted term dies because . Only the bias is left. This is exactly what the bias is for — it lets a neuron have a preferred output even when it hears nothing.

  2. Apply sigmoid. Why this step? Sigmoid squashes any real number into ; here it turns the leftover bias into a probability-like value.

Verify: with all inputs zero the output must equal . Since , the output must be above (sigmoid crosses at ). Indeed . ✓


Example 4 — Cell D: the dying-ReLU trap

Forecast: can any non-negative input ever make this neuron fire?

  1. Write for a general non-negative input. Why this step? To prove "always dead" we can't test one input — we must reason over all allowed inputs at once.

  2. Bound from above. Since , the terms and are . So Why this step? The largest can ever be is when , giving . Bigger inputs only push more negative.

  3. Apply ReLU. Why this step? We just proved for every allowed input, and ReLU sends every negative number to 0 — so the output is 0 no matter what, confirming the neuron is dead.

Verify: the neuron's gradient through ReLU is 0 whenever , so backprop (see backprop) can never update these weights — it is stuck dead permanently. This is the dying ReLU problem, fixed by Leaky ReLU which leaks a small slope for . ✓


Example 5 — Cell E: sigmoid saturation (a limit)

Forecast: lives in . How close to the edges does push it?

  1. Large positive logit. Why this step? is tiny, so the denominator is barely above 1 — output is glued near 1.

  2. Large negative logit. Why this step? Now dominates the denominator, crushing the output near 0.

  3. The gradient. The sigmoid derivative is . Why this step? When is near 0 or near 1, the product collapses to — the vanishing gradient. Learning stalls in these flat tails.

Verify: limiting behaviour: and . Our values and sit right at those limits. The maximum of is at ; both our gradients are microscopic by comparison. ✓

The figure below shows why: the violet sigmoid curve flattens hard in both tails, and the orange dashed curve (its slope ) is a tiny bump near that vanishes to nothing at — the two magenta dots sit exactly where the slope has died.

Figure — Multi-layer perceptron architecture

Example 6 — Cell F: softmax with overflow, and the shift trick

Forecast: the logits are huge but their gaps are tiny (1 apart). Guess: will the probabilities be extreme or gentle?

Recall softmax: .

  1. Shift by the max. Subtract from every logit. Why this step? Softmax is unchanged if we subtract the same constant from every logit, because and the cancels top and bottom. But now the exponents are small and safe — no overflow.

  2. Exponentiate the shifted logits (rounded to 4 decimals). Why this step? Softmax needs in the numerator; exponentiating turns each shifted logit into a positive "unnormalized weight" that we can then compare and normalize.

  3. Normalize. Sum (this total is approximate — it is the sum of the rounded values above, not an exact figure). Why this step? Dividing each weight by the total forces the outputs to sum to 1, turning raw scores into a valid probability distribution.

Verify: probabilities sum to (the small shortfall from 1 is pure rounding — with full precision they sum to exactly 1). The middle class (largest logit) wins with , but the gaps are only 1 apart so it's not a landslide — matching the forecast that gentle logit gaps give gentle probabilities. The absolute size (1000) was a red herring; only differences matter. ✓


Example 7 — Cell G: degenerate softmax (all logits equal)

Forecast: the network is perfectly undecided. What probability does each class get?

  1. Shift by the max (): . Why this step? Same overflow-safe trick; also makes the symmetry obvious.

  2. Exponentiate: for all four, so the vector is , sum . Why this step? Softmax's numerator is ; since every shifted logit is 0, every unnormalized weight equals — they are all identical, which is what forces a uniform result.

  3. Normalize: Why this step? Equal inputs must give equal outputs by symmetry — there is no information to prefer any class.

Verify: general rule — if all logits are equal, softmax outputs each. Here , and . ✓ This is exactly the state an untrained network starts near, and it's the maximum-uncertainty output.


Example 8 — Cell H: real-world word problem (build + count)

Forecast: it's regression, not classification — guess the output activation before reading.

  1. Choose the output layer. One output neuron, no (linear) activation. Why this step? We predict a real number (0–100), not a probability. Sigmoid/softmax would trap the output in ; a linear output can produce any real value. (Feature scaling belongs to feature engineering.)

  2. Lay out the shapes. Input 6 → Hidden1 12 → Hidden2 6 → Output 1. Each weight matrix is (neurons in ) (neurons in ); each layer also has one bias per neuron. Why this step? The parameter count comes directly from these shapes — we can't count weights and biases until we know how many neurons feed into how many, so pinning down each layer's size is the prerequisite for the arithmetic in step 3.

  3. Count parameters using per layer. Why this step? Total learnable parameters all weights all biases. This decides model capacity and overfitting risk — where dropout would help.

Verify: layer breakdown parameters, with output activation linear (identity). Units check: input features feed a chain of matrix multiplies ending in a single scalar score — dimensionally a real number, correct for a 0–100 score. ✓


Example 9 — Cell I: the exam twist (why layers collapse without )

Forecast: three matrices in a row with no non-linearity — how many effective layers remain?

  1. Set up (ignore biases for clarity). Let Input , and each layer just does (no ). Why this step? Biases only add a constant shift and don't change the "do the layers merge?" question; dropping them keeps the algebra clean so the collapse is easy to see, and the same argument works with biases included.

  2. Compose the matrices. Because matrix multiplication is associative, Why this step? Without a non-linearity between them, the layers merge — three matrices are equivalent to their single product .

  3. Multiply the inner two matrices first. Why this step? We collapse two of the three layers into one matrix; doing the inner product first keeps the numbers small and matches the left-to-right flow of the network.

  4. Multiply by to get the single equivalent layer. Why this step? This finishes the collapse: all three "layers" reduce to one weight row, which we can read off directly as a plain linear formula.

  5. Read off the formula. With and , Why this step? This is the punchline — the "deep" three-layer network computes exactly the same thing as a single linear layer with weights and .

Verify: the whole "deep" network computes — a single linear layer. Spot-check with : the layer-by-layer path gives , then , then ; and the collapsed formula gives — identical. That's why the parent note insists on : it breaks this collapse and is what separates an MLP from the linear single perceptron. ✓


Recall

What survives at a neuron when every input is zero? ::: Only the bias ; output is . Why does subtracting leave softmax unchanged? ::: The common factor cancels in numerator and denominator; only logit differences matter. Why is a ReLU neuron with all-negative reachable "dead"? ::: Its gradient is 0 for , so backprop can never update it and its output stays stuck at 0 forever. Without any activation function, what does a 3-layer network equal? ::: One linear layer, .