Search

Search papers and lessons

Continual Learning

Level 3 · 12 min read

Continual learning trains one model on tasks that arrive in sequence, aiming to learn each new task without losing the old ones, which plain retraining on the newest data does not do.

On this page

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

TL;DR

Continual learning is the problem of training one model on tasks or data that arrive in sequence, where the old data is no longer available when the new data arrives. The goal is to learn each new task while keeping what the model already knows. It is hard for a neural network because the same weights serve every task, so the update for a new task can undo the old one (Catastrophic Forgetting).

Builds on: Catastrophic Forgetting, Supervised Learning · Leads to: Experience Replay, Transfer Learning, elastic weight consolidation

Where it's used

Personal devices. A phone keyboard that learns a user's words and slang over months should keep handling ordinary language after it adapts. The update uses only what the phone has seen recently, so the model must keep its general skill while it specialises.

Fraud and spam filters. Banks and mail providers retrain their models as new scams appear, often on a regular schedule. Last year's transactions may be deleted or restricted by privacy rules, so each update has to learn the new patterns while still catching the old ones.

Robots that learn new skills. A household robot taught to open a new kind of cabinet must still open the cabinets it learned earlier. Robotics groups test this by giving a robot a sequence of manipulation tasks and measuring how well it does the first ones at the end.

How it works

Use the smallest learner that still shows the problem: one number ww, with prediction ww itself. Each task has a target tt, and its loss is (w−t)2(w - t)^2. Task A has target t=4t = 4. Task B has target t=0t = 0. We train with gradient descent at learning rate 0.250.25. The gradient of (w−t)2(w - t)^2 is 2(w−t)2(w - t), so each step is w←w−0.25×2(w−t)=0.5w+0.5tw \leftarrow w - 0.25 \times 2(w - t) = 0.5w + 0.5t. In words: each step moves ww halfway towards the target.

  1. Start untrained. w=0w = 0. The loss for task A is (0−4)2=16(0 - 4)^2 = 16. Check: the model is far from A's target.

  2. Train on A, step one. w=0.5×0+0.5×4=2w = 0.5 \times 0 + 0.5 \times 4 = 2. The loss for A is (2−4)2=4(2 - 4)^2 = 4. Check: ww moved halfway from 0 to 4.

  3. Train on A, step two. w=0.5×2+0.5×4=3w = 0.5 \times 2 + 0.5 \times 4 = 3. The loss for A is (3−4)2=1(3 - 4)^2 = 1. Check: ww moved halfway again, from 2 to 3.

  4. Switch to B, step one. The data now comes only from task B, so the update uses only B's loss. w=0.5×3+0.5×0=1.5w = 0.5 \times 3 + 0.5 \times 0 = 1.5. The loss for B is (1.5−0)2=2.25(1.5 - 0)^2 = 2.25, down from 9. But the loss for A is (1.5−4)2=6.25(1.5 - 4)^2 = 6.25, up from 1. Check: B improved and A got worse, although no update mentioned A.

  5. Switch to B, step two. w=0.5×1.5+0=0.75w = 0.5 \times 1.5 + 0 = 0.75. The loss for B is 0.56250.5625. The loss for A is (0.75−4)2=10.5625(0.75 - 4)^2 = 10.5625. Check: the more the model learns B, the further A's loss grows.

  6. Compare with replay. Now suppose each step uses the average of both losses, so the update sees A and B together. The average loss is 12(w−4)2+12w2\tfrac{1}{2}(w - 4)^2 + \tfrac{1}{2}w^2, and its gradient is 2w−42w - 4. With learning rate 0.250.25 the update becomes w←0.5w+1w \leftarrow 0.5w + 1. From w=3w = 3 the next value is 2.52.5, with losses 2.252.25 for A and 6.256.25 for B. After a few more steps ww settles at 22, where both losses are 44. Check: neither task is solved perfectly, but neither is lost.

flowchart LR
  A[Train on task A] --> B[Model solves A]
  B --> C[Train only on task B]
  C --> D[B improves]
  C --> E[A gets worse with each step]
  B --> F[Replay: mix A and B in each step]
  F --> G[Settles where both losses are moderate]
−10123450510152025wloss
  • task A loss
  • task B loss
  • mixed loss
Sequential training ends near w = 0.75, where task A's loss is 10.56. The mixed loss is lowest at w = 2, where both task losses are 4.

The math

Suppose there are tasks T1,…,TKT_1, \dots, T_K, arriving in that order. Task kk has a loss Lk(θ)\mathcal{L}_k(\theta) on the parameters θ\theta, and its data is available only during phase kk. The aim at the end is a small total loss over all tasks:

∑k=1KLk(θ).\sum_{k=1}^{K} \mathcal{L}_k(\theta).

Sequential training minimises only the last term, LK\mathcal{L}_K, and so has no reason to keep the others small. Replay approximates the full sum by putting examples from earlier tasks into each batch.

Step 2 in symbols: the update

For the toy learner, Lk(w)=(w−tk)2\mathcal{L}_k(w) = (w - t_k)^2, so its gradient is 2(w−tk)2(w - t_k). Gradient descent with learning rate η\eta gives ws+1=ws−2η(ws−tk)w_{s+1} = w_s - 2\eta(w_s - t_k). With η=0.25\eta = 0.25 this is ws+1=0.5ws+0.5tkw_{s+1} = 0.5 w_s + 0.5 t_k. Starting from w0=0w_0 = 0 on task A with tA=4t_A = 4, we get w1=2w_1 = 2 and w2=3w_2 = 3.

Step 4 in symbols: the forgetting

Let θA\theta_A be the parameters right after task A is learned, and θAB\theta_{AB} the parameters after the B phase. The forgetting on A is

FA=LA(θAB)−LA(θA).F_A = \mathcal{L}_A(\theta_{AB}) - \mathcal{L}_A(\theta_A).

In the walkthrough, LA(θA)=1\mathcal{L}_A(\theta_A) = 1 and, after step five, LA(θAB)=10.5625\mathcal{L}_A(\theta_{AB}) = 10.5625. So FA=9.5625F_A = 9.5625.

Step 6 in symbols: the replay objective

The replay objective is the average of the two losses,

Lmix(w)=12LA(w)+12LB(w)=12(w−4)2+12w2.\mathcal{L}_{\text{mix}}(w) = \tfrac{1}{2}\mathcal{L}_A(w) + \tfrac{1}{2}\mathcal{L}_B(w) = \tfrac{1}{2}(w - 4)^2 + \tfrac{1}{2}w^2.

Its derivative is (w−4)+w=2w−4(w - 4) + w = 2w - 4. Setting this to zero gives w=2w = 2. The loss is a parabola with its lowest point there, so no other value of ww gives a smaller average. At w=2w = 2 the two task losses are (2−4)2=4(2 - 4)^2 = 4 and (2−0)2=4(2 - 0)^2 = 4.

The gap between the two situations is a general tension. A model that changes easily to learn a new task is called plastic, and one that keeps old behaviour is stable. Continual learning is the search for a method that keeps both.

Worked examples

Example
Example 1: one step on a new task

Use the toy learner. Start at w=0w = 0, train on task A (target 4) for two steps, so w=3w = 3. Then take one step on task B (target 1) with the same rule w←0.5w+0.5tw \leftarrow 0.5w + 0.5t.

  1. After A, w=3w = 3. The loss for A is (3−4)2=1(3 - 4)^2 = 1.
  2. One step on B: w=0.5×3+0.5×1=2w = 0.5 \times 3 + 0.5 \times 1 = 2.
  3. The loss for A is now (2−4)2=4(2 - 4)^2 = 4, up by 3.
  4. The loss for B is now (2−1)2=1(2 - 1)^2 = 1, down from (3−1)2=4(3 - 1)^2 = 4, also by 3.

Interpretation: one step traded 3 units of loss on A for 3 units of loss on B. Sequential training always makes this trade in favour of the newest task.

Example
Example 2: measuring forgetting with accuracy (hypothetical numbers)

A photo classifier learns task A, telling animal photos apart, and then task B, telling vehicle photos apart. The numbers below are invented for the example.

  1. Accuracy on A after training on A is 0.90.
  2. Accuracy on A after training on B, with no replay, is 0.55.
  3. The forgetting is 0.90−0.55=0.350.90 - 0.55 = 0.35.
  4. Repeat with a replay buffer of old animal photos mixed into the B training. Accuracy on A is now 0.85.
  5. The forgetting with replay is 0.90−0.85=0.050.90 - 0.85 = 0.05.
  6. Replay recovered 0.35−0.05=0.300.35 - 0.05 = 0.30 of the 0.350.35 that was lost, which is 0.30/0.35≈0.860.30 / 0.35 \approx 0.86, about 86 percent.

Interpretation: a small buffer of old examples removed most of the forgetting in this case, without retraining on everything.

Example
Example 3: a monthly fraud model with a replay buffer (hypothetical numbers)

A card-fraud model is updated every month. The team keeps a buffer of 5,000 transactions from earlier months and adds 20,000 new transactions for the update. The numbers are invented for the example.

  1. Count the training set: 5,000+20,000=25,0005{,}000 + 20{,}000 = 25{,}000 transactions.
  2. Find the share of old transactions: 5,000/25,000=0.205{,}000 / 25{,}000 = 0.20.
  3. Compare with no buffer: the share of old transactions is 0.
  4. Interpret: about one training example in five is old, so the update still sees the old fraud patterns.

Try it: the buffer holds 1,500 old transactions and the new set has 4,500. What share is old? Answer: 1,500/6,000=0.251{,}500 / 6{,}000 = 0.25, one in four. A larger share keeps more of the old behaviour but slows learning the new patterns, which is the same tradeoff as in the toy example.

Common mistakes and tradeoffs

It is tempting to think that retraining from scratch on all the data is continual learning. In fact that is the upper bound that continual learning tries to approach, and it is often impossible, because the old data has been deleted or cannot be kept under privacy rules. Continual learning is about learning without that data.

It is tempting to think that a model which forgets just needs more training on the new task. In fact more training on the new task makes forgetting worse, as step five of the walkthrough shows. The loss on the old task rises with every step on the new one.

It is tempting to think forgetting needs very different tasks. In fact it also happens when the same task drifts slowly, such as a model whose users change their language over time. The shared weights are the cause, not the size of the change.

It is tempting to think that stability and plasticity are the same goal. In fact they pull against each other. The mixed loss in the walkthrough settles at a point where neither task is solved well, which is the price of keeping both.

Use replay when some old examples can be stored and the cost of keeping them is acceptable. Use a penalty on important weights, such as elastic weight consolidation, when old data cannot be kept at all. It needs an estimate of which weights mattered for the old task, usually from the Fisher information. Use Transfer Learning instead when the new task should benefit from the old one and the old skill does not need to be kept.

MethodIdeaMain cost
Retrain on everythingMix all old and new data each timeStorage, and compute grows with every update
ReplayKeep a buffer of old examples in each batchStorage of old examples, and a tradeoff in buffer size
Weight penaltyHold important weights near their old valuesEstimating importance, and no good way to set the penalty strength in general
Add capacityGive each task its own new parametersThe model grows with every task

History

In the late 1980s, Michael McCloskey and Neal Cohen reported that connectionist networks trained on a new set of associations lost the earlier ones, and they named the effect catastrophic interference. In 1999 Robert French reviewed the problem and helped establish catastrophic forgetting as the common name. Around the same time, Sebastian Thrun and Tom Mitchell wrote about lifelong learning, the idea that a learner should keep its skills across many tasks.

Work on the problem grew slowly while neural networks were out of favour, and then faster with deep learning. In 2016 James Kirkpatrick and colleagues at DeepMind showed that a penalty on important weights, based on the Fisher information, let a deep network learn several tasks in sequence with much less forgetting. The paper appeared on arXiv in 2016 and in the journal PNAS in 2017. Since then the field has grown, with replay, penalties and architectural methods all compared on common benchmarks.

Recap

  • Continual learning means learning a sequence of tasks or data streams while keeping what was learned earlier.
  • It is hard for neural networks because one set of weights serves all the tasks, so each update for a new task moves the weights that the old tasks need (Catastrophic Forgetting).
  • Sequential training makes the trade in favour of the newest task. Replay mixes old examples into each update, and a weight penalty holds important weights near their old values.
  • Read next: Experience Replay, the simplest remedy, and Transfer Learning, which is what to use when the old skill does not need to be kept.

Check yourself

QuestionIn one sentence, how does continual learning differ from retraining a model on the newest data?Show answer

Continual learning aims to keep performance on the earlier tasks while learning the new one, using only the data it has now or a small set of kept old examples. Plain retraining on the newest data gives no protection for the old tasks, so their performance drops as the model learns the new one.

QuestionA single weight starts at w=3w = 3. One update uses the rule w←0.5w+0.5tw \leftarrow 0.5w + 0.5t with target t=0t = 0. What is the new ww, and what is the loss for a task with target 4 afterwards?Show answer

The new value is w=0.5×3+0.5×0=1.5w = 0.5 \times 3 + 0.5 \times 0 = 1.5. The loss for target 4 is (1.5−4)2=6.25(1.5 - 4)^2 = 6.25. The second number is worse than the 1 it was at w=3w = 3, which is forgetting in one step.

QuestionWhy does mixing old examples into each batch help, when the update rule itself never mentions the old task?Show answer

Each batch then contains examples from the old task, so the gradient includes the old task's loss. The combined gradient pulls the weights towards a point that suits both tasks, instead of towards the new task alone. In the toy example, the mixed objective has its minimum at w=2w = 2 rather than at the new target.

QuestionA voice assistant must learn a new accent, must keep its old accents working, and may not keep any recordings after 30 days. Which method fits best, and why?Show answer

A weight penalty fits best, because it needs an estimate of which weights mattered for the old accents, not the old recordings. Replay would need old examples, which the 30-day rule forbids beyond a short window. A short replay buffer of recent, consented examples could be combined with the penalty if the rule allows it.

Sources