Neural Networks
Backpropagation
Machine Learning
Bias Adjustment
Deep Learning

How to update the bias in neural network backpropagation?

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Updating the Bias in Neural Network Backpropagation

Updating the bias in neural network backpropagation is a crucial step in optimizing a model’s accuracy and generalization. The backpropagation algorithm minimizes prediction error by iteratively adjusting weights and biases during training. This article explains how bias parameters are updated, with technical insights and examples for clarity.


Introduction to Backpropagation

Backpropagation is the core algorithm for training feedforward neural networks. It computes the gradient of the loss function with respect to the model’s parameters—weights and biases—allowing the network to learn from errors and improve through gradient-based updates.


The Role of Bias in Neural Networks

Each neuron in a neural network has an associated bias term that shifts the activation function, enabling the neuron to better fit complex patterns in data. The bias helps the model capture non-zero-centered relationships and improves learning, especially for non-linear functions.

zj=i=1nwjixi+bjz_j = \sum_{i=1}^{n} w_{ji}x_i + b_j

Here, zjz_j is the weighted input plus the bias bjb_j for neuron jj, wjiw_{ji} are the connection weights, and xix_i are the input features.


Gradient Descent and the Update Rule

Backpropagation uses gradient descent to update parameters. The derivative of the loss function LL with respect to each bias determines the adjustment magnitude. The update rule is:

bj=bjηLbjb_j = b_j - \eta \frac{\partial L}{\partial b_j}

Where:

  • bjb_j: bias for neuron jj
  • η\eta: learning rate
  • Lbj\frac{\partial L}{\partial b_j}: gradient of the loss with respect to the bias

Derivation: Bias Gradient in Backpropagation

Assume the loss function is the Mean Squared Error (MSE):

1. Output Layer Error

For an output neuron oko_k:

δk=Lzk=zk(12(ykak)2)=(ykak)σ(zk)\delta_k = \frac{\partial L}{\partial z_k} = \frac{\partial}{\partial z_k}\left(\frac{1}{2}(y_k - a_k)^2\right) = -(y_k - a_k)\sigma'(z_k)

Here:

  • yky_k: true label
  • aka_k: neuron activation
  • σ(zk)\sigma'(z_k): derivative of the activation function

2. Hidden Layer Error

For a hidden neuron hjh_j :

δj=Lzj=(kδkwkj)σ(zj)\delta_j = \frac{\partial L}{\partial z_j} = \left( \sum_{k} \delta_k w_{kj} \right) \sigma'(z_j)

The error propagates backward from the output through the weights.


3. Updating the Bias

Since the gradient of the loss with respect to bias equals the neuron’s error term:

Lbj=δj\frac{\partial L}{\partial b_j} = \delta_j

The bias update becomes:

bj=bjη,δjb_j = b_j - \eta , \delta_j


Example Calculation

Suppose:

  • η=0.01\eta = 0.01
  • δj=0.25\delta_j = 0.25
  • Initial bias b=0.1b = 0.1

Then:

b=0.10.01×0.25=0.0975b = 0.1 - 0.01 \times 0.25 = 0.0975


Implementing Bias Updates in Python

Here’s a simple Python example demonstrating bias updates during backpropagation:

python
1import numpy as np
2
3# Parameters
4learning_rate = 0.01
5bias = np.array([0.1])
6delta_j = np.array([0.25])  # gradient from backpropagation
7
8# Update rule
9bias -= learning_rate * delta_j
10
11print("Updated bias:", bias)

Output:

 
Updated bias: [0.0975]

Key Points Summary

AspectDescription
Role of BiasShifts the activation function, improving flexibility.
Gradient CalculationUses ∂L/∂b to determine adjustment direction and magnitude.
Update Rulebj=bjηLbjb_j = b_j - \eta \frac{\partial L}{\partial b_j}
Error PropagationOutput layer error is computed from loss; hidden layer error is backpropagated.
ImplementationSimple bias update via Python loop or vectorized NumPy operations.

Additional Considerations

  1. Learning Rate Tuning: A well-chosen learning rate ( \eta ) ensures smooth convergence. Too large, and training diverges; too small, and it stagnates.
  2. Regularization: L2 regularization slightly modifies the gradient, encouraging smaller weights and biases to prevent overfitting.
  3. Batch vs. Stochastic Updates: Batch gradient descent provides stable convergence; stochastic or mini-batch updates yield faster but noisier learning.

Final Thoughts

Understanding bias updates is fundamental to mastering backpropagation. Bias terms, though simple, play a pivotal role in ensuring that neural networks can learn flexible and accurate mappings from data. Fine-tuning how biases update—along with weights—can significantly enhance a model’s learning dynamics and generalization ability.


Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

All Rights Reserved.