Batched Forward Propagation
What You'll Learn
You'll discover how neural networks process multiple training examples at once using matrix operations, dramatically speeding up computation.
The Core Idea
Until now, we've thought about forward propagation for a single input sample—one vector flowing through the network layer by layer. But during training, we typically have hundreds or thousands of examples. Batched forward propagation means stacking multiple input samples together and processing them all simultaneously through the same matrix operations.
Instead of computing predictions one-by-one in a loop, we organize multiple inputs as rows in a matrix (called a batch). Each column represents a feature, and each row is a different training example.
How It Works
Recall that for a single sample, a layer computes:
z = W^T x + b
a = activation(z)
For a batch of m samples, we stack them into a matrix X where each row is one example. The computation becomes:
Z = X W + b
A = activation(Z)
Here, X has shape (m, n_features), W has shape (n_features, n_neurons), and the result Z has shape (m, n_neurons)—one row per sample, one column per neuron. The bias b broadcasts across all samples.
Why This Matters
Computational efficiency: Modern hardware (CPUs and especially GPUs) are optimized for matrix operations. Processing 100 examples as one matrix multiplication is much faster than 100 separate vector operations.
Memory layout: Batching also improves memory access patterns, reducing overhead.
Key Takeaway: Batched forward propagation processes multiple training examples simultaneously through matrix operations, enabling the computational efficiency that makes deep learning practical on real-world datasets.