Search

Search papers and lessons

Catastrophic Forgetting

Level 3 · 11 min read

Catastrophic forgetting is when a neural network trained on a new task overwrites what it learned on an old one, because the same weights serve both tasks.

On this page

  • Colour = topic mix
  • Discrete math
  • Calculus
  • Linear algebra
  • Probability
  • Neural network basics
  • Optimizers
  • ReadReady to readNot yet

TL;DR

Catastrophic forgetting is the sudden loss of an old skill when a neural network is trained on something new. The network has one set of weights, and gradient descent changes whichever weights reduce the current error, with no record of which weights mattered before. The result is a model that does well on the newest task and has lost most of what it knew earlier.

Builds on: Feedforward Neural Network, Stochastic Gradient Descent · Leads to: Continual Learning, Experience Replay

Where it's used

Phones and assistants that keep learning. A keyboard model that adapts to one person's writing must not forget how to handle ordinary words. If it is trained only on the newest messages, its ability on older kinds of text can fall away, which is why these systems mix old and new data during updates.

Models that get a new job. A language model fine-tuned for customer support can become worse at its original general knowledge. Teams that adapt a fine-tuned model to a narrow task often measure the old benchmarks again to see how much was lost.

Robots and games learning in sequence. A robot taught to grasp one object, then another, can lose its grip on the first. Deep Q-network game agents trained on ten Atari 2600 games in sequence were the test case in the 2016 work by Kirkpatrick and colleagues, who showed the same loss there and then reduced it.

How it works

Take the smallest possible learner: one weight ww and the prediction y=wxy = w x. Each task supplies one example, and the loss is the squared error. Task A is the example x=1x = 1, y=2y = 2, so its loss is (w−2)2(w - 2)^2, and the best weight for A is w=2w = 2. Task B is the example x=1x = 1, y=−1y = -1, so its loss is (w+1)2(w + 1)^2, and the best weight for B is w=−1w = -1. The learning rate is 0.25.

  1. Learn task A. Start at w=2w = 2, which already solves A. The loss for A is 0. Check: (2−2)2=0(2 - 2)^2 = 0.

  2. Switch to task B. Gradient descent moves ww downhill on B's loss. The gradient is the slope of the loss with respect to ww. For (w+1)2(w+1)^2, the power rule says the slope of u2u^2 is 2u2u, and here u=w+1u = w + 1, so the gradient is 2(w+1)2(w+1). Each step subtracts 0.25×2(w+1)=0.5(w+1)0.25 \times 2(w+1) = 0.5(w+1) from ww. From w=2w = 2, the step is 0.5×3=1.50.5 \times 3 = 1.5, so w=0.5w = 0.5. Check: ww moved towards B's best value, −1-1.

  3. Check task A again. At w=0.5w = 0.5 the loss for A is (0.5−2)2=2.25(0.5 - 2)^2 = 2.25. The network has already started to forget A, even though nothing in the update mentions A. Check: the loss rose from 0 to 2.25.

  4. Keep training on B. From w=0.5w = 0.5 the step is 0.5×1.5=0.750.5 \times 1.5 = 0.75, so w=−0.25w = -0.25. A's loss is now (−2.25)2=5.0625(-2.25)^2 = 5.0625. Check: the forgetting grows as training goes on.

  5. Finish. Two more steps give w=−0.625w = -0.625 and then w=−0.8125w = -0.8125. B's loss is now 0.18752≈0.0350.1875^2 \approx 0.035, nearly solved. A's loss is (−2.8125)2≈7.91(-2.8125)^2 \approx 7.91, up from 0. Check: the weight that once solved A now sits far from it.

flowchart LR
  A[Weight solves task A] --> B[Gradient steps on task B only]
  B --> C[Weight moves towards B's best value]
  C --> D[A's loss rises with every step]
  D --> E[Old skill lost]

The math

Let the network have parameters θ\theta and let LA(θ)\mathcal{L}_{A}(\theta) and LB(θ)\mathcal{L}_{B}(\theta) be the losses on tasks A and B. Training on the tasks in sequence means first finding θA∗\theta_A^{*} that minimises LA\mathcal{L}_{A}, then running gradient descent on LB\mathcal{L}_{B} alone:

θt+1=θt−η∇LB(θt),θ0=θA∗,\theta_{t+1} = \theta_t - \eta \nabla \mathcal{L}_{B}(\theta_t), \qquad \theta_0 = \theta_A^{*},

where η\eta is the learning rate and ∇LB(θt)\nabla \mathcal{L}_{B}(\theta_t) is the gradient, the vector of slopes of B's loss with respect to each parameter at the current values. Nothing in this update contains LA\mathcal{L}_{A}. Forgetting happens when the path from θA∗\theta_A^{*} to a good θ\theta for B passes through parameters where LA\mathcal{L}_{A} is large.

Step 2 in symbols: the update

For the toy learner, LB(w)=(w+1)2\mathcal{L}_{B}(w) = (w + 1)^2, so ∇LB(w)=2(w+1)\nabla \mathcal{L}_{B}(w) = 2(w + 1). With η=0.25\eta = 0.25, the update is wt+1=wt−0.5(wt+1)w_{t+1} = w_t - 0.5(w_t + 1). Starting from w0=2w_0 = 2, the first step gives w1=2−1.5=0.5w_1 = 2 - 1.5 = 0.5.

Step 3 in symbols: the forgetting

The loss on A after the step is LA(w1)=(w1−2)2=(0.5−2)2=2.25\mathcal{L}_{A}(w_1) = (w_1 - 2)^2 = (0.5 - 2)^2 = 2.25. In general, the forgetting after tt steps is the increase LA(θt)−LA(θA∗)\mathcal{L}_{A}(\theta_t) - \mathcal{L}_{A}(\theta_A^{*}), which is zero only if the B updates happen not to disturb A's weights.

The fix in symbols: a penalty on important weights

Elastic weight consolidation, the method in the 2016 paper, adds a penalty for moving weights that mattered for A. Let FiF_i be an estimate of how important weight ii was for A (the diagonal of the Fisher information), and let θA,i∗\theta_{A,i}^{*} be its value after task A. The training loss for B becomes

LB(θ)+λ2∑iFi(θi−θA,i∗)2,\mathcal{L}_{B}(\theta) + \frac{\lambda}{2} \sum_{i} F_i \left(\theta_i - \theta_{A,i}^{*}\right)^2,

where λ\lambda sets how strongly old knowledge is protected. A weight with a large FiF_i is held near its old value, and an unimportant weight is free to move.

Worked examples

Example
Example 1: one weight, two tasks

Use the toy learner above, with task A pulling ww towards 2 and task B pulling ww towards −1-1.

  1. Start at w=2w = 2. Task A's loss is (2−2)2=0(2 - 2)^2 = 0.
  2. One gradient step on B with η=0.25\eta = 0.25: w=2−0.25×2×(2+1)=2−1.5=0.5w = 2 - 0.25 \times 2 \times (2 + 1) = 2 - 1.5 = 0.5.
  3. Task A's loss is now (0.5−2)2=2.25(0.5 - 2)^2 = 2.25.
  4. Task B's loss is now (0.5+1)2=2.25(0.5 + 1)^2 = 2.25, so B has improved only from its starting point of (2+1)2=9(2 + 1)^2 = 9 to 2.25.

Interpretation: a single step on B fixed a large part of B's error and gave A a loss of 2.25, so the forgetting began at once.

Example
Example 2: the elastic penalty for two weights

Suppose a network has two weights after task A, with θA∗=(1,1)\theta_{A}^{*} = (1, 1). Their importances, the diagonal values of the Fisher information, are F1=4F_1 = 4 and F2=0.25F_2 = 0.25. Training on B moves the weights to θ=(1.5,3)\theta = (1.5, 3), and the penalty strength is λ=2\lambda = 2.

  1. Find the shifts: θ1−θA,1∗=1.5−1=0.5\theta_1 - \theta_{A,1}^{*} = 1.5 - 1 = 0.5 and θ2−θA,2∗=3−1=2\theta_2 - \theta_{A,2}^{*} = 3 - 1 = 2.
  2. Compute the penalty terms: F1×0.52=4×0.25=1F_1 \times 0.5^2 = 4 \times 0.25 = 1 and F2×22=0.25×4=1F_2 \times 2^2 = 0.25 \times 4 = 1.
  3. Add them and multiply by λ/2=1\lambda / 2 = 1: the penalty is 1+1=21 + 1 = 2.
  4. Compare the gradients of the penalty, λFi(θi−θA,i∗)\lambda F_i (\theta_i - \theta_{A,i}^{*}): weight 1 gives 2×4×0.5=42 \times 4 \times 0.5 = 4, and weight 2 gives 2×0.25×2=12 \times 0.25 \times 2 = 1.

Interpretation: weight 2 moved four times as far, but weight 1 is pushed back four times as hard, because it was the important one for A. The optimiser is allowed to change the unimportant weight much more freely.

Example
Example 3: a spam filter with a replay buffer (hypothetical numbers)

A spam filter is updated every week using only that week's mail. Suppose it keeps a replay buffer of 300 old messages from earlier weeks, and this week's training set has 2,700 new messages. The numbers are invented for the example.

  1. Count the total training set: 300+2,700=3,000300 + 2{,}700 = 3{,}000 messages.
  2. Find the share of old messages: 300/3,000=0.10300 / 3{,}000 = 0.10, which is 10 percent.
  3. Compare with no buffer: the share of old messages is 0 percent, so the update sees only new spam styles.
  4. Expect the buffer to keep the old skill: each batch contains about one old message in ten, so the gradient still reflects the old task and pulls the weights back towards it.

Interpretation: the buffer is a cheap way to keep the old task in the gradient. Its size is a tradeoff: too small and the old task is forgotten, too large and the update is slow and expensive.

Try it: the buffer has 200 old messages and the new set has 1,800. What share is old? Answer: 200/2000=0.10200 / 2000 = 0.10, which is again 10 percent, because the buffer and the new set have the same ratio as in the example.

Common mistakes and tradeoffs

It is tempting to think the network forgets because its weights are damaged. In fact nothing is damaged. The same weights are simply pulled, step by step, towards the solution for the new task, and that solution is far from the old one. Forgetting is the expected result of optimising one loss on a shared set of weights.

It is tempting to think more training on the old data will fix it. In fact the best way to keep an old skill is to keep some of the old data in the mix, which is what replay does. Retraining from scratch on everything works, but it costs far more than a small replay buffer.

It is tempting to think a lower learning rate prevents forgetting. In fact a smaller step only slows the drift. The weights still move towards the new task, and the forgetting still happens, just over more steps. Lowering the rate trades speed for less damage, not the removal of the problem.

It is tempting to think any regularisation will protect the old task. In fact a generic penalty on weight size treats all weights alike, so it protects the unimportant ones and fails to protect the important ones. Methods such as Fisher-weighted penalties work better because they weight each parameter by how much the old task depends on it.

Use replay when old data can be stored and the cost of keeping it is acceptable. Use a weight penalty when old data cannot be kept. Use Transfer Learning rather than continual learning when the new task should benefit from the old one and you do not need to keep the old skill at all.

History

In the late 1980s, McCloskey and Cohen reported that connectionist networks lost earlier learned material when trained on new material, and they called the effect catastrophic interference. Robert French's 1999 review is the usual citation for the term catastrophic forgetting. For years the common view was that the effect was an unavoidable feature of networks that store knowledge in shared weights.

The 2016 paper by James Kirkpatrick and colleagues at DeepMind challenged that view. It showed that a penalty on important weights, using the Fisher information, let a deep network learn a sequence of MNIST classification tasks and several Atari 2600 games in sequence without collapsing on the earlier ones. The paper appeared on arXiv in 2016 and was published in the journal PNAS in 2017. Since then, continual learning has become a field of its own, with replay, penalties and architectural methods competing on the same benchmarks.

Recap

  • Catastrophic forgetting happens because one set of weights is shared by all tasks, and gradient descent on a new task has no memory of the old one.
  • The loss on the old task rises with each step on the new one, which the toy example shows in a few steps.
  • Replay keeps old examples in the training mix, and a penalty on important weights holds them near their old values.
  • Read next: Continual Learning, the field that studies learning on a sequence of tasks, and Experience Replay, the simplest remedy.

Check yourself

QuestionIn one sentence, why does training on task B make a network forget task A even though the update never looks at task A?Show answer

Both tasks use the same weights, and the gradient for B moves those weights wherever B's loss decreases. Nothing in that update protects the values that A needed, so A's loss can rise.

QuestionFor the toy learner with w=0.5w = 0.5, what is the loss on task A, where the best weight for A is 2?Show answer

The loss is (0.5−2)2=(−1.5)2=2.25(0.5 - 2)^2 = (-1.5)^2 = 2.25.

QuestionWhy does the elastic penalty weight each weight by its importance FiF_i, rather than penalising every weight equally?Show answer

Important weights are the ones whose change hurts the old task most. Penalising every weight equally would stop unimportant weights from adapting, which wastes capacity, and would leave the important weights only weakly protected. The importance weighting puts the protection where it is needed.

QuestionA replay buffer holds 400 old examples, and the new training set has 1,600 examples. What share of each batch, on average, is old?Show answer

The total is 400+1600=2000400 + 1600 = 2000, and the share of old examples is 400/2000=0.20400 / 2000 = 0.20, which is 20 percent.

Sources