Why Deep Representations? (C1W4L04)

Deep networks work because early layers learn simple features like edges, middle layers combine them into parts like eyes, and later layers recognize whole objects. A circuit-theory argument shows some functions need exponential units in shallow networks but only logarithmic depth in deep ones.
Chapters
We've all been hearing that deep neural networks work really well for a lot of problems. It's not just that they need to be big neural networks. It's that specifically they need to be deep or to have a lot of hidden layers. So why is that? Let's go for a couple examples and try to gain some intuition for why deep networks might work well. So first, what is a deep network computing? If you're building a system for face recognition or face detection, you here's what a deep neural network could be doing. Um, perhaps you input a picture of a face. Then the first layer of the neural network you can think of as maybe being a feature detector or an edge detector. In this example, um, I'm plotting what a neural network with maybe 20 hidden units might be trying to compute on this Image with the 20 hidden units visualized by these little square boxes. So, for example, this little visualization represents a hidden unit that's trying to figure out if you know, where the edges of that orientation in the image. And maybe this hidden unit might be trying to figure out where are the horizontal edges in this image. And when we talk about convolutional networks in a later course, this particular visualization will make a bit more sense. But informally, you can think of the first layer of the neural network as looking at the picture and trying to figure out, you know, where are the edges in this picture. Now that it's figured out where the edges in this picture, by grouping together pixels to form edges, it can then take the detected edges and group edges together to form parts of faces. So, for example, you might have a little neuron trying to see if it's finding an eye or a different neuron trying to find that part of the nose. And so by putting together lots of edges, it can start to detect different parts of faces. And then finally, by putting together different parts of faces, like an eye or a nose or an ear or a chin, it can then try to recognize or detect different types of faces. So intuitively, you can think of the earlier layers of a neural network as detecting simpler functions like edges, and then composing them together in, in the later layers of a neural network so that it can learn more and more complex functions. These visualizations will make more sense when we talk about convolutional nets. And one technical detail of this visualization, the edge detectors are looking in relatively small areas of an image, maybe very small regions like that. And then the facial detectors, you can look at maybe much larger areas of the image. But the main intuition I want you to take away from this is just focus, finding simpler things like edges and then building them up, composing them together to detect more complex things like an iron, those and then composing those together to find even more complex things. And this type of simple to complex hierarchical representation or compositional representation applies in other types of data than images and face recognition as well. For example, if you're trying to build a speech recognition system, it's harder to visualize speech, but if you input an audio clip, then maybe the first level of a neural network might learn to detect, you know, low level audio waveform features such as is this tone going up, is this going down, is it white noise or sibilant sound, like, right? And what is the pitch? But it can detect low level waveform features like that. And then by composing low level waveforms, maybe you'll learn to detect basic units of sound. In linguistics, they're called phonemes. But for example, in the word cat, the K is a phoneme, the A is a phoneme, the T is another phoneme. It learns to find maybe the basic units of sound and then composing that together, maybe you learn to recognize words in the audio and then maybe compose those together in order to recognize entire, you know, phrases or sentences. So deep neural network with multiple hidden layers might be able to have the earlier layers learn these lower level simpler features and then have the later deeper layers then put together the simpler things that's detected in order to detect more complex things like recognize specific words or even phrases or sentences that you're uttering in order to carry out speech recognition. And what we see is that whereas the earlier layers are computing what seems like relatively simple functions of the input, such as where the edges, by the time you get deep in the network, you can actually do, you know, surprisingly complex things such as detect faces or detect words or phrases or sentences. Some people like to make an analogy between deep neural networks and the human brain, where we believe, or neuroscientists believe, that the human brain also starts off detecting, detecting simple things like edges in what your eyes see, and then builds those up to detect more complex things like the faces that you see. I think analogies between deep learning and the human brain are sometimes a little bit dangerous. But you know, there is a lot of truth to this being how we think the human brain works and that the human brain probably detects simple things like edges first and then puts them together to form more and more complex objects. And so that has served as a loose form of inspiration for some deep learning as well. We'll Say a bit more about the human brain or about the biological brain in a later video this week. The other piece of intuition about why deep networks seem to work well is the following. So this result comes from circuit theory, which pertains to thinking about what types of functions you can compute with different and gates and. Or gates and not gates, basically logic gates. So informally, there are functions you compute with a relatively small but deep neural network. And by small I mean the number of hidden units is relatively small, but that if you try to compute the same function with a shallow network, so if you aren't allowed enough hidden layers, then you might require exponentially more hidden units to compute. So let me just give you one example and illustrate this a bit informally. But let's say you're trying to compute the exclusive or, or the parity of all your input features. You're trying to compute x1xor, x2xor x3xor up to xn if you have N or nx features. So if you build an XOR tree like this, right? So first computer, the XOR of X1 and X2, then take X3 and X4 and compute their XOR. And technically, if you're just using and, or, and not gate, you might need a couple layers to compute the XOR function, rather than just one layer. But with a relatively small circuit, you can compute the xor, right? And so on. And then you can, you know, build really an XOR tree like so, until eventually you have a circuit here that outputs, you know, the. Well, let's call this Y that outputs Y hat equals Y the exclusive or the parity of all of these input bits. So to compute the xor, the depth of the network will be on the order of log N, right? Of this type of XOR tree. So the number of nodes and the number of circles, circuit components, or the number of gates in this network is not that large. You don't need that many gates in order to compute the exclusive or. But now if you're not allowed to use a neural network with multiple hidden layers with in this case, order log n hidden layers, if you're forced to compute this function with just one hidden layer, right? So you have all these things going into, you know, set of hidden units, and then these things then outputs Y. Then in order to compute the parity of X, to compute this XOR function, this hidden layer will need to be exponentially large because essentially you need to exhaustively enumerate all two to the n possible configurations, or on the order of 2 to the N possible configurations of the input bits that result in the exclusive or being either 1 or 0. So you end up needing a hidden layer that is exponentially large in the number of bits. I think technically you could do this with two to the n minus one hidden units, right? But that's the order two to the n, so it's gonna be exponentially large in the number of bits. So I hope this gives a sense that there are mathematical functions that are much easier to compute with deep networks than with shallow networks. I have to admit I personally found the result from circuit theory less useful for gaining intuitions. But this is one of the results that people often cite when, just when explaining the value of having very deep representations. Now, in addition to these reasons for preferring deep neural networks, the. To be perfectly honest, I think the other reason the term, term deep learning has taken off is just branding. Right? These things used to be called neural networks with a lot of hidden layers. But the phrase deep learning, you know, it's just a great brand, it just is so deep. Right? So I think that once that term called on that really neural networks rebranded or neural networks with many hidden layers rebranded help to capture the popular imagination as well. Well, but regardless of the pr, branding, deep networks do work well. Sometimes people go overboard and insist on using tons of hidden layers. But when I'm starting out with a new problem, I'll often really start out with even logistic regression. Then try something with one or two hidden layers and use that as a hyper parameter. Um, use that as a parameter or hyper parameter that you tune in order to try to find the right depth for your neural network. But, but over the last several years, there has been a trend toward people finding that for some applications, very, very deep neural networks, you know, maybe many dozens of layers sometimes can sometimes be the best model for a problem. So that's it for the intuitions for why deep learning seems to work well. Um, let's now take a look at the mechanics of how to implement not just forward propagation, but also back propagation.










