In machine learning, the vanishing gradient problem is the problem of greatly diverging gradient magnitudes between earlier and later layers encountered when training neural networks with backpropagation. In such methods, neural network weights are updated proportional to their partial derivative of the loss function. As the number of forward propagation steps in a network increases, for instance due to greater network depth, the gradients of earlier weights are calculated with increasingly many multiplications. These multiplications shrink the gradient magnitude. Consequently, the gradients of earlier weights will be exponentially smaller than the gradients of later weights. This difference in gradient magnitude might introduce instability in the training process, slow it, or halt it entirely. For instance, consider the hyperbolic tangent activation function. The gradients of this function are in range [0,1]. The product of repeated multiplication with such gradients decreases exponentially. The inverse problem, when weight gradients at earlier layers get exponentially larger, is called the exploding gradient problem. Backpropagation 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).
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 h1,h2,…, inputs u1,u2,…, and outputs x1,x2,…. Let it be parameterized by θ, so that the system evolves as (ht,xt)=F(ht−1,ut,θ) Often, the output xt is a function of ht, as some xt=G(ht). The vanishing gradient problem already presents itself clearly when xt=ht, so we simplify our notation to the special case with: xt=F(xt−1,ut,θ) Now, take its differential: dxt=∇θF(xt−1,ut,θ)dθ+∇xF(xt−1,ut,θ)dxt−1=∇θF(xt−1,ut,θ)dθ+∇xF(xt−1,ut,θ)[∇θF(xt−2,ut−1,θ)dθ+∇xF(xt−2,ut−1,θ)dxt−2]⋮=[∇θF(xt−1,ut,θ)+∇xF(xt−1,ut,θ)∇θF(xt−2,ut−1,θ)+⋯]dθ Training the network requires us to define a loss function to be minimized. Let it be L(xT,u1,…,uT), then minimizing it by gradient descent gives
Δθ=−η⋅[∇xL(xT)(∇θF(xt−1,ut,θ)+∇xF(xt−1,ut,θ)∇θF(xt−2,ut−1,θ)+⋯)]Twhere η is the learning rate. The vanishing/exploding gradient problem appears because there are repeated multiplications, of the form∇xF(xt−1,ut,θ)∇xF(xt−2,ut−1,θ)∇xF(xt−3,ut−2,θ)⋯
Example: recurrent network with sigmoid activation For a concrete example, consider a typical recurrent network defined by xt=F(xt−1,ut,θ)=Wrecσ(xt−1)+Winut+bwhere θ=(Wrec,Win) is the network parameter, σ is the sigmoid activation function, applied to each vector coordinate separately, and b is the bias vector. Then, ∇xF(xt−1,ut,θ)=Wrecdiag(σ′(xt−1)), and so ∇xF(xt−1,ut,θ)∇xF(xt−2,ut−1,θ)⋯∇xF(xt−k,ut−k+1,θ)=Wrecdiag(σ′(xt−1))Wrecdiag(σ′(xt−2))⋯Wrecdiag(σ′(xt−k)) Since |σ′|≤1, the operator norm of the above multiplication is bounded above by ‖Wrec‖k. So if the spectral radius of Wrec is γ<1, then at large k, the above multiplication has operator norm bounded above by γk→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):∇θL=∇xL(xT,u1,…,uT)[∇θF(xt−1,ut,θ)+∇xF(xt−1,ut,θ)∇θF(xt−2,ut−1,θ)+⋯]The components of ∇θF(x,u,θ) are just components of σ(x) and u, so if ut,ut−1,… are bounded, then ‖∇θF(xt−k−1,ut−k,θ)‖ is also bounded by some M>0, and so the terms in ∇θL decay as Mγk. This means that, effectively, ∇θL is affected only by the first O(γ−1) terms in the sum. If γ≥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: xt+1=(1−ε)xt+εσ(wxt+b)+εw′ut At the small ε limit, the dynamics of the network becomes dxdt=−x(t)+σ(wx(t)+b)+w′u(t) Consider first the autonomous case, with u=0. Set w=5.0, and vary b in [−3,−2]. As 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(x1−x)−5x). Now consider Δx(T)Δx(0) and Δx(T)Δb, where T is large enough that the system has settled into one of the stable points. If (x(0),b) puts the system very close to an unstable point, then a tiny variation in x(0) or b would make x(T) move from one stable point to the other. This makes Δx(T)Δx(0) and Δx(T)Δb both very large, a case of the exploding gradient. If (x(0),b) puts the system far from an unstable point, then a small variation in x(0) would have no effect on x(T), making Δx(T)Δx(0)=0, a case of the vanishing gradient. Note that in this case, Δx(T)Δb≈∂x(T)∂b=(1x(T)(1−x(T))−5)−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, and consider a loss function defined by L(x(T))=(0.855−x(T))2. This produces a rather pathological loss landscape: as b approach −2.5 from above, the loss approaches zero, but as soon as b crosses −2.5, the attractor basin changes, and loss jumps to 0.50. Consequently, attempting to train 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.
… excerpt ends here. Continue reading the full article.
