Why does Andrej Karpathy say neural networks are arranged in layers?

Andrej Karpathy says layers are mainly a computational trick that makes neural networks much more efficient. Instead of computing every neuron separately, you can evaluate all neurons in a layer in parallel with matrix multiplication. That is why fully connected layers are used: they let the same input be processed vectorially and much faster.

“In a neural network, the reason we arrange these into layers is because arranging them into layers allows us to perform the computation much more efficiently. So instead of having an amorphous blob of neurons, and every one of them has to be computed independently, having them in layers allows us to use vectorized operations. And so we can compute an entire set of neurons in a single hidden layer just at a single time as a matrix multiply, and that's why we arrange them in these layers where neurons inside a layer can be evaluated completely in parallel, and they all see the same input. So it's a computational trick to arrange them in layers.”
— Andrej Karpathy, CS231n Winter 2016 Lecture 4 · at 1:08:53
Andrej Karpathy: Andrej Karpathy on Backpropagation: Computational Graphs and Gradients

Key takeaways

  • Use layers to batch many neuron computations at once.
  • Matrix multiplies are the efficient core operation.
  • Layering is about computation, not just biology.

Context

In the same lecture, Karpathy is introducing the structure of fully connected neural networks and how they are computed efficiently. The quote above is taken word for word from the recording's transcript.

In the transcript

…that have weights. So here, the input layer does not count as a layer because these neurons are just single values; they don't actually do any computation. So we have two layers here that could have weights, so it's a two-layer net. And we call these layers fully connected layers. And so remember that I've shown you that a single neuron computes this little weighted sum and then passes a

In a neural network, the reason we arrange these into layers is because arranging them into layers allows us to perform the computation much more efficiently. So instead of having an amorphous blob of neurons, and every one of them has to be computed independently, having them in layers allows us to use vectorized operations. And so we can compute an entire set of neurons in a single hidden layer just at a single time as a matrix multiply, and that's why we arrange them in these layers where neurons inside a layer can be evaluated completely in parallel, and they all see the same input. So it's a computational trick to arrange them in layers.

demo of how these neural networks work. So this is a JavaScript demo that I'll show you in a bit, but basically this is an example of a two-layer neural network classifying, doing a binary classification task. So we have two classes, red and green, and so we have these points in two dimensions, and I'm drawing the decision boundaries by the neural network. And so what you can see…

Read the full transcript of CS231n Winter 2016 Lecture 4

Topics

What others said about neural networks

More questions about Andrej Karpathy

All Andrej Karpathy answers · All Andrej Karpathy recordings

How this answer was made: the quote is checked word for word against the transcript of the recording and confirmed as the speaker's own words; the summary above it was drafted with AI from that transcript and quality-checked. Methodology and corrections.

Search every transcript
Open the full search page →