Aller au contenu principal

Vanishing gradient problem


Vanishing gradient problem


In machine learning, the vanishing gradient problem is encountered when training neural networks with gradient-based learning methods and backpropagation. In such methods, during each iteration of training each of the neural networks weights receives an update proportional to the partial derivative of the error function with respect to the current weight. The problem is that as the sequence length increases, the gradient magnitude typically is expected to decrease (or grow uncontrollably), slowing the training process. In the worst case, this may completely stop the neural network from further training. As one example of the problem cause, traditional activation functions such as the hyperbolic tangent function have gradients in the range [-1,1], and backpropagation computes gradients by the chain rule. This has the effect of multiplying n of these small numbers to compute gradients of the early layers in an n-layer network, meaning that the gradient (error signal) decreases exponentially with n while the early layers train very slowly.

Back-propagation allowed researchers to train supervised deep artificial neural networks from scratch, initially with little success. Hochreiter's diplom thesis of 1991 formally identified the reason for this failure in the "vanishing gradient problem", which not only affects many-layered feedforward networks, but also recurrent networks. The latter are trained by unfolding them into very deep feedforward networks, where a new layer is created for each time step of an input sequence processed by the network. (The combination of unfolding and backpropagation is termed backpropagation through time.)

When activation functions are used whose derivatives can take on larger values, one risks encountering the related exploding gradient problem.

Prototypical models

This section is based on the paper On the difficulty of training Recurrent Neural Networks by Pascanu, Mikolov, and Bengio.

Recurrent network model

A generic recurrent network has hidden states h 1 , h 2 , . . . {\displaystyle h_{1},h_{2},...} inputs u 1 , u 2 , . . . {\displaystyle u_{1},u_{2},...} , and outputs x 1 , x 2 , . . . {\displaystyle x_{1},x_{2},...} . Let it be parametrized by θ {\displaystyle \theta } , so that the system evolves as

Often, the output x t {\displaystyle x_{t}} is a function of h t {\displaystyle h_{t}} , as some x t = G ( h t ) {\displaystyle x_{t}=G(h_{t})} . The vanishing gradient problem already presents itself clearly when x t = h t {\displaystyle x_{t}=h_{t}} , so we simplify our notation to the special case with: Now, take its differential:Training the network requires us to define a loss function to be minimized. Let it be L ( x T , u 1 , . . . , u T ) {\displaystyle L(x_{T},u_{1},...,u_{T})} , then minimizing it by gradient descent gives

where η {\displaystyle \eta } is the learning rate.

The vanishing/exploding gradient problem appears because there are repeated multiplications, of the form

Example: recurrent network with sigmoid activation

For a concrete example, consider a typical recurrent network defined by

where θ = ( W r e c , W i n ) {\displaystyle \theta =(W_{rec},W_{in})} is the network parameter, σ {\displaystyle \sigma } is the sigmoid activation function, applied to each vector coordinate separately, and b {\displaystyle b} is the bias vector.

Then, x F ( x t 1 , u t , θ ) = W r e c d i a g ( σ ( x t 1 ) ) {\displaystyle \nabla _{x}F(x_{t-1},u_{t},\theta )=W_{rec}\mathop {diag} (\sigma '(x_{t-1}))} , and so

Since | σ | 1 {\displaystyle |\sigma '|\leq 1} , the operator norm of the above multiplication is bounded above by W r e c k {\displaystyle \|W_{rec}\|^{k}} . So if the spectral radius of W r e c {\displaystyle W_{rec}} is γ < 1 {\displaystyle \gamma <1} , then at large k {\displaystyle k} , the above multiplication has operator norm bounded above by γ k 0 {\displaystyle \gamma ^{k}\to 0} . This is the prototypical vanishing gradient problem.

The effect of a vanishing gradient is that the network cannot learn long-range effects. Recall Equation (loss differential):

The components of θ F ( x , u , θ ) {\displaystyle \nabla _{\theta }F(x,u,\theta )} are just components of σ ( x ) {\displaystyle \sigma (x)} and u {\displaystyle u} , so if u t , u t 1 , . . . {\displaystyle u_{t},u_{t-1},...} are bounded, then θ F ( x t k 1 , u t k , θ ) {\displaystyle \|\nabla _{\theta }F(x_{t-k-1},u_{t-k},\theta )\|} is also bounded by some M > 0 {\displaystyle M>0} , and so the terms in θ L {\displaystyle \nabla _{\theta }L} decay as M γ k {\displaystyle M\gamma ^{k}} . This means that, effectively, θ L {\displaystyle \nabla _{\theta }L} is affected only by the first O ( γ 1 ) {\displaystyle O(\gamma ^{-1})} terms in the sum.

If γ 1 {\displaystyle \gamma \geq 1} , the above analysis does not quite work. For the prototypical exploding gradient problem, the next model is clearer.

Dynamical systems model

Following (Doya, 1993), consider this one-neuron recurrent network with sigmoid activation:

At the small ϵ {\displaystyle \epsilon } limit, the dynamics of the network becomesConsider first the autonomous case, with u = 0 {\displaystyle u=0} . Set w = 5.0 {\displaystyle w=5.0} , and vary b {\displaystyle b} in [ 3 , 2 ] {\displaystyle [-3,-2]} . As b {\displaystyle b} decreases, the system has 1 stable point, then has 2 stable points and 1 unstable point, and finally has 1 stable point again. Explicitly, the stable points are ( x , b ) = ( x , ln ( x 1 x ) 5 x ) {\displaystyle (x,b)=\left(x,\ln \left({\frac {x}{1-x}}\right)-5x\right)} .

Now consider Δ x ( T ) Δ x ( 0 ) {\displaystyle {\frac {\Delta x(T)}{\Delta x(0)}}} and Δ x ( T ) Δ b {\displaystyle {\frac {\Delta x(T)}{\Delta b}}} , where T {\displaystyle T} is large enough that the system has settled into one of the stable points.

If ( x ( 0 ) , b ) {\displaystyle (x(0),b)} puts the system very close to an unstable point, then a tiny variation in x ( 0 ) {\displaystyle x(0)} or b {\displaystyle b} would make x ( T ) {\displaystyle x(T)} move from one stable point to the other. This makes Δ x ( T ) Δ x ( 0 ) {\displaystyle {\frac {\Delta x(T)}{\Delta x(0)}}} and Δ x ( T ) Δ b {\displaystyle {\frac {\Delta x(T)}{\Delta b}}} both very large, a case of the exploding gradient.

If ( x ( 0 ) , b ) {\displaystyle (x(0),b)} puts the system far from an unstable point, then a small variation in x ( 0 ) {\displaystyle x(0)} would have no effect on x ( T ) {\displaystyle x(T)} , making Δ x ( T ) Δ x ( 0 ) = 0 {\displaystyle {\frac {\Delta x(T)}{\Delta x(0)}}=0} , a case of the vanishing gradient.

Note that in this case, Δ x ( T ) Δ b x ( T ) b = ( 1 x ( T ) ( 1 x ( T ) ) 5 ) 1 {\displaystyle {\frac {\Delta x(T)}{\Delta b}}\approx {\frac {\partial x(T)}{\partial b}}=\left({\frac {1}{x(T)(1-x(T))}}-5\right)^{-1}} neither decays to zero nor blows up to infinity. Indeed, it's the only well-behaved gradient, which explains why early researches focused on learning or designing recurrent networks systems that could perform long-ranged computations (such as outputting the first input it sees at the very end of an episode) by shaping its stable attractors.

For the general case, the intuition still holds ( Figures 3, 4, and 5).

Geometric model

Continue using the above one-neuron network, fixing w = 5 , x ( 0 ) = 0.5 , u ( t ) = 0 {\displaystyle w=5,x(0)=0.5,u(t)=0} , and consider a loss function defined by L ( x ( T ) ) = ( 0.855 x ( T ) ) 2 {\displaystyle L(x(T))=(0.855-x(T))^{2}} . This produces a rather pathological loss landscape: as b {\displaystyle b} approach 2.5 {\displaystyle -2.5} from above, the loss approaches zero, but as soon as b {\displaystyle b} crosses 2.5 {\displaystyle -2.5} , the attractor basin changes, and loss jumps to 0.50.

Consequently, attempting to train b {\displaystyle b} by gradient descent would "hit a wall in the loss landscape", and cause exploding gradient. A slightly more complex situation is plotted in, Figures 6.

Solutions

To overcome this problem, several methods were proposed.

Batch normalization

Batch normalization is a standard method for solving both the exploding and the vanishing gradient problems.

Multi-level hierarchy

One is Jürgen Schmidhuber's multi-level hierarchy of networks (1992) pre-trained one level at a time through unsupervised learning, fine-tuned through backpropagation. Here each level learns a compressed representation of the observations that is fed to the next level.

Related approach

Similar ideas have been used in feed-forward neural networks for unsupervised pre-training to structure a neural network, making it first learn generally useful feature detectors. Then the network is trained further by supervised backpropagation to classify labeled data. The deep belief network model by Hinton et al. (2006) involves learning the distribution of a high-level representation using successive layers of binary or real-valued latent variables. It uses a restricted Boltzmann machine to model each new layer of higher level features. Each new layer guarantees an increase on the lower-bound of the log likelihood of the data, thus improving the model, if trained properly. Once sufficiently many layers have been learned the deep architecture may be used as a generative model by reproducing the data when sampling down the model (an "ancestral pass") from the top level feature activations. Hinton reports that his models are effective feature extractors over high-dimensional, structured data.

Long short-term memory

Another technique particularly used for recurrent neural networks is the long short-term memory (LSTM) network of 1997 by Hochreiter & Schmidhuber. In 2009, deep multidimensional LSTM networks demonstrated the power of deep learning with many nonlinear layers, by winning three ICDAR 2009 competitions in connected handwriting recognition, without any prior knowledge about the three different languages to be learned.

Faster hardware

Hardware advances have meant that from 1991 to 2015, computer power (especially as delivered by GPUs) has increased around a million-fold, making standard backpropagation feasible for networks several layers deeper than when the vanishing gradient problem was recognized. Schmidhuber notes that this "is basically what is winning many of the image recognition competitions now", but that it "does not really overcome the problem in a fundamental way" since the original models tackling the vanishing gradient problem by Hinton and others were trained in a Xeon processor, not GPUs.

Residual networks

One of the newest and most effective ways to resolve the vanishing gradient problem is with residual neural networks, or ResNets (not to be confused with recurrent neural networks). ResNets refer to neural networks where skip connections or residual connections are part of the network architecture. These skip connections allow gradient information to pass through the layers, by creating "highways" of information, where the output of a previous layer/activation is added to the output of a deeper layer. This allows information from the earlier parts of the network to be passed to the deeper parts of the network, helping maintain signal propagation even in deeper networks. Skip connections are a critical component of what allowed successful training of deeper neural networks.

ResNets yielded lower training error (and test error) than their shallower counterparts simply by reintroducing outputs from shallower layers in the network to compensate for the vanishing data. Note that ResNets are an ensemble of relatively shallow nets and do not resolve the vanishing gradient problem by preserving gradient flow throughout the entire depth of the network – rather, they avoid the problem simply by constructing ensembles of many short networks together. (Ensemble by Construction)

Other activation functions

Rectifiers such as ReLU suffer less from the vanishing gradient problem, because they only saturate in one direction.

Weight initialization

Weight initialization is another approach that has been proposed to reduce the vanishing gradient problem in deep networks.

Kumar suggested that the distribution of initial weights should vary according to activation function used and proposed to initialize the weights in networks with the logistic activation function using a Gaussian distribution with a zero mean and a standard deviation of 3.6/sqrt(N), where N is the number of neurons in a layer.

Recently, Yilmaz and Poli performed a theoretical analysis on how gradients are affected by the mean of the initial weights in deep neural networks using the logistic activation function and found that gradients do not vanish if the mean of the initial weights is set according to the formula: max(−1,-8/N). This simple strategy allows networks with 10 or 15 hidden layers to be trained very efficiently and effectively using the standard backpropagation.

Other

Behnke relied only on the sign of the gradient (Rprop) when training his Neural Abstraction Pyramid to solve problems like image reconstruction and face localization.

Neural networks can also be optimized by using a universal search algorithm on the space of neural network's weights, e.g., random guess or more systematically genetic algorithm. This approach is not based on gradient and avoids the vanishing gradient problem.

See also

  • Spectral radius

Notes

References

Giuseppe Zanotti Luxury Sneakers

Text submitted to CC-BY-SA license. Source: Vanishing gradient problem by Wikipedia (Historical)



INVESTIGATION