Exercises — Multi-layer perceptron architecture
Recall Symbol refresher (open if any notation feels unfamiliar)
- ::: the input feature vector, a column of numbers fed into the network.
- ::: the weight matrix of layer . Row , column holds , the strength of the wire from neuron (previous layer) to neuron (this layer).
- ::: the bias vector of layer , one number per neuron, that shifts the decision.
- ::: the pre-activation (weighted sum before the non-linearity).
- ::: the activation (after the non-linearity ).
- logits ::: the raw output-layer scores before softmax — real numbers of any size and sign, not yet probabilities.
- ::: activation function — ReLU, sigmoid, tanh, softmax. See 3.1.04-Activation-Functions.
Level 1 — Recognition
Exercise 1.1 (L1)
Label each of these layer roles as input, hidden, or output: (a) receives the raw 784 pixels and does no computation; (b) produces 10 numbers that sum to 1; (c) sits between the other two and extracts abstract features.
Recall Solution
(a) input layer — it only holds and forwards the raw feature vector ; no weights act inside it. (b) output layer — "sum to 1" is the fingerprint of softmax, used for multi-class predictions. (c) hidden layer — "hidden" means it never touches the outside world; it only reshapes data for the next layer.
Exercise 1.2 (L1)
A network is written . What do the four numbers count, and how many hidden layers are there?
Recall Solution
Each number is the count of neurons in that layer, read left (input) to right (output).
- = input neurons (one per pixel)
- and = the two hidden layers
- = output neurons (one per digit class)
So there are 2 hidden layers. The arrows mean "fully connected, information flows forward only."
Exercise 1.3 (L1)
Match each output-layer setup to its task: sigmoid (1 neuron) · softmax (K neurons) · linear (1 neuron). Tasks: predict a house price · classify email as spam/not-spam · classify a photo into 5 animal types.
Recall Solution
- House price → linear (1 neuron). Prices are unbounded real numbers; squashing them into would be wrong.
- Spam/not-spam → sigmoid (1 neuron). Two classes = one probability ; the other class is .
- 5 animal types → softmax (5 neurons). Mutually exclusive classes need probabilities that sum to 1.
Level 2 — Application
Exercise 2.1 (L2)
A hidden neuron has inputs , weights , and bias . Compute , then .
Recall Solution
What we do: the weighted-sum-plus-bias, exactly . Then the non-linearity: . Why the answer is 0: ReLU kills all negative pre-activations. This neuron is "off" for this input — a completely normal event, not an error.
Exercise 2.2 (L2)
Same neuron, but now the input is (only the middle and last numbers changed). Recompute and .
Recall Solution
. Positive input passes straight through unchanged — that is ReLU's whole personality on the positive side.
Exercise 2.3 (L2)
Compute for and . Recall .
Recall Solution
Why sigmoid here: it squashes any real number into so we can read the output as a probability.
- : . The midpoint — maximum uncertainty.
- : .
Exercise 2.4 (L2)
A digit network outputs logits for a 3-class toy problem. (Recall: logits are the raw output scores before softmax — any real numbers, not yet probabilities.) Compute the softmax probabilities and name the predicted class.
Recall Solution
Step 1 — exponentiate. makes every value positive (probabilities can never be negative) and stretches the gaps so a slightly bigger logit becomes a noticeably bigger score. Step 2 — divide by the sum (normalize). Why normalize? Three positive numbers are not yet a probability distribution — to be one, they must add up to exactly 1 (something is certain to happen). Dividing each by their total forces exactly that: the ratios are preserved but the pieces now sum to 1, turning raw scores into shares of a whole. Check: . ✓ (exactly 1 before rounding) Highest probability is index 1 (0.6652), so we predict class 1.
Level 3 — Analysis
Exercise 3.1 (L3)
Count the total trainable parameters of the architecture (weights and biases). Show the per-layer breakdown.
Recall Solution
The rule: a layer with inputs and neurons has weights (the matrix ) plus biases.
- Layer :
- Layer :
- Layer : This matches Example 1 in the parent note. Notice the biases () are a small slice — most parameters live in the weight matrices.
Exercise 3.2 (L3)
Prove that stacking two linear layers with no activation collapses to a single linear layer. Use and (biases dropped for clarity).
Recall Solution
Substitute the first equation into the second: Why this matters: matrix multiplication is associative, so two matrices multiply into one matrix . The whole two-layer stack is equivalent to a single linear layer with weights . No amount of stacking adds power without a non-linear in between. This is the entire reason activation functions exist — see 3.1.04-Activation-Functions and the single-perceptron limits.
Exercise 3.3 (L3)
Look at the figure. The XOR points cannot be split by one straight line. Explain in one paragraph why adding a hidden layer fixes this, and what each hidden neuron is doing geometrically.

Recall Solution
A single perceptron draws exactly one straight line (a linear decision boundary). XOR wants the two blue corners on one side and the two amber corners on the other — no single line can do that. A hidden layer supplies two lines (two hidden neurons, each drawing its own boundary — the dashed cyan lines in the figure). The output neuron then combines the two half-plane answers with a non-linearity, carving out the bent region that isolates the amber class. Geometrically: hidden neurons draw simple lines; the output neuron glues those lines into a non-linear boundary. That composition of simple pieces into a complex shape is the whole point of "multi-layer."
Level 4 — Synthesis
Exercise 4.1 (L4)
Design an MLP for the MNIST digit task and compute its total parameters: input , two hidden layers of and (ReLU), output (softmax).
Recall Solution
- :
- :
- : Design reasoning: the funnel shape compresses raw pixels into progressively more abstract features (strokes → loops → digit identity). The first layer dominates the parameter budget because 784 inputs are expensive — a hint at why CNNs replace this dense first layer with shared filters.
Exercise 4.2 (L4)
You have a strict budget of exactly 100 trainable parameters and an input of size , output of size (no activation on output for simplicity, but count all weights + biases). Choose a single hidden layer of size that fits the budget, and show your count.
Recall Solution
Parameters as a function of : Solve . Take the largest fitting value : Exactly on budget. A neat coincidence that lands on 100; had it not, we'd pick the largest below budget.
Level 5 — Mastery
Exercise 5.1 (L5) — Dying ReLU
A neuron's weights and bias have drifted so that for every training input it ever sees. Compute its output and its gradient contribution (the slope of ReLU at ). Explain why this neuron is effectively dead and how Leaky ReLU rescues it.
Recall Solution
Output: . The neuron always outputs 0. Gradient: ReLU's slope is for and for . At the slope is . Why dead: during backpropagation, the weight update is proportional to this local slope. A slope of means no gradient flows back, so the weights never change, so stays negative forever — a self-locking trap. Leaky ReLU rescue: has slope (not ) for . At the output is and the slope is . That tiny non-zero gradient lets the weights slowly crawl back to life. See 3.1.04-Activation-Functions and gradient descent.
Exercise 5.2 (L5) — Softmax shift-invariance (numerical stability)
Show that softmax is unchanged if you subtract the same constant from every logit: . Then verify numerically for using .
Recall Solution
Proof: The factor cancels top and bottom. Why we care: raw logits like make overflow to infinity. Subtracting makes the largest exponent , keeping every number safe — same probabilities, no overflow. Numerical check with shifted logits : Identical to Exercise 2.4's unshifted result. ✓
Exercise 5.3 (L5) — Degenerate all-equal input
Suppose every logit is equal: for classes. Compute the softmax output. What does the network "know"?
Recall Solution
Every is identical, so: For that is for each class. Interpretation: this is maximal uncertainty — the network is guessing uniformly and has learned nothing that distinguishes one class from another. This is exactly the output of a freshly initialized network (before training pushes the logits apart) and it makes a useful sanity baseline: a 10-class model should start near accuracy. Notice too that the constant vanished entirely — it cancels top and bottom — so only the differences between logits matter to softmax, never their absolute size (the same fact that powered Exercise 5.2).
Recall Quick self-audit checklist (open after finishing)
Which formula gives a single neuron's pre-activation? ::: How many parameters does a layer with inputs and neurons have? ::: What is a logit? ::: the raw output score before softmax — a real number, not yet a probability. Why must there be a non-linearity between layers? ::: without it, stacked linear layers collapse to one matrix (Ex 3.2). What does softmax on all-equal logits give? ::: for every class — pure uncertainty.