ArticleslgStudy

computer science

Vanishing gradient problem

Vanishing gradient problem is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Vanishing gradient problem rather than just read about it. In short: 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.

Vanishing gradient problem — main illustration
Vanishing gradient problem — illustration

Key takeaways

  • Vanishing gradient problem belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Vanishing gradient problem to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Vanishing gradient problem from memory before moving on to harder problems.

Reference excerpt

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.

Worked examples

Example 1 — a first encounter with Vanishing gradient problem

Start with the simplest possible case. Write down what Vanishing gradient problem claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Vanishing gradient problem before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Vanishing gradient problem ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Vanishing gradient problem

In research
Vanishing gradient problem appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Vanishing gradient problem in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Vanishing gradient problem is common in secondary-school and first-year university syllabi. It links to neighbouring topics Artificial neural networks, so understanding it makes those chapters shorter.
In everyday life
Look for Vanishing gradient problem outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Vanishing gradient problem” →

How to study Vanishing gradient problem in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Vanishing gradient problem means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Vanishing gradient problem out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Vanishing gradient problem in simple terms?

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 o…

Why does Vanishing gradient problem matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Vanishing gradient problem?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Vanishing gradient problem.

Tags

  • Artificial neural networks

Keep exploring