Why is bias used in NN?
A bias term adds a learnable scalar offset to a neuron's weighted sum before applying the non-linear activation function, playing the same role as the intercept in linear regression. Without bias, the pre-activation hyperplane w^T x = 0 must pass through the origin and the zero-input response stays fixed at phi(0) (such as 0.5 for sigmoid). Including bias lets every neuron shift its activation threshold freely, dramatically expanding representational flexibility.
Study Card: The Role of Bias in Neural Networks
Direct Answer
In an artificial neuron computing , the bias is an additive learnable offset applied prior to the activation function .
Without a bias ():
- The linear decision hyperplane is forced to pass through the origin .
- Whenever all input features are zero (), the neuron’s output is locked at —for example, for sigmoid or for ReLU/—regardless of what weights learn.
Adding turns the linear map into an affine transformation, allowing the activation threshold to translate away from the origin and enabling neurons to adjust their baseline firing propensity independently of input scaling.
Key Terms
- Bias (): Learnable scalar intercept per neuron (or per output channel in CNNs) shifting the pre-activation .
- Affine Transformation: A linear map plus a translation ().
- Activation Threshold: The hyperplane where activations like ReLU switch on or sigmoid crosses .
- Intercept Analogy: Directly mirrors in linear or logistic regression ().
Example
Try implementing a 2-input AND gate ( iff and , classifying as when ) with a single sigmoid neuron.
- Without bias (): To predict for and , we need and . That immediately forces for —so no weights can separate from and without a bias (and is stuck at ).
- With bias (): Setting gives at , at and (all ), and at ().
Code Implementation
import numpy as np
def sigmoid(z):
return 1.0 / (1.0 + np.exp(-z))
def neuron_output(inputs, weights, bias=0.0):
return sigmoid(np.dot(inputs, weights) + bias)
# Demonstrate 2-input AND gate with vs. without bias
inputs_set = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
weights = np.array([5.0, 5.0])
bias = -7.5
print("AND gate outputs (threshold 0.5):")
for x in inputs_set:
y_with_bias = neuron_output(x, weights, bias=bias)
y_no_bias = neuron_output(x, weights, bias=0.0)
print(f"x={x} -> with bias: {y_with_bias:.4f} (pred={int(y_with_bias > 0.5)}) | "
f"no bias: {y_no_bias:.4f} (pred={int(y_no_bias > 0.5)})")
Related Concepts
- Batch Normalization / Layer Normalization: Linear or convolutional layers immediately followed by BatchNorm commonly omit biases (
use_bias=False) because subtracting the batch mean cancels any constant bias shift, and BatchNorm’s own parameter already supplies the shift. - Weight Decay / Regularization: Biases are typically excluded from L1/L2 weight decay penalties because each bias controls only a single offset (carrying negligible overfitting variance), while penalizing biases can induce unnecessary underfitting.
- Augmented Trick: Folding bias into weights by appending a constant feature to simplifies notation (), though production libraries track biases separately so weight decay and initialization can treat them distinctly.
- Backpropagation for Bias: Since , the gradient w.r.t. bias is simply the upstream pre-activation error summed over the mini-batch.