Activation function
An activation function is a mathematical function.
It is part of layer-to-layer feedforward mechanisms of an artificial neural network (ANN).
- For a simple ANN,the feedforward algorithm
- For a Transformer, the Feed-Forward Network (FFN)
Formal definition
An activation function is any component-wise real-vector map
$$ \sigma:\mathbb{R}^n\to\mathbb{R}^n $$
so for any $\vec z = (z_1,z_2,\dots,z_n)$:
$$ \sigma(\vec z)=(\sigma(z_1),\sigma(z_2),\dots,\sigma(z_n)) $$
Importance
Without an activation function:
$$ \mathbf{W}_2\left(\mathbf{W}_1\vec x+\vec b_1\right)+\vec b_2 = \mathbf{W}\vec x+\vec b, \qquad \mathbf{W}=\mathbf{W}_2\mathbf{W}_1, \quad \vec b=\mathbf{W}_2\vec b_1+\vec b_2, $$
Hence, any number of layers of artificial neurons is strictly equivalent to 1 larger layer, a phenomenon known as depth collapse.
The activation function, which introduces non-linearity, enables the preservation of depth of an ANN.