Activation Functions

What Are Activation Functions?

An activation function is a mathematical function used inside a neural network. It decides how a neuron passes information forward to the next layer.

01

Inputs — raw values enter the neuron

02

Weights — each input is multiplied by its weight

03

Weighted sum — weighted inputs are added together

04

Bias — a learned bias is added

05

Activation function — transforms the result

06

Neuron output — sent to the next layer

Activation functions help neural networks learn complex patterns from data.

Why Activation Functions Matter

Activation functions matter because they help neural networks learn non-linear relationships. Many real-world patterns are not simple straight-line relationships.

Complex Data Examples
  • Images contain shapes and textures
  • Speech contains changing sound patterns
  • Text depends on context
  • Medical data has feature interactions
  • User behavior can be unpredictable

What Happens Without Activation Functions?

Without activation functions, a neural network would behave more like a simple linear model, even if it had many layers.

Without Activation Functions

Many layers collapse into a mostly linear transformation.

Problem — the model struggles to learn complex patterns.

Example — image classification is difficult because visual patterns are not simple straight lines.

Neuron Calculation Review

A neuron receives inputs, multiplies them by weights, adds a bias, and then applies an activation function.

01

Inputs: 2, 4 — Weights: 3, 5 — Bias: 1

02

Weighted sum — 2×3 + 4×5 = 6 + 20 = 26

03

Add bias — 26 + 1 = 27

04

Activation function — transforms 27 into the neuron output

Activation Function Inputs and Outputs

An activation function receives a number and returns another number. Different activation functions transform values in different ways.

Example: Input -3

ReLU — returns 0

Sigmoid — returns a value close to 0

Tanh — returns a value close to -1

The same input can produce different outputs depending on the activation function.

Common Activation Functions

Common activation functions include ReLU, Sigmoid, Tanh, and Softmax. Each one has a different purpose.

Activation FunctionCommon Use
ReLUHidden layers
SigmoidBinary classification output
TanhSome hidden layers or sequence models
SoftmaxMulti-class classification output

ReLU

ReLU stands for Rectified Linear Unit. It is one of the most common activation functions in deep learning.

ReLU Rule

If the input is positive — keep it

If the input is negative — turn it into 0

Formula — ReLU(x) = max(0, x)

Examples — ReLU(5) = 5, ReLU(-3) = 0, ReLU(0) = 0

Why ReLU Is Useful

ReLU is useful because it is simple, efficient, and works well in many deep learning models.

ReLU Is Commonly Used In
  • Hidden layers
  • Deep neural networks
  • Convolutional neural networks
  • Image models
  • Feedforward networks

ReLU is often a strong default choice for hidden layers.

ReLU Example

ReLU turns negative values into 0 and keeps positive values unchanged.

Example

Input values — -4, -1, 0, 2, 6

After ReLU — 0, 0, 0, 2, 6

Negative values are turned off. Positive values pass forward.

ReLU Limitation

ReLU can have a problem called dying ReLU. This happens when a neuron keeps outputting 0 and stops learning useful patterns.

Dying ReLU

Cause — if a neuron's input is always negative, ReLU always returns 0

Problem — the neuron may become inactive

Possible fix — use variations such as Leaky ReLU

Sigmoid

Sigmoid is an activation function that squashes values between 0 and 1. This makes it useful for probability-like outputs.

Sigmoid Behavior

Large positive input — output close to 1

Input near 0 — output near 0.5

Large negative input — output close to 0

Common use — binary classification output layer

Why Sigmoid Is Useful

Sigmoid is useful when the model needs to output a probability for two possible classes.

Binary Classification Examples
  • Spam or Not Spam
  • Fraud or Not Fraud
  • Disease or No Disease
  • Pass or Fail

Example output — 0.87 means the model estimates an 87% chance of the positive class.

Sigmoid Example

A spam detection model may use sigmoid to produce a spam probability.

Example

Raw model output — 2.1

Sigmoid output — 0.89

Interpretation — the model estimates an 89% chance that the email is spam

If threshold = 0.50 — predict Spam

Sigmoid Limitation

Sigmoid can cause very small gradients when values are very high or very low. This can slow down learning in deep networks.

Vanishing Gradient Problem

When sigmoid output is close to 0 or 1, weight updates may become very small.

This is called — vanishing gradient problem

Result — training can become slow; sigmoid is less common in deep hidden layers

Tanh

Tanh stands for hyperbolic tangent. It squashes values between -1 and 1.

Tanh Output Range

Minimum — -1 | Maximum — 1 | Center — 0

Examples — Tanh(5) ≈ 1, Tanh(0) = 0, Tanh(-5) ≈ -1

Tanh is centered around 0.

Why Tanh Is Useful

Tanh can be useful because its outputs are centered around 0. It was often used in older neural network architectures.

Common Uses
  • Some hidden layers
  • Older recurrent neural networks
  • Sequence models

ReLU is more common for many modern hidden layers.

Tanh Example

Tanh keeps negative values negative and positive values positive, but compresses values into the range from -1 to 1.

Example

Input values — -3, 0, 3

After Tanh — close to -1, 0, close to 1

Negative inputs stay negative. Positive inputs stay positive. Large values are compressed.

Tanh Limitation

Like sigmoid, tanh can suffer from vanishing gradients when inputs are very large or very small.

Tanh Limitation

Large positive input — Tanh output gets close to 1

Large negative input — Tanh output gets close to -1

Problem — learning can slow down in these regions

Softmax

Softmax is an activation function used for multi-class classification. It turns raw output scores into probabilities.

Example

Raw scores — Cat: 4.0, Dog: 2.0, Bird: 1.0

After Softmax — Cat: 0.84, Dog: 0.11, Bird: 0.05

Prediction — Cat (highest probability)

The probabilities add up to 1.

Why Softmax Is Useful

Softmax is useful when the model must choose one class from multiple possible classes.

Multi-Class Examples
  • Cat, Dog, or Bird
  • Red, Blue, or Green
  • Low, Medium, or High
  • Positive, Neutral, or Negative

Softmax outputs probabilities that add up to 1. The class with the highest probability is usually chosen.

Softmax Example

In image classification, softmax can show the model's probability for each class.

Image Classification Output

Cat — 0.70

Dog — 0.20

Bird — 0.10

Total — 1.00 | Prediction — Cat (highest probability)

Softmax vs Sigmoid

Sigmoid and softmax are both used for probability-like outputs, but they are used for different tasks.

FunctionBest ForOutput
SigmoidBinary classificationOne probability-like score
SoftmaxMulti-class classificationProbabilities across classes

Activation Functions in Hidden Layers

Hidden layers usually use activation functions such as ReLU, Tanh, or sometimes Sigmoid. ReLU is the most common choice for many modern hidden layers.

Hidden Layer Purpose

Learn useful patterns from data.

Image model example — layers learn: edges, shapes, textures, object parts

Common hidden layer activation — ReLU

Activation Functions in Output Layers

The output layer activation depends on the task.

Output Layer Activations

Binary classification — use Sigmoid

Multi-class classification — use Softmax

Regression — often use Linear output

Examples — Spam detection → Sigmoid | Animal classification → Softmax | House price → Linear

Linear Activation

A linear activation means the output is not changed. This is often used for regression outputs.

Regression Example

Model output — 450000

Prediction — $450,000

Use case — predicting numerical values such as price, temperature, score, or delivery time

Choosing an Activation Function

The best activation function depends on the layer and the task.

SituationCommon Choice
Hidden layersReLU
Binary classification outputSigmoid
Multi-class classification outputSoftmax
Regression outputLinear
Some sequence modelsTanh

Activation Function Comparison

Comparison

ReLU — good for hidden layers and deep networks

Sigmoid — good for binary classification outputs

Tanh — outputs values from -1 to 1; useful in some hidden layers

Softmax — good for multi-class classification outputs

Linear — good for regression outputs

Activation Functions and Non-Linearity

Non-linearity is the main reason activation functions are needed. Many real-world relationships are too complex for a simple straight line.

Example

A student's exam score may depend on: study time, sleep, attendance, prior knowledge, and stress.

Not simply — more study time always means a perfect score.

Activation functions help models learn these complex interactions.

Activation Functions and Deep Learning

Deep learning depends on activation functions because each layer needs to learn useful transformations.

L1

Layer 1 — edges

L2

Layer 2 — shapes

L3

Layer 3 — object parts

L4

Layer 4 — full object

Activation functions help each layer add meaningful transformations.

Vanishing Gradients

A vanishing gradient happens when weight updates become very small during training. This can make learning slow.

Vanishing Gradients

Can happen with — Sigmoid, Tanh

Problem — earlier layers may learn very slowly

Reason ReLU is popular — it helps reduce this problem in many networks

Exploding Gradients

An exploding gradient happens when weight updates become too large, making training unstable.

Exploding Gradients

Weight updates become too large → training becomes unstable → loss may jump around or fail to improve.

Helpful tools — careful learning rate, normalization, good architecture choices

ReLU in Image Models

ReLU is commonly used in image models such as convolutional neural networks.

Why ReLU Helps Image Models
  • Simple calculation
  • Efficient training
  • Works well with hidden layers
  • Helps models learn visual patterns

CNN layers may use ReLU after detecting edges, shapes, or textures.

Sigmoid in Binary Classification

Sigmoid is often used when there are two possible classes.

Disease Prediction

Output — 0.92

Interpretation — the model estimates a 92% chance of disease present

If threshold = 0.50 — predict disease present

Thresholds affect whether the model predicts positive or negative.

Softmax in Multi-Class Classification

Softmax is used when there are multiple possible classes and one class should be selected.

Handwritten Digit Example

0 — 0.02 | 1 — 0.01 | 2 — 0.90 | 3 — 0.03

Other digits — remaining probability

Prediction — 2 (highest probability)

Softmax makes the output easier to interpret as class probabilities.

Activation Functions and Probabilities

Sigmoid and softmax are often used to create probability-like outputs. These outputs are useful, but they are not always perfectly calibrated.

Probability Outputs

Sigmoid — probability-like score for one positive class

Softmax — probability distribution across multiple classes

Important — a model saying 90% confidence does not always mean it is correct 90% of the time

Activation Functions and Model Output

The final activation function affects how the model output should be interpreted.

Interpreting Model Output

Sigmoid output — 0.83 means probability-like score for the positive class

Softmax output — class probabilities that add to 1

Linear output — a raw number such as price, temperature, or score

Common Mistakes

Common Mistakes
  • Thinking activation functions are optional in deep networks
  • Using sigmoid for every hidden layer without considering vanishing gradients
  • Using softmax for binary classification when sigmoid may be simpler
  • Using sigmoid for multi-class classification when softmax is needed
  • Forgetting that regression often uses linear output
  • Confusing activation functions with loss functions
  • Thinking ReLU outputs probabilities
  • Thinking softmax should be used like ReLU in hidden layers

Summary

Key Takeaways
  • Activation functions transform neuron outputs.
  • They help neural networks learn non-linear patterns.
  • Without activation functions, deep networks would behave more like linear models.
  • ReLU is commonly used in hidden layers.
  • Sigmoid outputs values between 0 and 1.
  • Sigmoid is often used for binary classification outputs.
  • Tanh outputs values between -1 and 1.
  • Softmax outputs probabilities across multiple classes.
  • Softmax is used for multi-class classification outputs.
  • The right activation function depends on the layer and task.

Practice Prompt

A neural network is being built for three tasks: predicting whether an email is spam, classifying an image as cat, dog, or bird, and predicting a house price.

Choose an output activation function for each task and explain why that activation function fits the problem.

Need Help?

Ask the AI if you need help understanding ReLU, Sigmoid, Tanh, Softmax, hidden layer activations, output layer activations, non-linearity, vanishing gradients, or how to choose the right activation function.