Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.
Understand the limits of manual feature engineering and why deep hierarchical neural networks revolutionized artificial intelligence.
| Symbol / Term | Meaning | Beginner Interpretation |
|---|---|---|
| Activation vector at layer l | Outputs of the current layer | |
| Weight matrix | Synaptic connection strengths | |
| Non-linear activation function | Enables learning non-linear curves |
Multiplying 2 inputs [1, 2] by weight matrix [[0.5, 0.5]] with bias 0.1 and ReLU activation.
Result: Neuron fires activation 1.6
Raw high-dimensional inputs (e.g., 224x224 RGB image pixels) are fed into the input layer.
Early layers act as Gabor-like filters detecting localized edges, gradients, and frequencies.
Deep layers combine motifs into semantic parts (eyes, wheels, textures).
Final dense layer maps abstract representations to class probabilities via Softmax.
Problem: Recognizing pedestrians and cyclists in rain, fog, and nighttime shadows.
Solution: Deep neural networks learn robust visual invariants from millions of recorded driving hours.
Problem: Detecting microscopic metastatic tumor cells in gigapixel biopsy slides.
Solution: Deep networks scan millions of cell textures, outperforming human screening benchmarks.
Interactive activity component
Construct a simple multi-layer neural network in PyTorch and inspect layer dimensions.
For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:
!pip install torch1 import torch 2 import torch.nn as nn
import torch → Import PyTorch
import torch.nn as nn → Import neural network modules
1 # Define a 3-layer deep feedforward network 2 model = nn.Sequential( 3 nn.Linear(784, 128), # Layer 1: 784 pixels -> 128 low-level features 4 nn.ReLU(), # Non-linear activation 5 nn.Linear(128, 64), # Layer 2: 128 features -> 64 abstract motifs 6 nn.ReLU(), # Non-linear activation 7 nn.Linear(64, 10) # Layer 3: 64 motifs -> 10 digit classes 8 ) 9 10 dummy_image = torch.randn(1, 784) # Simulated 28x28 grayscale image 11 output_logits = model(dummy_image) 12 print("Input Tensor Shape:", dummy_image.shape) 13 print("Output Class Logits Shape:", output_logits.shape) 14 total_params = sum(p.numel() for p in model.parameters()) 15 print(f"Total Learnable Parameters: {total_params:,}")
# Define a 3-layer deep feedforward network
Architecture
model = nn.Sequential(
Sequential container
nn.Linear(784, 128), # Layer 1: 784 pixels -> 128 low-level features
First dense layer
nn.ReLU(), # Non-linear activation
Non-linearity
nn.Linear(128, 64), # Layer 2: 128 features -> 64 abstract motifs
Second dense layer
nn.ReLU(), # Non-linear activation
Non-linearity
nn.Linear(64, 10) # Layer 3: 64 motifs -> 10 digit classes
Output head
)
Close model
dummy_image = torch.randn(1, 784) # Simulated 28x28 grayscale image
Input tensor
output_logits = model(dummy_image)
Forward pass
print("Input Tensor Shape:", dummy_image.shape)
Print input size
print("Output Class Logits Shape:", output_logits.shape)
Print output size
total_params = sum(p.numel() for p in model.parameters())
Count parameters
print(f"Total Learnable Parameters: {total_params:,}")
Display weight count
Click "Copy for Colab", open Google Colab, paste into a single cell, and run.
1 # ========================================================= 2 # Visualizing Deep Feature Hierarchy with PyTorch 3 # Prepared for Google Colab (Run with Shift + Enter) 4 # ========================================================= 5 6 # Step 1: Install required packages 7 !pip install torch 8 9 # Step 2: Import libraries 10 import torch 11 import torch.nn as nn 12 13 # Step 3: Run Demonstration 14 # Define a 3-layer deep feedforward network 15 model = nn.Sequential( 16 nn.Linear(784, 128), # Layer 1: 784 pixels -> 128 low-level features 17 nn.ReLU(), # Non-linear activation 18 nn.Linear(128, 64), # Layer 2: 128 features -> 64 abstract motifs 19 nn.ReLU(), # Non-linear activation 20 nn.Linear(64, 10) # Layer 3: 64 motifs -> 10 digit classes 21 ) 22 23 dummy_image = torch.randn(1, 784) # Simulated 28x28 grayscale image 24 output_logits = model(dummy_image) 25 print("Input Tensor Shape:", dummy_image.shape) 26 print("Output Class Logits Shape:", output_logits.shape) 27 total_params = sum(p.numel() for p in model.parameters()) 28 print(f"Total Learnable Parameters: {total_params:,}")
784 raw pixel inputs are projected into 128 hidden features, then 64 abstract features, and finally 10 output classes.
The network has over 109,000 learnable weights to approximate complex non-linear functions.
Single image vector of 784 pixels
Input Tensor Shape: torch.Size([1, 784]) Output Class Logits Shape: torch.Size([1, 10]) Total Learnable Parameters: 109,386
In just 10 lines of code, PyTorch creates a parameter-rich non-linear model capable of mapping high-dimensional inputs to discrete categories.
CNN, MNIST dataset, backpropagation, loss functions, and optimization.
Test your understanding with these questions. Remember, this is for learning, not examination!