Answers.Body: <p>People often place a batchnorm layer before ReLU. That effectively prevents the problem you have described. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-25T12:31:58.820Z
Answers.LastActivityDate: 2019-01-25T12:31:58.820Z
Answers.UserDisplayName: ssegvic
Answers.Body: <p><strong>Learning and Zero Derivatives</strong></p>
  
  <p>Artificial networks are designed so that even when the partial derivative of a single activation function is zero they can learn. They can also be designed to continue learning when the derivative of the loss<sup>1</sup> function is zero too. This resilience to a vanishing feedback signal amplitude, by design, determines some of how calculus results are employed in the learning algorithm, hardware acceleration circuitry, or both. By learning behavior is meant the behavior of the changes to the parameters of the network as learning occurs.</p>
  
  <p>For many of the activation functions used today, the derivative of the of the activation function is never the real expression 0, but there are such cases. These are examples of when the evaluation of the derivative of the activation function is effectively zero.</p>
  
  <ul>
  <li>All the time for a binary step activation function, which is why they are usually only used for the very last layer of a network to discretize the output.</li>
  <li>When the input of a ReLU activation function is negative, which is the case given in the question</li>
  <li>When the granularity of the IEEE representation of the number can no longer support the smallness of the absolute value of the number upon evaluation</li>
  <li>When the loss is zero</li>
  </ul>
  
  <p><strong>Nearing Zero</strong></p>
  
  <p>This last condition can easily occur if the result of the loss function output is so close to zero that the digital products of that number, during propagation, rounds to zero in the floating point hardware. Even if not zero, the number can be so small that learning slows to an untenable speed. The learning process either oscillates, in many cases chaotically, because of rounding phenomena or finds a static state and remains there. Again, this does not necessarily require a zero partial in the Jacobian.</p>
  
  <p><strong>A Familiar Analogy</strong></p>
  
  <p>The cognitive equivalent that helps intuition in understanding this but is not at all a great and across-the-board accurate analogy is the mental concept of doubt. The advantages of various directions of change or action to produce change is no longer clear. This is a rough analogy that some can connect to when considering what it means when the gradient is vanishing. When looking at gradient in historical context, where gradient is the slope of a surface in a location where gravity defines which direction is down, a vanishing gradient is a place where no direction seems to be down hill.</p>
  
  <p><strong>Flat in One Dimension by Design</strong></p>
  
  <p>In the question, where an inner layer<sup>2</sup> is a ReLU activation function, the evaluation of the partial derivative of the loss function with respect to the parameter being adjusted will always be zero if its input is negative. However, this is by design and is one of the reasons ReLU trains fast. When the signal is negative going into the layer at that particular cell, it is thrifty to ignore it. The other cells upstream are then altered through other paths around the deactivated cell with the zero partial. A neuroscientist might smile at the oversimplification, but this is like a missing synapse between two adjacent cells in the brain.</p>
  
  <blockquote>
    <p>In a setup like the above where the derivative is 0, is it true that a [network] won't learn anything?</p>
  </blockquote>
  
  <p>It is false. Learning will stop if all the derivatives in a layer are zero and no other device, such as curvature, momentum, regularization, and other devices controlled by hyper-parameters, is employed. Even so, zeros across the layer would only affect the adjustment of upstream layers, layers closer to the input. Downstream, convergence activity may continue in such a case.</p>
  
  <p>Zero and close to zero values (as well as near overflows) are kinds of saturation conditions, and these are studied carefully in artificial network research, but a single cell with a zero partial will not stop learning and may, in specific cases, ensure its completion and the adequacy of its result.</p>
  
  <p><strong>Some Calculus</strong></p>
  
  <p>In mathematical terms, if the Jacobian has a zero in one position, the others may remain active indicators of proper adjustment magnitude and direction for the individual parameters. If the Hessian is used or various types of momentum, regularization, or other techniques are employed, zeros across the Jacobian will probably not block upstream learning, which is part of the reason why they are used.</p>
  
  <p><strong>An Analogy for Momentum</strong></p>
  
  <p>The analogy can again be employed to clarify momentum as a principle, with the caveat that it is again an oversimplification. Beliefs have momentum, so when a belief exists and all other indications of direction for the next step is unsure, most will base their next step upon their beliefs.</p>
  
  <p>This is how all organisms with a brain tend to work and why mouse traps and spider webs can catch. Without viable feedback from which learning can occur, the organism will act based on the momentum in its DNA or networks of its brain. This is usually beneficial, but can lead to loss in specific cases.</p>
  
  <p>Gradients are not fool proof either. The problem of local minima can render pure gradient descent dysfunctional as well.</p>
  
  <p><strong>An Analogy for Curvature</strong></p>
  
  <p>Curvature (as when the Hessian is employed) requires a different analogy.</p>
  
  <p>If a smart, blind person is on a dry, flat surface, thirsty, and needing water, the gradient may be flat, they may feel with their foot or cane for some indication of curvature. If some down curving feature of the surface is found, that may guide the person to water in more cases than a random step.</p>
  
  <p>As hardware acceleration improves, the Hessian, which is to computationally heavy for CPU execution in most cases, may emerge as standard practice.</p>
  
  <p>Mathematically, this is simply moving from two terms of the Taylor series expansion in multivariate space to three terms. From a mechanics perspective, it is the inclusion of acceleration to velocity.</p>
  
  <hr>
  
  <p><strong>Footnotes</strong></p>
  
  <p>[1] Loss or any of these functions that drive behavior in AI systems: Error, disparity, value, benefit, optimality, and others of similar evaluative nature.</p>
  
  <p>[2] Inner layers in artificial networks are often called hidden layers, but that is not technically correct. Even though the encapsulation of a neural network may hide signals in inner layers from the programmer, it is a low level software design feature to do that, and a bad one. One can usually and definitely should be able to monitor those signals and produce statistics on them. They are not hidden in the mathematics, as in some kind of mathematical mystery, and the only difference between them and the output layer is that the output layer is intended to drive or influence something outside the network.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-24T14:42:08.207Z
Answers.LastActivityDate: 2019-01-28T17:13:29.753Z
Answers.LastEditDate: 2019-01-28T17:13:29.753Z
Answers.UserDisplayName: Douglas Daseeco
Answers.Body: <blockquote>
    <p>In a setup like the above where the derivat[iv]e is 0 is it true that an NN won´t learn anything?</p>
  </blockquote>
  
  <p>There are a couple of adjustments to gradients that <em>might</em> apply if you do this in a standard framework:</p>
  
  <ul>
  <li><p>Momentum may cause weights to continue changing if any recent ones were non-zero. This is typically implemented as a rolling mean of recent gradients.</p></li>
  <li><p>Weight decay (aka L2 weight regularisation) is often implemented as an additional gradient term and may adjust weights down even in the absence of signals from prediction errors.</p></li>
  </ul>
  
  <p>If either of these extensions to basic gradient descent are active, or anything similar, then it is possible for the neural network to move out of the stationary zone that you have created after a few steps and then continue learning.</p>
  
  <p>Otherwise, then yes it is correct that the neural networks weights would not change at all through gradient descent, and the NN would remain unchanged for any of your input values. Your careful initialisation of biases and weights will have created a system that is unable to learn from the given data. This is a known problem with ReLU activation, and can happen to some percentage of artificial neurons during training with normal start conditions. Other activation functions such as sigmoid have similar problems - although the gradient is never zero in many of these, it can be arbitrarily low, so it is possible for parameters to get into a state where learning is so slow that the NN, whilst technically learning <em>something</em> on each iteration, is effectively stuck. It is not always easy to tell the difference between these unwanted states of a NN and the goal of finding a useful minimum error.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-15T21:31:18.607Z
Answers.Text: @DuttaA I read an article about that topic too. According to the authors it is all about statistics. In order for you to find a local minimum you must find a point where all your N input variables are in a local minimum. If A of your input variables are in a local minimum and B are not (where A + B = N) then you found a saddle point. That's the reason why usually are way more saddle points than mínima.
Answers.UserDisplayName: Daniel Oliveira
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-24T08:20:05.443Z
Answers.Text: @DuttA: It means that you are close to stationary point. That could be a "good" mimimum, but could also be a bad local minimum, a maximum or a saddle point. I have read articles that claim that a lot of "unwanted" stationary 
  and close-to-stationary points that occur during NN training are saddle points - i.e. with upward slopes in many directions but downward slopes in others.
Answers.UserDisplayName: Neil Slater
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-24T07:59:21.400Z
Answers.LastActivityDate: 2019-01-24T08:21:49.527Z
Answers.LastEditDate: 2019-01-24T08:21:49.527Z
Answers.UserDisplayName: Neil Slater
Body: <p>Imagine that I have an artificial neural network with a single hidden layer and that I am using ReLU as my activating function.
  If by change I initialize my bias and my weights in such a form that:
  <span class="math-container">$$
  X * W + B &lt; 0
  $$</span>
  for every input <strong>x</strong> in <strong>X</strong> then the partial derivate of the Loss function with respect to W will always be 0! </p>
  
  <p>In a setup like the above where the derivate is 0 is it true that an NN won´t learn anything? </p>
  
  <p>If true (the NN won´t learn anything) can I also assume that once the gradient reaches the value 0 for a given weight, that weight won´t ever be updated?</p>
  
Tags: <neural-networks><deep-learning><gradient-descent>
Title: How can a neural network learn when the derivative of the activation function is 0?
UserDisplayName: Daniel Oliveira
ThreadText: # How can a neural network learn when the derivative of the activation function is 0?
  
  (Asked by: username_0 on 2019-01-24)
  
  Imagine that I have an artificial neural network with a single hidden layer and that I am using ReLU as my activating function.
  If by change I initialize my bias and my weights in such a form that:
  $$
  X \* W + B < 0
  $$
  for every input **x** in **X** then the partial derivate of the Loss function with respect to W will always be 0!
  
  In a setup like the above where the derivate is 0 is it true that an NN won´t learn anything?
  
  If true (the NN won´t learn anything) can I also assume that once the gradient reaches the value 0 for a given weight, that weight won´t ever be updated?
  
  **Tags:** neural-networks, deep-learning, gradient-descent
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_3 on 2019-01-24. Score: 3 | Accepted answer
  
  > In a setup like the above where the derivat[iv]e is 0 is it true that an NN won´t learn anything?
  
  There are a couple of adjustments to gradients that *might* apply if you do this in a standard framework:
  
  * Momentum may cause weights to continue changing if any recent ones were non-zero. This is typically implemented as a rolling mean of recent gradients.
  * Weight decay (aka L2 weight regularisation) is often implemented as an additional gradient term and may adjust weights down even in the absence of signals from prediction errors.
  
  If either of these extensions to basic gradient descent are active, or anything similar, then it is possible for the neural network to move out of the stationary zone that you have created after a few steps and then continue learning.
  
  Otherwise, then yes it is correct that the neural networks weights would not change at all through gradient descent, and the NN would remain unchanged for any of your input values. Your careful initialisation of biases and weights will have created a system that is unable to learn from the given data. This is a known problem with ReLU activation, and can happen to some percentage of artificial neurons during training with normal start conditions. Other activation functions such as sigmoid have similar problems - although the gradient is never zero in many of these, it can be arbitrarily low, so it is possible for parameters to get into a state where learning is so slow that the NN, whilst technically learning *something* on each iteration, is effectively stuck. It is not always easy to tell the difference between these unwanted states of a NN and the goal of finding a useful minimum error.
  
  > **Comments:**
  > **username_3**: @DuttA: It means that you are close to stationary point. That could be a "good" mimimum, but could also be a bad local minimum, a maximum or a saddle point. I have read articles that claim that a lot of "unwanted" stationary  and close-to-stationary points that occur during NN training are saddle points - i.e. with upward slopes in many directions but downward slopes in others.  
  > **username_0**: @DuttaA I read an article about that topic too. According to the authors it is all about statistics. In order for you to find a local minimum you must find a point where all your N input variables are in a local minimum. If A of your input variables are in a local minimum and B are not (where A + B = N) then you found a saddle point. That's the reason why usually are way more saddle points than mínima.  
  
  ---
  
  ### Answer by username_1 on 2019-01-25. Score: 1
  
  People often place a batchnorm layer before ReLU. That effectively prevents the problem you have described.
  
  
  ---
  
  ### Answer by username_2 on 2019-01-24. Score: 1
  
  **Learning and Zero Derivatives**
  
  Artificial networks are designed so that even when the partial derivative of a single activation function is zero they can learn. They can also be designed to continue learning when the derivative of the loss1 function is zero too. This resilience to a vanishing feedback signal amplitude, by design, determines some of how calculus results are employed in the learning algorithm, hardware acceleration circuitry, or both. By learning behavior is meant the behavior of the changes to the parameters of the network as learning occurs.
  
  For many of the activation functions used today, the derivative of the of the activation function is never the real expression 0, but there are such cases. These are examples of when the evaluation of the derivative of the activation function is effectively zero.
  
  * All the time for a binary step activation function, which is why they are usually only used for the very last layer of a network to discretize the output.
  * When the input of a ReLU activation function is negative, which is the case given in the question
  * When the granularity of the IEEE representation of the number can no longer support the smallness of the absolute value of the number upon evaluation
  * When the loss is zero
  
  **Nearing Zero**
  
  This last condition can easily occur if the result of the loss function output is so close to zero that the digital products of that number, during propagation, rounds to zero in the floating point hardware. Even if not zero, the number can be so small that learning slows to an untenable speed. The learning process either oscillates, in many cases chaotically, because of rounding phenomena or finds a static state and remains there. Again, this does not necessarily require a zero partial in the Jacobian.
  
  **A Familiar Analogy**
  
  The cognitive equivalent that helps intuition in understanding this but is not at all a great and across-the-board accurate analogy is the mental concept of doubt. The advantages of various directions of change or action to produce change is no longer clear. This is a rough analogy that some can connect to when considering what it means when the gradient is vanishing. When looking at gradient in historical context, where gradient is the slope of a surface in a location where gravity defines which direction is down, a vanishing gradient is a place where no direction seems to be down hill.
  
  **Flat in One Dimension by Design**
  
  In the question, where an inner layer2 is a ReLU activation function, the evaluation of the partial derivative of the loss function with respect to the parameter being adjusted will always be zero if its input is negative. However, this is by design and is one of the reasons ReLU trains fast. When the signal is negative going into the layer at that particular cell, it is thrifty to ignore it. The other cells upstream are then altered through other paths around the deactivated cell with the zero partial. A neuroscientist might smile at the oversimplification, but this is like a missing synapse between two adjacent cells in the brain.
  
  > In a setup like the above where the derivative is 0, is it true that a [network] won't learn anything?
  
  It is false. Learning will stop if all the derivatives in a layer are zero and no other device, such as curvature, momentum, regularization, and other devices controlled by hyper-parameters, is employed. Even so, zeros across the layer would only affect the adjustment of upstream layers, layers closer to the input. Downstream, convergence activity may continue in such a case.
  
  Zero and close to zero values (as well as near overflows) are kinds of saturation conditions, and these are studied carefully in artificial network research, but a single cell with a zero partial will not stop learning and may, in specific cases, ensure its completion and the adequacy of its result.
  
  **Some Calculus**
  
  In mathematical terms, if the Jacobian has a zero in one position, the others may remain active indicators of proper adjustment magnitude and direction for the individual parameters. If the Hessian is used or various types of momentum, regularization, or other techniques are employed, zeros across the Jacobian will probably not block upstream learning, which is part of the reason why they are used.
  
  **An Analogy for Momentum**
  
  The analogy can again be employed to clarify momentum as a principle, with the caveat that it is again an oversimplification. Beliefs have momentum, so when a belief exists and all other indications of direction for the next step is unsure, most will base their next step upon their beliefs.
  
  This is how all organisms with a brain tend to work and why mouse traps and spider webs can catch. Without viable feedback from which learning can occur, the organism will act based on the momentum in its DNA or networks of its brain. This is usually beneficial, but can lead to loss in specific cases.
  
  Gradients are not fool proof either. The problem of local minima can render pure gradient descent dysfunctional as well.
  
  **An Analogy for Curvature**
  
  Curvature (as when the Hessian is employed) requires a different analogy.
  
  If a smart, blind person is on a dry, flat surface, thirsty, and needing water, the gradient may be flat, they may feel with their foot or cane for some indication of curvature. If some down curving feature of the surface is found, that may guide the person to water in more cases than a random step.
  
  As hardware acceleration improves, the Hessian, which is to computationally heavy for CPU execution in most cases, may emerge as standard practice.
  
  Mathematically, this is simply moving from two terms of the Taylor series expansion in multivariate space to three terms. From a mechanics perspective, it is the inclusion of acceleration to velocity.
  
  ---
  
  **Footnotes**
  
  [1] Loss or any of these functions that drive behavior in AI systems: Error, disparity, value, benefit, optimality, and others of similar evaluative nature.
  
  [2] Inner layers in artificial networks are often called hidden layers, but that is not technically correct. Even though the encapsulation of a neural network may hide signals in inner layers from the programmer, it is a low level software design feature to do that, and a bad one. One can usually and definitely should be able to monitor those signals and produce statistics on them. They are not hidden in the mathematics, as in some kind of mathematical mystery, and the only difference between them and the output layer is that the output layer is intended to drive or influence something outside the network.
  
  
  ---
  
  