Neural Networks Overview


Neural Networks Overview

Hope
Last time we talked about two-layer neural networks where the hidden layer learned features and the output layer did classification. Today we're going deeper—literally—by adding more hidden layers. And we'll focus on one very successful way to do that: convolutional neural networks, or CNNs.

Corey
So why are CNNs so special? There's definitely been a lot of hype around deep learning recently. What kicked it off?

Hope
A big moment was the ImageNet challenge in 2012. AlexNet, a deep CNN with about eight layers, crushed the competition. Before that, the best methods were getting over 20% error. AlexNet dropped that dramatically, and by 2015, the winner had over 100 layers. It really changed the field.

Corey
But weren't neural networks around for decades? What made CNNs finally take off?

Hope
You're right—the ideas weren't new. There was the neocognitron in 1980, and Yann LeCun used CNNs for digit recognition in 1989. What changed was computation—GPUs were perfect for the matrix operations—and we had way more labeled data from sources like Mechanical Turk.

Corey
Alright, so how do we even feed an image into a neural network? We have pixels—how do we turn that into our usual x1, x2, ...?

Hope
We can flatten the image into a vector. For a grayscale image, each pixel becomes a feature. But if we feed that into a fully connected layer, we lose all spatial structure: it treats pixel 1 and pixel 100 as completely independent.

Corey
And that's bad because we know that in images, nearby pixels are related. Like, a stop sign is made of pixels that are all together, not scattered across the picture.

Hope
Exactly. And we also want translation invariance—a stop sign in the corner should be recognized the same as one in the middle. A fully connected layer has to relearn the pattern at every location. So we need a layer that builds in these properties.

Corey
That's where convolution comes in, right? How does that work?

Hope
Let's start with a 1D example. Imagine a signal like a time series. A filter is just a small set of weights—say three numbers—that we slide across the signal, taking dot products. Each dot product gives us a new value. That's a convolution.

Corey
So we're reusing the same small filter across the whole signal. That already sounds more efficient. But what about the edges? If you start at the beginning, you can't center the filter on the first pixel.

Hope
Right, that's where padding comes in. We add zeros around the edges so the filter can be applied everywhere, and the output can stay the same size as the input. Then we often pass the result through an activation function like ReLU, which zeros out negative values.

Corey
And besides the filter weights, there's also a bias term, right? Like in logistic regression.

Hope
Yes. For each filter we have a set of weights and a bias. You compute the dot product plus the bias, then apply the activation. And the beautiful thing is how few parameters we need.

Corey
Let's compare that to a fully connected layer. Say I have 10 input pixels and I want 10 outputs. With a filter of size 3 plus bias, that's just 4 parameters. But if I used a fully connected layer, how many would I have?

Hope
For 10 inputs and 10 outputs, each output needs a weight for every input plus a bias, so 11 parameters per output, times 10 outputs, gives 110. That's a huge difference! Convolution forces weight sharing, which is great when the same pattern can appear anywhere.

Corey
Okay, that makes sense for 1D. But real images are 2D. How does convolution work there?

Hope
Pretty much the same, but now the filter is a 2D patch, like 3x3. We slide it over the image, multiplying corresponding pixel values and summing. For example, a filter with -1 on the border and +1 in the centre acts like a dot detector—it lights up when a pixel is surrounded by zeros.

Corey
So filters detect simple patterns like edges or dots. But in practice, we use many different filters, right? That gives us multiple output images.

Hope
Exactly. Each filter produces a channel, and stacking them gives a 3D tensor. Even grayscale images become 3D once we apply multiple filters—so depth appears both from color channels and from the filter bank.

Corey
And after convolution, we normally do some pooling. What's that about?

Hope
Max pooling looks at small regions and takes the maximum value. It tells you whether something was detected in that region, and it reduces the spatial size. You can also use stride to skip pixels—so instead of sliding one step at a time, you move three steps, which further downsamples the image. Importantly, pooling has no learnable parameters.

Corey
So a typical CNN stacks these: convolution + ReLU, then max pooling, then another convolution + ReLU, then pooling, and so on. Then at the end, we flatten and use a fully connected layer for classification.

Hope
Yes. The early layers detect simple patterns, deeper layers combine them into more complex features, and the final fully connected layer uses those features to make a prediction. It's all learned end-to-end.

Corey
And how do we learn all those filter weights? Is it still gradient descent and backpropagation?

Hope
Exactly the same principle. We define a loss, compute gradients, and update weights. The only difference is that because filters are shared across the image, the gradient for a weight involves summing over all positions. For example, with a 1D filter of size 3, the derivative of a pre-activation with respect to weight w3 is just the corresponding input pixel x3 at that position. So backpropagation handles it naturally, just with a bit more bookkeeping.

Corey
So we've gone from simple linear models to two-layer nets, and now to deep CNNs. It's a really powerful framework, especially for images.

Hope
Absolutely. That's all for today. Next time we'll build on these ideas. Enjoy the rest of your week!

Ask anything
We've read this whole study set, so questions about it get the best answers.