Home/AI/ML Notes/Deep Learning and Machine Learning/How Neural Networks Learn & the DL Training Process
⌂ Main Page
Deep Learning and Machine Learning

How Neural Networks Learn & the DL Training Process

Forward and backward propagation, the training loop, activation functions, monotonic and convex functions.

On this page

How do neural networks learn ?

The learning process is about updating the values of weights matrix W and biases vector b to find a loss function minimum by using gradient descent through partial derivatives of loss function. Derivatives describe the slope of the function, and thus we know how to manipulate variables in order to move downhill.

Alpha = learning rate (important to set it right). W & b are adjusted to get down the slope in the right direction.

Note:

Backpropagation involves taking the loss function’s error rate (e.g. MSE) between true values and computed values of a forward propagation and iteratively feeding it backward through the neural network layers to adjusts the weights and biases until the error rate reaches a minimum so that a NN can use randomly allocated weights and biases to produce the correct output.

After each forward pass, the backward pass adjusts weights and biases to minimize the loss function C. This is done by computing the gradient of C with respect to each weight which tells you how much the parameter x needs to change to minimize C (see gradient) and whether to increase (negative gradient) or decrease (positive gradient) the weights.

Image for post


The DL Training Process

Activation Functions

https://towardsdatascience.com/activation-functions-neural-networks-1cbd9f8d91d6

REVIEW THE GWU DL / NLP COURSE FOR MORE CORE BASIC INSIGHTS – VERY HELPFUL REFRESHER LECTURE NOTES!


Transfer Functions to determine the output of a node, map the resulting values to a range: ( [0, 1], [-1, 1], etc. depending on the function). Two types: linear and non-linear

Linear or Identity Activation Function

Fig: Linear Activation Function

f(x) = x, [ -inf, inf ]

Doesn’t help with complexity or various aspects of data fed to NN, but is used in output layers of regression models, autoencoders, special cases where no transformation is desired, simplified / baseline models -

making the model just a weighted sum of inputs.

Non-linear Activation Functions

Mostly used - nonlinearity helps the model to generalize / adapt to a variety of data and to differentiate between the output. Subtypes based on range and curves.

Main terms:

Derivative or Differential: Δy/Δx - change in y w.r.t. change in x (aka slope)

Monotonic f(x): either entirely non-increasing or non-decreasing.
f(x) = 2x + 3, f(x) = log(x), f(x) = e^x are increasing function;
f(x) = -x5, f(x) = e^-x are decreasing functions.

First derivative (which needs not be continuous) does not change sign.

Monotonically non-decreasing Monotonically non-increasing Non-monotonic

Significance of monotonic functions in ML

Convex f(x): line segment between any two points of the function lies above or on the graph between the two points. y=x^2, y=e^x. In simple terms, a convex function is U-shaped, and a concave function is upside-down U-shaped. A twice-differentiable function of a single variable is convex if and only if its second derivative is nonnegative on its entire domain.

Convex f(x) – optimality in optimization problems

Concave f(x) - optimality in maximization problems

Feed-forward ANN - wherein connections between nodes have no cycles / loops (different from RNNs). Was the first and simplest ANN where info moves forward: input nodes => hidden nodes => output nodes.


1. Sigmoid / Logistic Act. F(x)

Fig: Sigmoid Function

S-shaped, range (0, 1)=> especially good for models predicting probability. Used in feed-forward nets. Differentiable - we can find slope of curve at any two points. Softmax extends it to multiclass tasks. Due to the first drawback below, it is still used in output layers, though largely replaced in hidden layers by ReLU/Tanh.

Drawbacks:

2. Tanh / hyperbolic tangent Act. F(x)

f(z) = (e^(2z)-1)/(e^(2z)+1),

Tanh vs. Logistic Sigmoid

S-shaped, range (-1, 1). Unlike sigmoid, it is zero-centered: positive inputs mapped strongly positive, negative inputs mapped strongly negative, and the zero inputs mapped near zero.

Differentiable, monotonic while its derivative is not. Like sigmoid, saturates for large ∣x∣, causing very small [vanishing] gradients → training slows down in deep networks. Still useful in some RNNs (e.g., LSTMs/GRUs) and occasionally in hidden layers, but largely replaced by ReLU in deep feed-forward nets. Used mainly for binary classification in output layer of feed-forward nets.

3a. ReLU (Rectified Linear Unit) Act. F.

Fig: ReLU v/s Logistic Sigmoid

ReLU is half rectified (from bottom). f(x) = 0 if x < 0 and f(x) = x, if x >= 0

Range:[ 0, ∞]. Most used for CNNs or DL. Function and derivative are monotonic.

Advantages:

Disadvantages:

3b. Leaky ReLU

Fig : ReLU v/s Leaky ReLU

Attempt to solve the dying ReLU problem. Leak increases range. Usually, a= ~0.01. If it is not 0.01, f(x) is called randomized ReLU.

Range: [-inf, inf], both L. and R. ReLU & their derivatives are monotonic.

Advantage over ReLU:

Drawback:

3c. Softplus (SoftRELU)

A close-up of a computer screen Description automatically generated

A graph with a line Description automatically generated

Range (0,∞).

Approximation to ReLU:

Advantages over ReLU:

Disadvantages:

Use cases:

4. Softmax

Returns probability distribution for all classes: ratio of exponential of input parameter / sum of exponential parameters of all inputs. Multiclass unilabel classification. Multilabel uses multiple logistic regressions.

def softmax(scores):

return np.exp(scores)/sum(np.exp(scores)) # axis=0

or

5. Maxout

An activation function that outputs the maximum value from a set of linear transformations. Given multiple affine transformations zi=xWi+bi​, the output is: y=maxi(zi). Provides a piecewise linear approximation to arbitrary convex functions. Originally proposed for dropout networks; used in some GAN architectures. Benefits:

Other activation f(x)

Why use derivatives (differentiation) in ML & DL?

When updating the curve, to know in which direction and how much to change / update the curve depending upon the slope.

A table of equations Description automatically generated

Fig: Activation Function Cheetsheet

Fig: Derivative of Activation Functions

NORMALIZATION

Normalization keeps neural networks numerically stable, trainable at scale, and often better at generalizing. Core goals:

  1. Stabilize training

    • Prevent exploding/vanishing activations.

    • Keep activations in a “healthy” range (not too big, not too small).

  2. Improve gradient flow

    • Smoother loss landscape → makes backpropagation more effective.

    • Reduces internal covariate shift (shifts in activation distributions as training progresses).

  3. Speed up convergence

    • Networks train faster with fewer epochs.

    • Optimizers (like SGD, Adam) behave more reliably.

  4. Improve generalization

    • Acts as a form of regularization (e.g., BatchNorm adds noise through batch statistics).

    • Helps models avoid overfitting.

  5. Enable very deep architectures

    • Without normalization, extremely deep models (ResNets, Transformers, GANs) would be nearly impossible to train effectively.

Batch Normalization (BN)

Input shape: [B, C, H, W]

Normalize across: B, H, W (per channel C)

-------------------------------------------------

For each channel:

Mean/Var computed over all batch samples + spatial positions

Layer Normalization (LN)

Input shape: [B, C, H, W]

Normalize across: C, H, W (per sample B)

-------------------------------------------------

For each individual sample:

Mean/Var computed across all features in the layer

RMSNorm (Root Mean Square Layer Normalization) - simplified variant of Layer Normalization that normalizes using only the root mean square (RMS) of activations, without centering (no mean subtraction).

Instance Normalization (IN)

Input shape: [B, C, H, W]

Normalize across: H, W (per channel C, per sample B)

-------------------------------------------------

For each channel of each sample:

Mean/Var computed over spatial positions only

In Instance Normalization (IN), the term “instance” refers to a single sample in the batch (e.g., one image), normalized independently from all the others.

Let’s unpack it:

Intuition in style transfer:
Each image (instance) may have very different contrast/lighting. Normalizing each instance separately removes this contrast variation, making it easier to apply a consistent “style” to the image, regardless of the original lighting.

Group Normalization (GN)

Input shape: [B, C, H, W]

Normalize across: Subset of channels (C/G) + H, W (per group, per sample B)

-------------------------------------------------

Channels are divided into G groups:

Mean/Var computed within each group

PixelNorm (Pixelwise Normalization)

Key Difference Summary:

Other normalization techniques

Spectral Normalization

Weight Normalization

w=g / ∥v∥v

where g is a learnable scalar (magnitude) and v is a learnable vector (direction).

Key Difference:

Example - How Batch Normalization works:

Process and add to this primer: