Lesson deck

Neural networks and backpropagation: gradients, checks and initialisation flashcards

Reviewing needs JavaScript. You can read every card in the list below.

Loading your cards...

Back to the lesson10 cards in this deck

Read all 10 cards as a list
  1. Front
    Why does a neural network need a non-linear activation?
    Back
    An affine function of an affine function is affine: W2(W1 x + b1) + b2 = (W2 W1) x + (W2 b1 + b2). Without an activation, any number of layers is one linear layer, and XOR cannot be solved (a linear rule gets at most 3 of 4 points). Two ReLU units, relu(a+c) and relu(a+c-1) with output h1 - 2 h2, solve it.
  2. Front
    Shapes and parameter count of a 2-layer network (d inputs, h hidden units, k classes)?
    Back
    W1 is h x d, b1 is h, W2 is k x h, b2 is k, so there are h(d+1) + k(h+1) parameters: 101,770 for 784, 128 and 10. A batch X of n rows gives Z1 = X W1^T + b1 of shape n x h. A gradient always has the shape of its parameter.
  3. Front
    Sigmoid and tanh: what is saturation, in numbers?
    Back
    Far from zero both flatten, so their derivatives collapse. Sigmoid derivative: 0.25 at 0, 0.0066 at 5, 4.5e-5 at 10 (never above 0.25). Tanh derivative: 1 at 0, 1.8e-4 at 5, 8.2e-9 at 10. Ten sigmoid layers shrink the derivative part of the gradient by at least 0.25^10, about 1e-6.
  4. Front
    What is a dead ReLU, and how does GELU differ?
    Back
    The ReLU derivative is exactly 0 for negative inputs, so a unit that is negative on all the data gets no gradient and cannot recover. GELU = z times the normal CDF of z is smooth and gives small non-zero values for negative z (-0.159 at z = -1), so gradients still flow.
  5. Front
    Write the backward pass of a 2-layer ReLU network with softmax cross-entropy.
    Back
    delta2 = p - onehot(y); dW2 = delta2 a1^T; db2 = delta2; da1 = W2^T delta2; delta1 = da1 * 1[z1 > 0]; dW1 = delta1 x^T; db1 = delta1. Each gradient has its parameter's shape. Cache z1, a1 and p from the forward pass.
  6. Front
    Why is backprop cheap, and what does it cost in memory?
    Back
    It evaluates the chain rule from the output backwards, reusing the gradient of the layer after and the saved forward values, so one sweep gives every parameter's gradient. The saved activations stay in memory until the backward pass ends and grow with depth and batch size, so training needs more memory than prediction.
  7. Front
    How do you gradient-check a backward pass, and what errors mean what?
    Back
    Nudge one parameter by +h and -h and compare (L(w+h) - L(w-h)) / 2h with the analytic gradient, in double precision on a few examples. Relative error 1e-7 or less is good; above 1e-2 is probably a bug (CS231n; deeper nets accumulate error, so 1e-2 may be fine for 10 layers). In the lesson the correct code gave 2.4e-11 and a missing ReLU mask gave 1.0.
  8. Front
    Two cheap sanity checks before training a network?
    Back
    The initial loss should be about ln C for C balanced classes (2.3026 for 10; 0.693 for 2), and the model must be able to overfit a tiny batch to near zero loss (4 points reached 0.0067 in the lesson). If either fails, look for a bug before tuning anything.
  9. Front
    What causes vanishing and exploding gradients?
    Back
    The gradient through L layers is a product of L per-layer factors (weight scale times activation derivative). Below 1 it shrinks exponentially, above 1 it grows exponentially. In the lesson's 20-layer test the per-layer gradient factor was 0.227 for sigmoid with Xavier weights and 2.10 for ReLU with twice He's variance. Saturation does not guarantee vanishing: tanh with std 1.0 exploded.
  10. Front
    Xavier versus He initialisation, and why not zero?
    Back
    Xavier: variance 2/(n_in + n_out), about 1/n for a square layer, for roughly linear layers. He: variance 2/n_in for ReLU, which zeroes half the pre-activations; with Xavier a ReLU net had its activation rms multiplied by about 0.71 per layer. All-equal weights, zero included, make every unit in a layer identical, so symmetry never breaks.