Skip to content

Activation function

Also called: activation functions

Published:

Why does a network need one?

Google's glossary says an activation function enables neural networks to learn non-linear, complex relationships between features and the label [3]. Adding hidden layers on its own is not enough, because linear operations stacked on linear operations are still linear [1]. The activation function applies a non-linear transform to each node's output before it feeds the next layer, and as those transforms stack up each layer can learn a higher-level function of the raw inputs [1].

Which ones are most common?

Sigmoid, 1 / (1 + e^-x), squeezes values into the range 0 to 1, while tanh outputs between -1 and 1 [1]. ReLU returns 0 for negative inputs and the input itself otherwise: max(0, x) [1]. Google notes that ReLU is less prone to the vanishing gradient problem than sigmoid or tanh and is much cheaper to compute [1].

To see the difference, suppose a ReLU neuron's weighted sum comes out at -2: it outputs 0. At 3, it outputs 3. Pass the same two sums through a sigmoid and both land somewhere between 0 and 1.

What changes at the output layer?

In scikit-learn's multi-layer perceptron the hidden layers default to tanh [2]. The output depends on the task: binary classification uses the logistic function to produce a value between zero and one, multiclass classification uses softmax, and regression leaves the output as it is [2].

Frequently asked questions

Which activation function should I start with?

Google suggests starting with ReLU for hidden layers: it is cheap to compute and less prone to vanishing gradients.

Is sigmoid the same as the logistic function?

In machine learning, sigmoid usually refers to 1 / (1 + e^-x), which is the logistic function.

Sources

  1. Neural networks: Activation functions — Google for Developers
  2. Neural network models (supervised) — scikit-learn
  3. Machine Learning Glossary: ML Fundamentals — Google for Developers