Neural Network Fundamentals
Level: 4 (Application — novel problems, no hints) Time limit: 60 minutes Total marks: 50
Question 1 — Forward Propagation & Activation Design (12 marks)
A 2-layer MLP processes input . The hidden layer has 2 units with tanh activation; the output layer has 1 unit with sigmoid activation.
(Rows of correspond to hidden units; .)
(a) Compute the pre-activations and activations of the hidden layer. Give to 3 decimals. (5)
(b) Compute the network output to 3 decimals. (4)
(c) An engineer proposes replacing tanh in the hidden layer with ReLU. Give one concrete numerical advantage and one concrete disadvantage relevant to this network's gradient flow. (3)
Question 2 — Softmax, Cross-Entropy & Backprop (12 marks)
A classifier outputs logits for a 3-class problem. The true label is class 0 (one-hot ).
(a) Compute the softmax probabilities to 3 decimals. (4)
(b) Compute the categorical cross-entropy loss to 3 decimals. (3)
(c) Derive and compute the gradient for the softmax + cross-entropy combination. Report all three components. (5)
Question 3 — Gradient Pathologies & Initialization (11 marks)
Consider a deep network of layers, each performing (scalar, no bias), with identical weight and sigmoid .
(a) Assume all activations sit near during training. Express the magnitude of as a function of and derive the condition on that keeps the product of layer-Jacobians from vanishing or exploding. (4)
(b) A ReLU network has a layer with fan-in . State the He initialization variance and standard deviation for its weights, and explain in one sentence why He uses rather than Xavier's . (4)
(c) You observe that a sigmoid-activated deep net trains fine at layer 1 but layer 40's weights barely move. Name the phenomenon and propose two distinct architectural/initialization fixes. (3)
Question 4 — Universal Approximation & Model Reasoning (8 marks)
(a) The Universal Approximation Theorem guarantees a single hidden layer can approximate any continuous function on a compact set. A student concludes: "Therefore deep networks are pointless." Give two rigorous reasons why this conclusion is wrong. (4)
(b) You must approximate the function on using a network with ReLU hidden units and a linear output. Construct explicit weights/biases for a two-hidden-unit network that computes exactly. Show the resulting function. (4)
Question 5 — Computational Graph & Autograd (7 marks)
Consider the scalar computation:
(a) Draw/describe the computational graph with intermediate nodes. (2)
(b) Using reverse-mode autodiff, compute and at the given point (to 3 decimals). Show the local gradients propagated at each node. (5)
Answer keyMark scheme & solutions
Question 1 (12 marks)
(a) Pre-activations :
- Unit 1: (1)
- Unit 2: (1)
Activations :
- (1.5)
- (1.5)
So .
(b) Output pre-activation: (2) (2)
(c) (3 marks, 1.5 each)
- Advantage: ReLU has gradient 1 for positive inputs (here ), avoiding tanh's gradient shrinkage (), so it propagates larger gradients → mitigates vanishing. (1.5)
- Disadvantage: ReLU can produce dead units if pre-activations go negative (zero gradient), and it is unbounded, potentially causing exploding activations; tanh is bounded and zero-centered. (1.5)
Question 2 (12 marks)
(a) Softmax: .
- ; sum (2)
- (2)
(b) (3)
(c) For softmax + cross-entropy the gradient simplifies: Derivation: ; using and gives . (2)
Values: (3)
Question 3 (11 marks)
(a) Each layer contributes Jacobian factor . Over 50 layers: (2) For stability (neither vanish nor explode) we need , i.e. . If → vanish; if → explode. (2)
(b) He init: . (2) Std . (1) Reason: ReLU zeroes half its inputs, halving the variance passed forward; the factor 2 compensates to keep signal variance constant. (1)
(c) (3 marks)
- Phenomenon: vanishing gradients (1). Sigmoid derivative compounds multiplicatively over depth. (1)
- Fixes (any two, 1 each): use ReLU/variants; use He/Xavier initialization; add residual/skip connections; batch normalization; LSTM-style gating (if recurrent). (2)
Question 4 (8 marks)
(a) Any two (2 each):
- UAT is an existence result: it guarantees a network exists but says nothing about the number of hidden units, which may be exponentially large for shallow nets. Deep nets can represent many functions far more compactly (parameter efficiency). (2)
- UAT says nothing about learnability — whether SGD can find those weights, or about generalization. Depth aids optimization and hierarchical feature reuse. (2)
(b) Note . (2) Construction:
- Hidden unit 1:
- Hidden unit 2:
- Output: (2)
Verification: for , output ; for , output ; at , output . Exact.
Question 5 (7 marks)
(a) Graph nodes (2 marks): ; ; ; . Leaves .
(b) Forward: , , , . (1)
Reverse pass:
- (1)
Combine: (3)
[
{"claim":"Q1a hidden pre-activations both 1.5 and tanh(1.5)=0.905","code":"import sympy as sp\nz1=sp.Rational(1,2)*1+sp.Rational(-1,2)*(-2)+0\nz2=1*1+0*(-2)+sp.Rational(1,2)\na=sp.tanh(1.5)\nresult = (z1==sp.Rational(3,2)) and (z2==sp.Rational(3,2)) and abs(float(a)-0.905)<0.001"},
{"claim":"Q1b output sigmoid(0.2)=0.550","code":"z2=0.2\nout=1/(1+sp.exp(-z2))\nresult = abs(float(out)-0.550)<0.001"},
{"claim":"Q2 softmax p0=0.659, loss=0.417, grad0=-0.341","code":"import sympy as sp\nz=[2.0,1.0,0.1]\nex=[sp.exp(v) for v in z]\ns=sum(ex)\np=[e/s for e in ex]\nL=-sp.log(p[0])\ng0=p[0]-1\nresult = abs(float(p[0])-0.659)<0.002 and abs(float(L)-0.417)<0.002 and abs(float(g0)+0.341)<0.002"},
{"claim":"Q3b He std for n=256 is 0.0884","code":"import sympy as sp\nvar=sp.Rational(2,256)\nstd=sp.sqrt(var)\nresult = abs(float(std)-0.08839)<0.001"},
{"claim":"Q5 gradients df/dx=14.437, df/dy=5.683","code":"import sympy as sp\nx,y=sp.symbols('x y')\nf=(x*y+sp.sin(x))**2\nfx=sp.diff(f,x).subs({x:1.0,y:2.0})\nfy=sp.diff(f,y).subs({x:1.0,y:2.0})\nresult = abs(float(fx)-14.437)<0.01 and abs(float(fy)-5.683)<0.01"}
]