34 min total

Deep Learning

Hyperparameters & batch norm

Hyperparameters & batch norm
RankHyperparameter tuning priority
1Learning rate
2Momentum term
3Mini batch size
4Hidden units
5# layers
6Learning rate decay
7Beta1, Beta2, epsilon
  1. Traditional sampling: earlier ML algorithms sampled hyperparameters in a grid format, all combinations in the grid were tried
  2. Random sampling: choosing hyper parameter combinations randomly, start with a broad range(coarse sampling). Once you identify a promising region, zoom in and sample more densely within that region(fine sampling)
Hyperparameters & batch norm — diagram

Sampling learning rate

Use logarithmic scale, consider values like 0.0001, 0.001, 0.01, 0.1, 1 and sample randomly on this log scale

r = -4 * np.random.rand() [-4, 0]

alpha =

Sampling the averaging parameter β

When beta is near 1, even minor variations can have significant impacts

Shifting beta from 0.9 to 0.9005 has minimal effect

Shifting from 0.999 to 0.9995 drastically changes the results

1/(1-beta) is highly sensitive to minor changes in beta when its near 1

So you can sample more densely when closer to 1

Hyperparameters & batch norm — diagram

Batch normalization

When training models like logistic regression, it’s widely known that normalizing the input features can speed up learning

"Can we normalize activations from any hidden layer to optimize the training of subsequent parameters?”

For each hidden layer, compute mean and variance of layer's activation

Normalize these activations to have zero mean and unit variance

After normalization, scale and shift values using learnable parameters γ and β

Hyperparameters & batch norm — diagram
Hyperparameters & batch norm — diagram

Traditional NN uses weights and biases, Batch norm too uses weights and biases, but replaces biases b with beta β and γ, which are learned during training

Update W using standard backprop

Learn β and γ using derivatives Dβ and Dγ derived from cost function

Update these parameters too using any optimizer

Why batch norm works

  1. Feature scaling accelerates the learning process
  2. DNNs can be sensitive to changes in weights in earlier layers, which might impact weights in subsequent layers. Batch norm makes the deeper layers less sensitive to such changes

Covariate shift: when distribution of model's input features in production changes compared to what model has seen during training and validation, this makes model perform not optimally

As weights in earlier layer change, values to subsequent layers also change, leading to an internal covariate shift

Regularization effect: An additional benefit of batch norm is its slight regularization effect. As batch norm computes mean and variance based on mini-batches, there’s inherent noise in the values, somewhat similar to the noise added by the dropout technique. This noise prevents over-reliance on any single hidden unit, which aids in regularization. However, the main purpose of batch norm isn’t regularization; it’s to normalize activations and speed up learning

Handling data during testing: Batch norm processes data in mini-batches, computing mean and variances accordingly. But when making predictions (especially for single data points),

use a running average of μ and computed during training.

Deep learning frameworks

Hyperparameters & batch norm — diagram

Criteria of choosing framework

  1. Ease of programming
  2. Running speed
  3. Truly open with a trust that they'll remain opensource