Activation Functions: ReLU, Sigmoid, Softmax & Tanh

Deep Learning with Keras and TensorFlow 10 min min read Updated: Nov 16, 2026 Beginner
Activation Functions: ReLU, Sigmoid, Softmax & Tanh
Beginner Topic 1 of 9

Why Do We Need Activation Functions?

Without an activation function, a neural network is just a long chain of multiplications and additions. No matter how many layers you add, it can only learn straight-line relationships. Activation functions add a bend (non-linearity), so the network can learn curves and complex patterns, such as the shape of a face.

Simple example: A straight ruler can only draw straight lines. Activation functions turn it into a flexible wire that can follow any shape.

Common Activation Functions

FunctionOutput rangeUse it for
ReLU0 to infinityHidden layers (the default choice)
Leaky ReLUSmall negative to infinityHidden layers when ReLU neurons die
Sigmoid0 to 1Output of binary classification
Tanh-1 to 1Hidden layers in some RNNs
Softmax0 to 1, sum is 1Output for multi-class classification
Linear (none)Any numberOutput for regression

ReLU

ReLU stands for Rectified Linear Unit. The rule is very simple: if the number is negative, output 0, otherwise output the number itself. It is fast and works very well, so it is the default in most hidden layers.

python import numpy as np def relu(x): return np.maximum(0, x) print(relu(np.array([-3, -1, 0, 2, 5]))) # [0 0 0 2 5]

Sigmoid

Sigmoid squashes any number into the range between 0 and 1. It is perfect for answering yes or no questions, because the output can be read as a probability.

python def sigmoid(x): return 1 / (1 + np.exp(-x)) print(sigmoid(np.array([-5, 0, 5]))) # [0.0067 0.5 0.9933]

Softmax

Softmax turns a list of scores into probabilities that add up to 1. It is used in the last layer when there are more than two classes.

python def softmax(x): e = np.exp(x - np.max(x)) return e / e.sum() scores = np.array([2.0, 1.0, 0.1]) print(softmax(scores)) # [0.659 0.242 0.099] -> sums to 1
Result

The first class gets the highest probability (about 66 percent).

Using Activations in Keras

python import keras from keras import layers # As a string argument layers.Dense(64, activation="relu") # As a separate layer layers.Dense(64) layers.Activation("relu") # Other examples layers.Dense(1, activation="sigmoid") # binary output layers.Dense(10, activation="softmax") # 10-class output layers.Dense(1) # regression output (linear) layers.LeakyReLU(negative_slope=0.1) # leaky ReLU as a layer

Quick Rules

  • Hidden layers: start with ReLU
  • Binary classification output: sigmoid with 1 neuron
  • Multi-class classification output: softmax with one neuron per class
  • Regression output: no activation (linear)
Common mistake: Using softmax in hidden layers or forgetting the activation in the output layer. The output activation must match the problem type.

Conclusion

Activation functions give neural networks their power. Remember ReLU for hidden layers and match your output activation to the task.

Quick Summary: ReLU for hidden layers, sigmoid for binary output, softmax for multi-class output, and linear for regression.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators