With EWC, learning task B after task A proceeds as follows.
- Train on task A as usual and save the resulting weights θA∗.
- Using task A's data, compute the importance of each weight (the diagonal of the Fisher information matrix, Fi) and save it.
- Train on task B with the loss L(θ) below. Task A's data is not used.
- When moving on to task C, add the penalties for both A and B (the sum of two quadratic penalties is itself a quadratic penalty, so they can also be merged into one).
The loss in step 3 is Eq. (3) of the paper.
L(θ)=LB(θ)+i∑2λFi(θi−θA,i∗)2
Here LB(θ) is the loss for task B alone, i indexes the weights, θA,i∗ is the i-th weight after learning task A, Fi is that weight's importance for task A, and λ is a coefficient that sets how much the old task matters relative to the new one. The penalty is a squared distance weighted per weight by Fi, so weights with larger Fi stay closer to θA,i∗.
This formula follows from a probabilistic argument. Rewriting the probability of the weights given all the data D (=DA and DB) with Bayes' theorem gives the following.
logp(θ∣D)=logp(DB∣θ)+logp(θ∣DA)−logp(DB)
The first term on the right is (the negative of) the task B loss, and everything that needs to be known about task A is contained in the second term, p(θ∣DA). Since this is hard to compute exactly, it is approximated by a Gaussian with mean θA∗ and precision (inverse variance) given by the diagonal of the Fisher information matrix F (the Laplace approximation). The log of a Gaussian is quadratic, which yields the penalty in the loss above.
The Fisher information matrix has three properties, listed in the paper, that make it well suited to measuring weight importance.
- Near a minimum, it equals the second derivative (curvature) of the loss: the steeper the curvature in a direction, the more the loss increases with even a small step.
- It can be computed from first derivatives alone: it is easy to compute even for large models.
- It is always positive semidefinite: the penalty is never negative.
In practice, compute the gradient of the model's output log-probability logp(y∣x,θ) on task A data x, and average its square to obtain Fi.
EWC stores only the weights θ∗ and the Fisher information diagonal F for each task, not the past data itself. The amount stored is twice the number of weights, independent of the amount of data.