AI-ML interleaved practice
Instructions: Solve all problems. Show your work. Use notation for any math. Each problem tests a different subtopic — read carefully and choose the appropriate method. No calculators needed for conceptual parts; keep arithmetic exact where possible.
1. (6 marks) A single neuron receives inputs with weights and bias . Compute the pre-activation , then the output under (a) sigmoid and (b) ReLU. Give exactly and the ReLU output exactly.
2. (5 marks) You are training a 30-layer plain feedforward network with sigmoid activations and notice the early layers barely update. Name the phenomenon, explain mechanistically why depth + sigmoid causes it, and give two concrete architectural fixes.
3. (7 marks) For the Adam optimizer with , , , learning rate : at step the gradient is . Compute the bias-corrected , , and the resulting parameter update .
4. (4 marks) A 3-class classifier outputs logits . Compute the softmax probabilities (leave in terms of , then give decimal to 3 dp). Which class is predicted?
5. (6 marks) Given the true one-hot label and the predicted distribution from Problem 4, compute the cross-entropy loss. Then state what MSE would (incorrectly) give as its gradient character here, and explain in one sentence why cross-entropy is preferred for classification.
6. (6 marks) Consider the computational graph with . Using backpropagation on the graph, compute , , and .
7. (5 marks) You initialize a layer with input units feeding into a ReLU. State the He initialization variance and Xavier initialization variance, compute both numerically, and say which you should use here and why.
8. (6 marks) A mini-batch of pre-activations for one feature is . Apply batch normalization (with , , ). Compute the mean, variance, and the normalized outputs. Then state the one key difference between batch norm and layer norm regarding what axis the statistics are computed over.
9. (5 marks) Compare SGD-with-momentum () update to plain SGD. Given plain gradient sequence (constant) and learning rate , compute the momentum velocity and the resulting step size, versus plain SGD's step. What does this illustrate?
10. (4 marks) State the Universal Approximation Theorem precisely (what class of functions, what network, what conditions), and explain in one sentence why it does not guarantee that gradient descent will find such a network.
11. (4 marks) During dropout with keep-probability , a layer's activations at train time are scaled by inverted dropout. If a surviving neuron has raw activation , what value is used in the forward pass? What happens at test time?
Answer keyMark scheme & solutions
1. (Tests 3.1.3 Forward propagation + 3.1.4/3.1.5 activations) . (a) Sigmoid: . (b) ReLU: . Why: Must recognize forward-prop dot product before applying activation — the choice of activation changes only the final map, not .
2. (Tests 3.1.11 Vanishing gradients) Phenomenon: vanishing gradients. Sigmoid derivative . Backprop multiplies these across 30 layers; , so early-layer gradients underflow to ~0. Fixes: (a) use ReLU/GELU (derivative 1 in positive region), (b) residual/skip connections, (c) batch/layer norm, (d) careful (He) init. (Any two.) Why: The symptom (early layers frozen) points to gradient magnitude decay, not exploding — must distinguish from the exploding case.
3. (Tests 3.2.5 Adam) ; . Bias correction: ; . . Why: At bias correction is essential; the near-cancellation gives update , showing Adam's normalized early steps.
4. (Tests 3.1.6 Softmax) , , ; sum . Probs: . Predicted class = class 0. Why: Softmax normalizes exponentiated logits; pick the argmax.
5. (Tests 3.1.8 Cross-entropy) CE . MSE would produce gradients that vanish when the sigmoid/softmax saturates (small even when very wrong). Cross-entropy is preferred because its gradient w.r.t. logits is simply , giving strong, non-saturating learning signal. Why: Requires selecting the true-class probability (index 1) — a common trap is using the predicted class.
6. (Tests 3.1.9/3.1.10 Backprop on a computational graph) Let , , . . , . . . . Why: Chain rule through the graph — must track the product node's local grads.
7. (Tests 3.1.12 Weight init) He: . Xavier: (or variant). Use He because activation is ReLU (accounts for the halved variance from zeroing negatives). Why: Init choice is dictated by activation family — Xavier for tanh/sigmoid, He for ReLU.
8. (Tests 3.2.8 Batch norm) Mean . Deviations , squared , variance . . Normalized: . Difference: batch norm computes statistics across the batch dimension (per feature); layer norm computes across the feature dimension (per sample). Why: Must normalize over the batch axis here, contrasting with layer norm's per-example axis.
9. (Tests 3.2.3 Momentum) ; ; . Momentum step , vs plain SGD step . Illustrates: momentum accumulates along consistent gradient directions, accelerating (geometric approach to ). Why: Distinguish accumulating velocity from single-step gradient.
10. (Tests 3.1.7 UAT) UAT: A feedforward network with a single hidden layer containing finitely many neurons and a non-constant, bounded (or non-polynomial) activation can approximate any continuous function on a compact subset of to arbitrary accuracy. It is an existence theorem — it says weights exist, not that SGD (a local optimizer on a non-convex loss) will find them, nor how many neurons are needed. Why: Precision about "existence vs learnability."
11. (Tests 3.2.10 Dropout) Inverted dropout scales surviving activations by : . At test time no dropout is applied and no scaling is needed (expectations already match). Why: Inverted dropout puts the correction at train time so test forward pass is unchanged.
[
{"claim":"Adam step 1 update magnitude ≈ -0.1","code":"m=0.1*0.2; v=0.001*0.04; mhat=m/(1-0.9); vhat=v/(1-0.999); upd=-0.1*mhat/(vhat**0.5+1e-8); result = abs(upd + 0.1) < 1e-3"},
{"claim":"Backprop grads are dL/da=42, dL/db=28, dL/dc=14","code":"a,b,c=2,3,1; s=a*b+c; dLds=2*s; da=dLds*b; db=dLds*a; dc=dLds; result = (da,db,dc)==(42,28,14)"},
{"claim":"BatchNorm variance of [4,8,6,2] is 5","code":"xs=[4,8,6,2]; mu=sum(xs)/len(xs); var=sum((x-mu)**2 for x in xs)/len(xs); result = var==5"}
]