Activation Functions
In the previous lessons, we have seen how the activation functions work. Letβs recap what we learned and then introduce some new activation functions.
This Lesson Will Cover
- β‘ Activation Functions Overview
- πͺ Step Function
- π₯ ReLU Function
- π Sigmoid Function
- π― Softmax Function
- π Function Comparisons
What are Activation Functions?
A neural network layer with parameters and will operate on an input vector as follows:
Where an activation function is then applied element-wise to each component of :
This activation function is responsible for introducing non-linearity into the network, allowing it to learn and model complex patterns that a simple linear transformation cannot capture.
The Step Function
The step function is the first activation function we talked about in this section.
Itβs probably the simplest activation function:
- It outputs 1 if the input is positive (or zero)
- It outputs 0 if the input is negative
While rarely used in modern networks (since e.g. (a) itβs non-differentiable, and (b) the sigmoid function provides a more informative representation anyway), it was historically important in early neural network development.
Formula
Example: Applying the Step Function
For an input :
For a negative input :
The ReLU Function (Rectified Linear Unit)
Weβve also already seen the ReLU function in action.
- It outputs the input directly if the input is positive
- It outputs 0 otherwise
Itβs simple, computationally efficient, and commonly used in hidden layers.
Formula
Example: Applying the ReLU Function
For an input :
For a negative input :
The Sigmoid Function
The sigmoid function maps any real-valued input to a value between 0 and 1.
Unlike the step function, the sigmoid function provides a smooth, continuous output that can be interpreted as a probability, and itβs differentiable - making it suitable for gradient-based learning.
Formula
Example: Applying the Sigmoid Function
Letβs apply the sigmoid function to a single input value:
z = 2.0
Substitute into the formula:
First, compute :
Then compute :
The output of the sigmoid function for is:
This result can be interpreted as an 88.08% probability for the positive class.
The Softmax Function
The softmax function is the multi-class generalization of the sigmoid function.
It converts a vector of raw scores into a probability distribution across multiple classes.
In fact, for a binary classification problem (n = 2), the softmax function reduces to the sigmoid function, making the sigmoid function a special case of softmax.
For a binary case with input , the softmax probabilities would be:
This mathematical relationship shows why the sigmoid function is often considered the binary version of softmax, and why we can use either function for binary classification tasks.
Formula
Where:
- : The -th element of the input vector,
- : Total number of classes.
Example: Applying the Softmax Function
Letβs apply the softmax function to a 3-dimensional input vector :
Step 1: Compute the Exponentials
Calculate the exponentials of each element:
Step 2: Compute the Sum of Exponentials
Sum all the exponentials:
Step 3: Compute the Softmax Outputs
Divide each exponential by the sum:
The final probabilities are:
These outputs represent the probabilities for three classes. For example:
- The probability of the first class is 27.52%.
- The probability of the second class is 11.19%.
- The probability of the third class is 61.29%.
Comparison: ReLU vs Sigmoid vs Softmax
ReLU
- Where to Use: Hidden layers in any type of neural network.
- Why: It introduces non-linearity without constraining the output range, allowing the network to learn complex functions.
- Example Use Case: Learning features in deep layers of a network for image or text data.
Sigmoid
- Where to Use: Output layer for binary classification problems.
- Why: It squashes values between 0 and 1, making it ideal for binary probability predictions.
- Example Use Case: Spam detection, sentiment analysis (positive/negative).
Softmax
- Where to Use: Output layer for multi-class classification problems.
- Why: It converts raw scores into probabilities that sum to 1, making it ideal for interpreting outputs as class probabilities.
- Example Use Case: Predicting the type of object in an image (e.g., cat, dog, bird).
Key Differences
| Feature | ReLU | Sigmoid | Softmax |
|---|---|---|---|
| Range of Outputs | for positive inputs; otherwise | ||
| Primary Application | Non-linear transformations in hidden layers | Binary classification output layer | Multi-class output layers |
| Output Normalization | No normalization | No normalization | Outputs sum to 1 |
Conclusion
Congratulations! Weβve made it through the basics of neural networks. Understanding this section is an important foundation for grasping how AI works at a technical level.
Key Takeaways
β‘ Activation functions introduce non-linearity into neural networks, allowing them to learn complex patterns.
π The Step function was historically important but is rarely used in modern networks.
π ReLU is computationally efficient and commonly used in hidden layers.
π― Sigmoid maps inputs to values between 0 and 1, making it useful for binary classification.
π Softmax generalizes sigmoid for multi-class problems by outputting a probability distribution.
π Each activation function has specific use cases:
- β‘ ReLU: Hidden layers in any neural network
- π― Sigmoid: Binary classification output layers
- π Softmax: Multi-class classification output layers
Next: Famous Nerual Networks
This leads us perfectly into the next section, where we get to talk about a few of the most famous neural networks that have paved the way to modern AI.
Comments (0)
No comments yet.