34 min total

Deep Learning

Initialization & gradient checks

Initialization & gradient checks

Input normalization

Steps

  1. Zero centering: Subtract mean from all training sample to ensure mean is 0
  2. Normalize variances: normalize data by dividing each feature by its standard deviation
Initialization & gradient checks — diagram

Vanishing and exploding gradients

When gradients(derivates) become extremely large(exploding) or extremely small(vanishing), making it impossible for the network to converge to solution

Initialization & gradient checks — diagram
Initialization & gradient checks — diagram

Solution:

Initialize weights with a scale suited to the activation function and layer width.

Weight initialization

python
W = np.random.randn(n_out, n_in) * np.sqrt(2 / n_in)

Where n is the number of neurons in layer l-1

For ReLU, He initialization uses a standard deviation of √(2/n_in).

For Tanh activations use

Gradient checking

Is a technique used to verify if gradients calculated by backprop are correct

Idea is to approximate graident of each param by tweaking it slightly and observing change in cost function. The computed gradient and this approximation should be close it backprop is implemented correctly

Flatten W₁, b₁, …, Wₗ, bₗ into a parameter vector θ, and their derivatives dW₁, db₁, …, dWₗ, dbₗ into dθ.

Initialization & gradient checks — diagram
Initialization & gradient checks — diagram

Implementation details

  1. Don’t use in training, only use in debugging
  2. If algorithm fails grad check, look at components to try to identify bug
  3. Remember if you are currently using regularization
  4. Disable dropout while checking gradients so the numerical and analytical calculations use the same network.
  5. Run at random intilizations, perhaps again after some training