Level 4 — ApplicationNeural Network Fundamentals

Neural Network Fundamentals

60 minutes50 marksprintable — key stays hidden on paper

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 x=[1,2]\mathbf{x} = [1, -2]^\top. The hidden layer has 2 units with tanh activation; the output layer has 1 unit with sigmoid activation.

W(1)=[0.50.51.00.0],b(1)=[00.5],W(2)=[1.01.0],b(2)=0.2W^{(1)} = \begin{bmatrix} 0.5 & -0.5 \\ 1.0 & 0.0 \end{bmatrix}, \quad \mathbf{b}^{(1)} = \begin{bmatrix} 0 \\ 0.5 \end{bmatrix}, \quad W^{(2)} = \begin{bmatrix} 1.0 & -1.0 \end{bmatrix}, \quad b^{(2)} = 0.2

(Rows of W(1)W^{(1)} correspond to hidden units; z=Wx+bz = Wx + b.)

(a) Compute the pre-activations and activations of the hidden layer. Give a(1)\mathbf{a}^{(1)} to 3 decimals. (5)

(b) Compute the network output y^\hat{y} 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 z=[2.0,1.0,0.1]\mathbf{z} = [2.0, 1.0, 0.1] for a 3-class problem. The true label is class 0 (one-hot [1,0,0][1,0,0]).

(a) Compute the softmax probabilities p\mathbf{p} to 3 decimals. (4)

(b) Compute the categorical cross-entropy loss LL to 3 decimals. (3)

(c) Derive and compute the gradient L/z\partial L / \partial \mathbf{z} for the softmax + cross-entropy combination. Report all three components. (5)


Question 3 — Gradient Pathologies & Initialization (11 marks)

Consider a deep network of L=50L=50 layers, each performing a(l)=σ(wa(l1))a^{(l)} = \sigma(w\, a^{(l-1)}) (scalar, no bias), with identical weight ww and sigmoid σ\sigma.

(a) Assume all activations sit near σ(z)0.2\sigma'(z) \approx 0.2 during training. Express the magnitude of L/a(0)\partial L / \partial a^{(0)} as a function of ww and derive the condition on w|w| that keeps the product of layer-Jacobians from vanishing or exploding. (4)

(b) A ReLU network has a layer with fan-in nin=256n_{in} = 256. State the He initialization variance and standard deviation for its weights, and explain in one sentence why He uses 2/nin2/n_{in} rather than Xavier's 1/nin1/n_{in}. (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 f(x)=xf(x) = |x| on [1,1][-1, 1] using a network with ReLU hidden units and a linear output. Construct explicit weights/biases for a two-hidden-unit network that computes f(x)f(x) exactly. Show the resulting function. (4)


Question 5 — Computational Graph & Autograd (7 marks)

Consider the scalar computation: f(x,y)=(xy+sinx)2,x=1.0,  y=2.0f(x, y) = (x \cdot y + \sin x)^2, \quad x = 1.0, \; y = 2.0

(a) Draw/describe the computational graph with intermediate nodes. (2)

(b) Using reverse-mode autodiff, compute f/x\partial f/\partial x and f/y\partial f/\partial y 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 z(1)=W(1)x+b(1)z^{(1)} = W^{(1)}\mathbf{x} + \mathbf{b}^{(1)}:

  • Unit 1: 0.5(1)+(0.5)(2)+0=0.5+1.0=1.50.5(1) + (-0.5)(-2) + 0 = 0.5 + 1.0 = 1.5 (1)
  • Unit 2: 1.0(1)+0.0(2)+0.5=1.51.0(1) + 0.0(-2) + 0.5 = 1.5 (1)

Activations a(1)=tanh(z(1))a^{(1)} = \tanh(z^{(1)}):

  • tanh(1.5)=0.90515\tanh(1.5) = 0.90515 (1.5)
  • tanh(1.5)=0.90515\tanh(1.5) = 0.90515 (1.5)

So a(1)=[0.905,0.905]\mathbf{a}^{(1)} = [0.905, 0.905]^\top.

(b) Output pre-activation: z(2)=1.0(0.90515)+(1.0)(0.90515)+0.2=0.2z^{(2)} = 1.0(0.90515) + (-1.0)(0.90515) + 0.2 = 0.2 (2) y^=σ(0.2)=11+e0.2=0.54980.550\hat{y} = \sigma(0.2) = \frac{1}{1+e^{-0.2}} = 0.5498 \approx 0.550 (2)

(c) (3 marks, 1.5 each)

  • Advantage: ReLU has gradient 1 for positive inputs (here z=1.5>0z=1.5>0), avoiding tanh's gradient shrinkage (tanh(1.5)0.18\tanh'(1.5)\approx0.18), 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: pi=ezi/jezjp_i = e^{z_i}/\sum_j e^{z_j}.

  • e2.0=7.389,  e1.0=2.718,  e0.1=1.105e^{2.0}=7.389,\; e^{1.0}=2.718,\; e^{0.1}=1.105; sum =11.212=11.212 (2)
  • p0=7.389/11.212=0.659p_0 = 7.389/11.212 = 0.659
  • p1=2.718/11.212=0.242p_1 = 2.718/11.212 = 0.242
  • p2=1.105/11.212=0.099p_2 = 1.105/11.212 = 0.099 (2)

(b) L=lnp0=ln(0.659)=0.417L = -\ln p_0 = -\ln(0.659) = 0.417 (3)

(c) For softmax + cross-entropy the gradient simplifies: Lzi=piyi\frac{\partial L}{\partial z_i} = p_i - y_i Derivation: L=kyklnpkL=-\sum_k y_k \ln p_k; using pk/zi=pk(δkipi)\partial p_k/\partial z_i = p_k(\delta_{ki}-p_i) and kyk=1\sum_k y_k = 1 gives piyip_i - y_i. (2)

Values: (3)

  • L/z0=0.6591=0.341\partial L/\partial z_0 = 0.659 - 1 = -0.341
  • L/z1=0.2420=0.242\partial L/\partial z_1 = 0.242 - 0 = 0.242
  • L/z2=0.0990=0.099\partial L/\partial z_2 = 0.099 - 0 = 0.099

Question 3 (11 marks)

(a) Each layer contributes Jacobian factor σ(z)w0.2w\sigma'(z)\cdot w \approx 0.2w. Over 50 layers: La(0)l=1500.2w=0.2w50\left|\frac{\partial L}{\partial a^{(0)}}\right| \propto \prod_{l=1}^{50} |0.2\,w| = |0.2w|^{50} (2) For stability (neither vanish nor explode) we need 0.2w1|0.2w| \approx 1, i.e. w5|w| \approx 5. If 0.2w<1|0.2w|<1 → vanish; if >1>1 → explode. (2)

(b) He init: Var(w)=2/nin=2/256=0.0078125\text{Var}(w) = 2/n_{in} = 2/256 = 0.0078125. (2) Std =0.0078125=0.08839= \sqrt{0.0078125} = 0.08839. (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 0.25\le 0.25 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 x=ReLU(x)+ReLU(x)|x| = \text{ReLU}(x) + \text{ReLU}(-x). (2) Construction:

  • Hidden unit 1: w1=1,b1=0h1=ReLU(x)w_1=1, b_1=0 \Rightarrow h_1=\text{ReLU}(x)
  • Hidden unit 2: w2=1,b2=0h2=ReLU(x)w_2=-1, b_2=0 \Rightarrow h_2=\text{ReLU}(-x)
  • Output: f^=1h1+1h2+0=ReLU(x)+ReLU(x)=x\hat{f} = 1\cdot h_1 + 1\cdot h_2 + 0 = \text{ReLU}(x)+\text{ReLU}(-x) = |x| (2)

Verification: for x>0x>0, output =x=x; for x<0x<0, output =x=-x; at 00, output =0=0. Exact.


Question 5 (7 marks)

(a) Graph nodes (2 marks): u=xyu = x\cdot y; s=sinxs=\sin x; v=u+sv = u+s; f=v2f = v^2. Leaves x,yx,y.

(b) Forward: u=2.0u=2.0, s=sin1=0.8415s=\sin 1=0.8415, v=2.8415v=2.8415, f=8.074f=8.074. (1)

Reverse pass:

  • f/v=2v=5.6829\partial f/\partial v = 2v = 5.6829 (1)
  • v/u=1,  v/s=1\partial v/\partial u = 1,\; \partial v/\partial s = 1
  • u/x=y=2,  u/y=x=1\partial u/\partial x = y = 2,\; \partial u/\partial y = x = 1
  • s/x=cosx=0.5403\partial s/\partial x = \cos x = 0.5403

Combine: (3) fx=5.6829(12+10.5403)=5.6829×2.5403=14.437\frac{\partial f}{\partial x} = 5.6829(1\cdot 2 + 1\cdot 0.5403) = 5.6829 \times 2.5403 = 14.437 fy=5.6829(1x)=5.6829×1=5.683\frac{\partial f}{\partial y} = 5.6829(1 \cdot x) = 5.6829 \times 1 = 5.683


[
  {"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"}
]