Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.
Master the mathematical non-linearities that allow neural networks to bend space: Sigmoid, Tanh, ReLU, Leaky ReLU, and Softmax.
| Symbol / Term | Meaning | Beginner Interpretation |
|---|---|---|
| Raw output logit for class i | Unbounded score | |
| Number of classes | Total target categories |
Applying Softmax to logits [2.0, 1.0, 0.1].
Result: Probabilities: 65.8%, 24.2%, 9.9% (Sum = 100%)
Use ReLU (or Leaky ReLU / GELU) in all hidden layers to ensure healthy gradient flow.
Use Sigmoid on a single output neuron for binary classification (outputs probability between 0 and 1).
Use Softmax across C output neurons for multi-class classification (outputs probability distribution summing to 1).
Problem: Deep 50-layer networks suffering from vanishing gradient failure.
Solution: ReLU activations enable training deep ResNet architectures without gradient attenuation.
Problem: Selecting the most likely next word out of a 50,000-token vocabulary.
Solution: Softmax temperature layer normalizes output token logits into next-word sampling probabilities.
Interactive activity component
Implement Sigmoid, ReLU, and Softmax and visualize their numerical outputs.
For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:
!pip install numpy1 import numpy as np
import numpy as np â NumPy for vector math
1 # Raw input logits from negative to positive 2 z = np.array([-3.0, -1.0, 0.0, 1.0, 3.0]) 3 4 # 1. Sigmoid Function: 1 / (1 + exp(-z)) 5 sigmoid = 1 / (1 + np.exp(-z)) 6 print("Sigmoid Outputs (0 to 1):\n", sigmoid.round(3)) 7 8 # 2. ReLU Function: max(0, z) 9 relu = np.maximum(0, z) 10 print("\nReLU Outputs (0 for negatives):\n", relu) 11 12 # 3. Softmax Function on 3-class logits [2.0, 1.0, 0.1]: 13 logits = np.array([2.0, 1.0, 0.1]) 14 exp_scores = np.exp(logits - np.max(logits)) # Subtract max for numerical stability 15 softmax_probs = exp_scores / np.sum(exp_scores) 16 print("\nSoftmax Class Probabilities:\n", softmax_probs.round(3)) 17 print("Softmax Sum Check:", round(np.sum(softmax_probs), 3))
# Raw input logits from negative to positive
Sample inputs
z = np.array([-3.0, -1.0, 0.0, 1.0, 3.0])
Range of test values
# 1. Sigmoid Function: 1 / (1 + exp(-z))
Sigmoid formula
sigmoid = 1 / (1 + np.exp(-z))
Compute sigmoid
print("Sigmoid Outputs (0 to 1):\n", sigmoid.round(3))
Print sigmoid
# 2. ReLU Function: max(0, z)
ReLU formula
relu = np.maximum(0, z)
Compute ReLU
print("\nReLU Outputs (0 for negatives):\n", relu)
Print ReLU
# 3. Softmax Function on 3-class logits [2.0, 1.0, 0.1]:
Softmax formula
logits = np.array([2.0, 1.0, 0.1])
Logit scores
exp_scores = np.exp(logits - np.max(logits)) # Subtract max for numerical stability
Exp step
softmax_probs = exp_scores / np.sum(exp_scores)
Normalize to 1.0
print("\nSoftmax Class Probabilities:\n", softmax_probs.round(3))
Print probs
print("Softmax Sum Check:", round(np.sum(softmax_probs), 3))
Verify sum is 1.0
Click "Copy for Colab", open Google Colab, paste into a single cell, and run.
1 # ========================================================= 2 # Comparing Activation Functions in NumPy 3 # Prepared for Google Colab (Run with Shift + Enter) 4 # ========================================================= 5 6 # Step 1: Install required packages 7 !pip install numpy 8 9 # Step 2: Import libraries 10 import numpy as np 11 12 # Step 3: Run Demonstration 13 # Raw input logits from negative to positive 14 z = np.array([-3.0, -1.0, 0.0, 1.0, 3.0]) 15 16 # 1. Sigmoid Function: 1 / (1 + exp(-z)) 17 sigmoid = 1 / (1 + np.exp(-z)) 18 print("Sigmoid Outputs (0 to 1):\n", sigmoid.round(3)) 19 20 # 2. ReLU Function: max(0, z) 21 relu = np.maximum(0, z) 22 print("\nReLU Outputs (0 for negatives):\n", relu) 23 24 # 3. Softmax Function on 3-class logits [2.0, 1.0, 0.1]: 25 logits = np.array([2.0, 1.0, 0.1]) 26 exp_scores = np.exp(logits - np.max(logits)) # Subtract max for numerical stability 27 softmax_probs = exp_scores / np.sum(exp_scores) 28 print("\nSoftmax Class Probabilities:\n", softmax_probs.round(3)) 29 print("Softmax Sum Check:", round(np.sum(softmax_probs), 3))
Compresses [-3, 3] smoothly into [0.047, 0.953].
Zeroes out negative values completely, keeping positives untouched.
Converts raw logits [2.0, 1.0, 0.1] into clean probabilities [0.658, 0.242, 0.099] summing to exactly 1.0.
Test vectors z = [-3, -1, 0, 1, 3] and logits = [2.0, 1.0, 0.1]
Sigmoid Outputs: [0.047 0.269 0.5 0.731 0.953] ReLU Outputs: [0. 0. 0. 1. 3.] Softmax Class Probabilities: [0.658 0.242 0.099] Softmax Sum Check: 1.0
Each activation serves a distinct mathematical role: ReLU for deep hidden feature extraction, Sigmoid for binary probability, and Softmax for multi-class probability.
CNN, MNIST dataset, backpropagation, loss functions, and optimization.
Test your understanding with these questions. Remember, this is for learning, not examination!