Catastrophic forgetting
9 min read
One set of weights, many skills
A model has one set of weights, and every skill it has is stored across them. When you fine-tune on a narrow dataset, the updates push the weights towards that data. Nothing in the loss asks the model to stay good at anything else, so abilities that the new data never uses can degrade. The more the weights move, the more you can lose.
This matters for real products. A support model tuned to label tickets might become worse at following a general instruction, at refusing unsafe requests or at writing in another language. If those behaviours matter, you have to measure them.
Watch it happen
The program below uses the same kind of tiny model as How a language model learns: one score per word, turned into probabilities. The model starts by liking the pet words cat and dog. It is then trained on support words only, and compared with a run that mixes in pet examples as it trains.
import math
words = ["cat", "dog", "invoice", "password"]
def probabilities(scores):
exps = [math.exp(s) for s in scores]
total = sum(exps)
return [e / total for e in exps]
def train(scores, targets, rate):
for target in targets:
p = probabilities(scores)
for i in range(len(scores)):
scores[i] -= rate * (p[i] - (1.0 if i == target else 0.0))
return scores
def mass(scores, names):
p = probabilities(scores)
return sum(p[words.index(n)] for n in names)
pretrained = train([0.0] * 4, [0, 1] * 100, 0.1)
support = [2, 3] * 150
mixed = ([2, 3, 2, 3, 0, 1] * 50)
for name, targets, rate in [
("support only", support, 0.1),
("support only, gentle", support, 0.01),
("mixed with pets", mixed, 0.1),
]:
tuned = train(list(pretrained), targets, rate)
print(f"{name:22} pets {mass(tuned, ['cat', 'dog']):.2f} support {mass(tuned, ['invoice', 'password']):.2f}")
print(f"{'before tuning':22} pets {mass(pretrained, ['cat', 'dog']):.2f} support {mass(pretrained, ['invoice', 'password']):.2f}")It prints:
support only pets 0.04 support 0.96
support only, gentle pets 0.62 support 0.38
mixed with pets pets 0.35 support 0.65
before tuning pets 0.95 support 0.05Before tuning, the model puts 0.95 of its probability on pets. After training on support words only, the pet share collapses to 0.04 and the support share rises to 0.96: the old behaviour is gone. A gentler rate keeps more of it (pets 0.62), but it also learns the new task less well in the same number of steps (support 0.38). Mixing pet examples in as the model trains keeps a real share on pets (0.35) while it still learns the new words (0.65). Real models are far larger and more flexible than this one, so forgetting is rarely as total, but the shape of the trade-off is the same.
Measure it
- Pick the skills to keep. A small set of general questions, safety cases and the main behaviours your product relies on.
- Score the base model first. Use fixed prompts and the same scoring method you will use afterwards.
- Score the tuned model on the same set. Compare the new task and the old skills side by side.
- Decide what loss you can accept. A small drop in a skill you do not use may be fine. A drop in safety behaviour may not be.
Ways to limit forgetting
- Lower learning rate or fewer steps. Smaller moves keep the weights closer to where they were. Neither guarantees that skills survive, so measure.
- Mix in replay examples. Add general examples that you may use, such as instruction pairs of the kind the original model handled well, at a modest share of each batch. Check that the mixture does not lower the new task's score.
- Train fewer weights. Parameter-efficient methods like LoRA keep the base weights frozen and train a small adapter. That limits how far the model can drift, and it lets you switch the adapter off to get the original behaviour back. The adapter can still change outputs, so it needs the same testing.
- Keep the original. Always keep the Base modelAn existing trained model chosen as the starting point for additional training or adaptation. available to run the same inputs through.
When forgetting is acceptable
If the tuned model will only ever do one narrow job, losing unrelated skills may not matter, and a narrow model is simpler to test. The danger comes when users can send it anything. In that case, plan for general behaviour in your evaluation set from the start.
- ListWrite the skills the tuned model must keep.
- BaselineScore the base model on them with fixed prompts.
- Tune gentlyUse a small rate, few steps or an adapter.
- CompareScore the old skills again and read what changed.
- AdjustMix in replay examples or train less if the loss is too large.
What is catastrophic forgetting?
After tuning on support tickets, a model forgets how to summarise.
The weights move to fit the new task and lose ground on others.
How can mixed data help?
You must keep general skills.
Replaying old behaviour reminds the model of it.
Which gentler setting reduces forgetting?
The model changes too much.
Smaller changes keep the weights closer to the starting point.
Your reading position is saved
0 of 36 complete
Lesson complete
Catastrophic forgetting
Up next