Activation Function

Home Glossary Item Activation Function
« Back to Glossary Index

An activation function is a mathematical operation applied to the output of a neuron in a neural network that determines whether and to what extent that signal should be passed forward to subsequent layers. By introducing non-linearity into the network, it enables the model to learn and represent complex, non-linear relationships within data that would otherwise be impossible to capture using only linear transformations.

How it works

In a standard neural network layer, each neuron receives inputs from the previous layer, multiplies them by corresponding weights, and adds a bias term. This process results in a weighted sum, which serves as the raw input to the activation function. The activation function then transforms this scalar value into a new output value. This transformation is the critical step that decides whether the neuron is “activated” or not, effectively influencing whether the signal progresses through the network. The function can either escalate the input signal, dampen it, or completely suppress it, depending on the specific mathematical nature of the function chosen.

The primary purpose of this transformation is to introduce non-linearity. Without an activation function, a neural network, regardless of how many layers it has, would behave as a single linear regression model. This is because the composition of linear functions is itself a linear function. By applying a non-linear activation function, the network can approximate complex, non-linear patterns found in real-world data. This allows the model to create useful hierarchies of learned features, where lower layers might detect simple edges or patterns, and deeper layers combine these into more abstract concepts.

Activation functions also play a vital role in the training process, specifically during backpropagation. When the network makes a prediction, the error is calculated and propagated backward through the network to adjust the weights. The activation function determines how this gradient flows. For instance, some functions produce gradients that are easy to compute and propagate, while others might cause the gradient to shrink exponentially as it moves backward through many layers, a phenomenon known as the vanishing gradient problem. The choice of activation function directly impacts the efficiency and feasibility of the optimization algorithm used to minimize the network’s loss.

Common activation functions include the sigmoid, hyperbolic tangent (tanh), and Rectified Linear Unit (ReLU). The sigmoid function squashes input values into a range between zero and one, making it useful for binary classification outputs but prone to vanishing gradients for deep networks. The tanh function squashes inputs into a range between negative one and one, centering the data around zero, which can help with convergence but also suffers from vanishing gradients. ReLU, defined as the maximum of zero and the input, is widely used because it is computationally efficient and helps mitigate the vanishing gradient problem for positive inputs, although it can “die” if inputs are consistently negative.

Where it is used

Activation functions are fundamental components in virtually all types of artificial neural networks, including feed-forward networks, convolutional neural networks, and recurrent neural networks. They are used in any context where the relationship between inputs and outputs is not strictly linear. This includes a wide variety of tasks such as image recognition, natural language processing, speech recognition, and time series forecasting.

In the output layer of a neural network, the choice of activation function is often dictated by the type of prediction task. For binary classification problems, where the goal is to predict one of two classes, a sigmoid function is typically used to output a probability between zero and one. For multi-class classification problems, where an input must be assigned to one of many mutually exclusive categories, a softmax function is commonly employed to produce a probability distribution over the classes. In regression tasks, where the output is a continuous value, a linear activation function might be used in the output layer to allow the network to predict any real number.

Within the hidden layers of a network, activation functions are used to enable the network to learn hierarchical representations of data. For example, in a convolutional neural network used for image processing, ReLU is frequently used in hidden layers to introduce non-linearity after convolution operations, allowing the network to detect complex features like textures, shapes, and objects at various levels of abstraction. In recurrent neural networks used for sequence modeling, activation functions like tanh or ReLU are applied at each time step to process sequential data, helping the network maintain context over time.

Limitations and trade-offs

One significant trade-off in choosing an activation function is the balance between non-linearity and computational efficiency. Functions like sigmoid and tanh involve exponential calculations, which are more computationally expensive than the simple thresholding operation of ReLU. Additionally, sigmoid and tanh are prone to the vanishing gradient problem, where gradients become extremely small as they are backpropagated through many layers, causing the weights in earlier layers to update very slowly or not at all. This can stall learning in deep networks. Conversely, ReLU can suffer from the “dying ReLU” problem, where neurons output zero for all inputs and stop learning entirely if their weighted sum is consistently negative.

Another consideration is the range of the output. Some activation functions, like sigmoid, restrict outputs to a specific range, which can be beneficial for probability estimation but may limit the network’s ability to model data with large variance. Others, like ReLU, have an unbounded upper range, which can lead to exploding gradients if not properly managed. The choice of activation function also affects the sparsity of the network’s activations. ReLU produces sparse activations because it outputs zero for negative inputs, which can be beneficial for efficiency and feature selection, while sigmoid and tanh produce dense activations, which might be preferable in certain contexts but require more memory and computation.

Related terms

  • Neuron – The activation function is applied to the output of a neuron to determine its signal.
  • Neural Network – Activation functions are essential components that enable neural networks to learn non-linear patterns.
  • Rectified Linear Unit – A specific type of activation function that outputs the input directly if positive, otherwise zero.
  • Back Propagation – The algorithm used to train neural networks, which relies on the derivatives of activation functions to update weights.
  • Vanishing/Exploding Gradients – A common issue in deep networks where activation functions can cause gradients to shrink or grow exponentially during backpropagation.
  • Feed-Forward (Neural) Networks – A class of neural networks where activation functions are applied in a forward direction from input to output.
« Back to Glossary Index
Eugene Serbin

Systems Analyst and AI Engineer, Semalt

Eugene Serbin is a systems analyst and AI engineer at Semalt. He graduated with honours from Kharkiv National University of Radio Electronics in 2005, specialising in intelligent decision-making systems, and holds a second degree from the same university in economic cybernetics. He writes and edits the AI research summaries, applied machine learning explainers and the glossary on ai-magazine.com.