KatInterview

Underfitting Shallow Nets and Dying Gradients in Deep Sigmoid MLPs

Machine LearningModel answer
HardModel answerMachine Learningbias-variancevanishing-gradientsbackpropagation

Last updated

Analyze why a shallow network underfits and a very deep sigmoid network fails to train, using the bias-variance decomposition, the backprop chain rule, ReLU and residual connections.

Context

You are building a fully connected network that predicts the probability a user saves an item, P(save | user, item). All hidden layers use sigmoid activations. Sweeping the depth from 2 to 20 layers, you see two separate problems:

  1. Shallow models (2-3 layers) converge quickly, but their training loss stays high and the test metric is poor.
  2. Very deep models (15-20 layers) barely train. The weights in the earliest layers stay close to their initial values.

Give a theoretical explanation and a practical diagnosis for both.

Part 1: Bias and variance

  1. Write the decomposition of expected squared error at a point x for an estimator f_hat(x), when the target is y = f(x) + epsilon, with epsilon zero-mean noise of variance sigma^2.
  2. Which failure mode does the shallow network show, in bias/variance terms? Justify using the observed training and test behavior, and say what you would change.
  3. Very large networks can fit the training data perfectly and still generalize well ("double descent"). Explain conceptually why this does not match the classical U-shaped expectation.

Part 2: Vanishing gradients

Consider an L-layer network with, for layer l:

  • z^(l) = W^(l) a^(l-1) + b^(l)
  • a^(l) = sigma(z^(l)), with a^(0) = x and sigma(z) = 1 / (1 + exp(-z)) applied element-wise.
  1. Using the chain rule, write the gradient of the scalar loss with respect to the first-layer weights, dLoss/dW^(1).
  2. State the maximum of sigma'(z). Show mathematically why repeated multiplication by this factor makes the gradient shrink exponentially with L.
  3. Compare two remedies: (a) replacing sigmoid with ReLU, and (b) adding residual connections of the form a^(l) = sigma(z^(l)) + a^(l-1). Explain how each one keeps the gradient from vanishing, and what limitations each has.

Answer in a structured way, with equations where they help.

Hints

Hint 1

Training loss is the key observation for Part 1: variance appears only as a gap between train and test performance, so ask whether that gap exists here.

Hint 2

For the gradient, define an error signal delta^(l) = dLoss/dz^(l) and write the recursion delta^(l) = diag(sigma'(z^(l))) (W^(l+1))^T delta^(l+1), then unroll it down to layer 1 and finish with the transpose of the input.

Hint 3

Sigmoid's derivative is sigma(z)(1 - sigma(z)); find where it peaks, then bound the product of L such factors. For the remedies, look at the per-layer Jacobian: diag(sigma') W for the plain network versus I + diag(sigma') W with the skip connection.