Continual Learning from the Perspective of Compression
Abstract
Connectionist models such as neural networks suffer from catastrophic forgetting.
In this work, we study this problem from the perspective of information theory and deﬁne forgetting as the increase of description lengths of previous data when they are compressed with a sequentially learned model.
In addition, we show that continual learning approaches based on variational posterior approximation and generative replay can be considered as approximations to two prequential coding methods in compression, namely, the
Bayesian mixture code and maximum likelihood (ML) plug-in code.
We compare these approaches in terms of both compression and forgetting and empirically study the reasons that limit the performance of continual learning methods based on variational posterior approximation.
To address these limitations, we propose a new continual learning method that combines ML plug-in and
Bayesian mixture codes.
1. Introduction
When sequentially learning a non-stationary data stream, neural networks usually suffer from the problem of catastrophic forgetting when the data from the past are not available anymore (McCloskey & Cohen, 1989).
Recently, this problem has received renewed attention within the ﬁeld of deep learning, and a ﬂurry of methods (see (Parisi et al., 2019) for a survey) have been proposed to address this issue in order to achieve the goal of continual learning (CL)
(Ring, 1998).
Intuitively speaking, forgetting can be understood as loss of information about past data.
Previous studies on this problem have indirectly measured forgetting by degradation of task-speciﬁc performance metrics such as classiﬁcation accuracy (Lopez-Paz & Ranzato, 2017), regression error (Javed & White, 2019) or the Frechet Inception Distance (FID) (Lesort et al., 2019).
In order to explicitly study the problem of information loss, here we place continual learning within the framework of information theory and
Minimum Description Length (MDL) (Gr¨unwald, 2007).
According to the MDL principle, any regularity within a dataset can be used for compression, and the best model for a given dataset is the one that results in the minimum total description length of the dataset together with the model itself.
Therefore, MDL formalizes the Occam’s Razor principle for machine learning and provides a criterion for model selection.
Other inspirations and foundations for MDL include the “comprehension is compression” hypothesis by
Chaitin (Chaitin, 2002) and Solomonoffs theory of inductive inference (Solomonoff, 1964), which proved that the most likely explanation of some observations of the world is the smallest computer program (in terms of its Kolmogrov
Complexity (Kolmogorov, 1968)) that generates these observations, assuming the world is generated by an unknown computer.
The compression perspective has provided insights in various problems in machine learning, including generalization (Arora et al., 2018), unsupervised modeling (Ollivier, 2014) and information bottleneck (Tishby & Zaslavsky, 2015).
Recently, (Blier & Ollivier, 2018) showed that one particular coding method from the MDL toolbox called prequential coding outperforms the other coding methods at explaining why deep learning models generalize well despite their large number of parameters, displaying strong correlation between generalization and compression.
In this work, we show that the compression perspective can also shed light on continual learning.
Our contributions are:
• We provide a formal deﬁnition of forgetting based on information theory, which allows us to evaluate continual learning methods for generative models in a principled way.
• We show that two major paradigms of continual learning (variational continual learning and generative replay) can be interpreted as approximations of two prequential coding methods (Bayesian mixture coding and ML plug-in coding) in the MDL framework, thus establishing a connection between continual learning and a r X i v : . 15078v [ c s .
G ]
J un compression. • We compare different CL methods for continual generative modeling using the proposed deﬁnition of forgetting and empirically study the limitations of the variational continual learning approaches.
• We introduce a new CL method that combines the prediction strategies of the two prequential coding methods and show that it improves over the variational continual learning.
2. Minimum Description Length
Formally, given a dataset x n := { x 1 , . . .
, x n } where each x i is from a space of observation X , the overall description length of x n under the model with parameters θ can be separated into two parts:
[Equation]
The ﬁrst part L ( x n | θ ) describes the codelength (number of bits) of x n when compressed with the help of a model parametrized by θ , and the second part L ( θ ) corresponds to the codelength of the model itself.
A model with more capacity can ﬁt the data better, thus resulting in shorter codelength of the ﬁrst part.
However, higher capacity might also lead to longer description length of the model itself.
Therefore, the best explanation for x n , according to MDL, is given by the model that minimizes the total length L ( x n ) .
For probabilistic models, the code length L ( x n | θ ) can be computed using the Shannon-Fano code.
Shannon-Fano Code Let p ( x | θ ) be a probability density (or mass) function over X determined by parameters θ , then for any x ∈ X , there exists a preﬁx code that losslessly compresses x with code length
[Equation]
In this work, we use the codelength function L only as a metric to measure the amount of information and do not care about the actual encoding of data, hence we adopt the idealized view of code lengths which does not require them to be integers.
Bayesian Code One way to encode the parameters θ is to consider these parameters also as random variables and use the following Bayesian coding scheme:
[Equation]
where (4) is the evidence lower bound (ELBO) used in variational Bayesian methods.
The equality holds when q ( θ | x n ) =
p ( θ | x n ) .
The ﬁrst term corresponds to L ( x n | θ ) , describing the expected code length of x n if encoded with θ sampled from the approximate posterior q ( θ | x n ) .
The second term corresponds to L ( θ ) , describing the code length of θ using the bits-back coding (Hinton & Van Camp, 1993) with a ﬁxed prior distribution p ( θ ) .
Prequential (Online) Code Another way to compute the total description length
L ( x n ) without explicitly separating
L ( x n ) into two parts is to use the prequential or online code, which considers a dataset x n as a sequence of observations and encode each observation x t at time t by predicting its value based on past observations x t − 1 .
Note that for any x t , we can write its Shannon-Fano code as a sum of negative log conditional probabilities:
[Equation]
Hence the total description length can be computed by accumulating the code length − log p ( x t | x t − 1 ) at every step t using a prediction strategy.
Formally, a prediction strategy is a function S : (cid:83) 0 ≤ t ≤ n X t → P X that maps any initial observations x t − 1 to a distribution on X corresponding to the conditional model p ( X t | x t − 1 ) .
For example, Bayesian mixture code uses the following prediction strategy:
[Equation]
where p ( θ | x t − 1 ) is the posterior of model parameters given all previous data x t − 1 .
Another example of prequential coding is the maximum likelihood (ML) plug-in code , which encodes each observation by
[Equation]
where θ ( x t − 1 ) is given by a maximum likelihood estimator:
[Equation]
As we will show in the next section, this online incremental view of prequential coding is well-aligned with the setting of continual learning.
3. Continual Learning
Continual learning studies the scenario where data are provided at different time in a sequential manner, and the learning algorithm incrementally updates the model parameters as more data are presented.
However, due to reasons such as privacy or limited memory budget, the learning algorithm may not always store all the data x t − 1 it has seen so far.
Alternatively, even if all data are stored, naively retraining on all previous data will increase the run time per step over time, which may not be affordable for long data streams.
On the other hand, if the model is only trained on the data presented recently, it usually suffers from “catastrophic forgetting”.
This problem is especially severe when the data stream is non-stationary.
Here we provide a deﬁnition of forgetting that allows us to precisely measure the amount of information forgotten.
3.1. An Information-Theoretic Deﬁnition of Forgetting
We can see from (1) that when the data x n is compressed with the help of a model, the information of x n is divided into two parts, with one part contained in the code words of x n and the other part contained in the model.
Hence, the model alone is not enough to recover the data losslessly, it requires also the code words of the compressed data, which can be understood as the information of x n not captured by the model.
This intuition leads to our deﬁnition of forgetting: for any data x , the amount of forgetting about x caused by changing the model parameters from θ i to θ j is given as the increase of the codelength of x :
[Equation]
In other words, the number of extra bits required for the model to losslessly recover x is the amount of information the model has forgotten about x .
The max( · , 0) function in (9) is used to prevent “negative forgetting”, if the codelength does not increase, there is no forgetting.
In the prequential setting, at any time t , we can measure the cumulative average forgetting of a learning algorithm over the entire sequence x t seen so far by the following metric:
[Equation]
where θ i are the parameters given by the learning algorithm at time i , after seeing x i .
3.2. Prequential Interpretation of CL Approaches
A primary goal of continual learning is to overcome or to alleviate catastrophic forgetting.
Many CL methods have been proposed for this purpose (Parisi et al., 2019).
Some common paradigms emerged from these methods.
One paradigm is based on the sequential nature of Bayesian inference and it applies variational methods to approximating the parameter posterior.
The approximated posterior is then used as the prior for future learning.
Examples of this paradigm include Bayesian Online Learning (Opper, 1998),
Variational Continual Learning (VCL) (Nguyen et al., 2018) and Online Structured Laplace Approximations (Ritter et al., 2018).
Some regularization-based CL methods such as Elastic Weight Consolidation (EWC) (Kirkpatrick et al., 2017) and Uncertainty-guided Continual Bayesian Neural Networks (UCB) (Ebrahimi et al., 2020) are also motivated by this idea.
Another paradigm combats forgetting by training a generative model of past data.
When new data are provided later, the samples from the generative model are replayed instead of the original data.
Representative works of this class are Deep Generative Replay (DGR)
(Shin et al., 2017), Memory Replay GAN (Wu et al., 2018) and Continual Unsupervised Representation Learning (CURL) (Rao et al., 2019).
Farquhar & Gal (2019) proposed a unifying
Bayesian view that encompasses both paradigms.
From the perspective of MDL, these two types of approaches can be seen as approximations of the two prequential coding methods introduced before.
We discuss their relationships below using VCL and Generative Replay as examples.
VCL
The ﬁrst paradigm corresponds to the Bayesian mixture code, which uses (6) as its prediction strategy.
Since the exact posterior p ( θ | x t − 1 ) in (6) depends on all previous data x t − 1 , which might not always be available in the continual learning scenario, VCL therefore uses a variational model q ( θ | x t − 1 ) to approximate the real posterior p ( θ | x t − 1 ) .
By the Bayes’ rule, we have
[Equation]
where Z t := (cid:82) θ p ( x t | θ ) p ( θ | x t − 1 ) is a normalizing factor that does not depend on θ .
Therefore, q ( θ | x t ) can be updated recursively by minimizing the following KL divergence at every step t :
[Equation]
The ﬁrst approximate posterior q ( θ | x 0 ) is usually a ﬁxed prior chosen before learning starts:
q ( θ | x 0 ) =
p ( θ ) .
Since
Z t does not depend on θ , it is not required for the optimization above.
The second paradigm, on the other hand, corresponds to the ML plug-in code, which uses the prediction strategy deﬁned in (7) and (8).
The objective function in (8) requires all previous data x t − 1 .
In order to relax this requirement for continual learning, replay-based methods approximate the real objective function using a generative model p ( x | θ ) .
Assuming x i
∈ x t are independent given θ , we have:
[Equation]
where θ t − 1 are the parameters of the generative model at time t − 1 and the expected value can be computed by Monte
Carlo sampling.
In this way the generative model can be recursively updated by the following rule:
[Equation]
Measuring Forgetting and Compression We empirically compare the two prequential coding methods and their continual learning approximations in terms of both forgetting and compression on the MNIST dataset.
Data are presented in a class-incremental fashion: ﬁrst only images of digit zero, then only images of digit one, and so on.
Throughout the paper, we use a variational autoencoder (VAE)(Kingma & Welling, 2013) for encoding and generative modelling.
In this experiment, one observation corresponds to an entire class of images.
Fig.1 shows the cumulative average forgetting after learning each digit.
Since ML plug-in and Bayesian Mixture methods are trained on all data seen so far, they have almost zero forgetting.
VCL and Replay, on the other hand, do not have access to previous data, so information are lost over time.
However, thanks to the variational posterior and generated samples, they achieve less forgetting than the Catastrophic baseline, which only trains the model on images of the current digit.
The results on prequential coding as deﬁned in (5) are shown in Fig.
After all the images of one class are presented, the model is updated and used to encode all the images of the next class.
The left plot shows the codelength of each class, since models are only trained on the images from previous classes, the results shown here correspond to the concept of forward transfer in continual learning.
We can see that
Bayesian Mixture and VCL have high codelength at the beginning, when there is no forgetting yet.
The reason for this phenomenon is discussed in Sec. 4.1.
The plot on the right shows the prequential codelength of the entire MNIST dataset measured in bits per dimension.
4. Limitations of VCL
It can be seen from both Fig.1 and 2, VCL performs poorly compared to generative replay.
A systematic comparison
[Figure]
between VCL and replay on discriminative tasks was carried out by Farquhar & Gal (2018).
VCL was reported to work similarly to generative replay on simple tasks like Permuted
MNIST.
On the more challenging Split MNIST task, VCL requires both a multi-head output layer and a coreset of past examples in order to be comparable with generative replay.
For generative modeling, the results in Fig.
1 conﬁrm the limitation of VCL at retaining information of past data.
In this section, we analyze the reasons that limit the performance of VCL.
4.1. Overhead of Bayesian Mixture due to Prior
With deep generative models, the integration in Bayesian mixture code deﬁned in (6) is intractable because p ( x | θ ) is a neural network generator.
Therefore, the ELBO is used in practice as an approximation, which adapts q ( θ ) in (4) to minimize the total description length.
We make two observations here.
First, in VCL, the best achievable description length is predetermined by the selected prior p ( θ ) .
Second, compared to ML plug-in code, which directly minimizes the encoding length L ( x | θ ) , the approximate Bayesian code has an extra KL regularization, indicating a longer description length L ( x | θ ) for the code words.
Furthermore, since we do not explicitly encode data and keep their code words in continual learning, a larger encoding length means more information is lost about the data.
This overhead is negligible asymptotically if the data sequence is very long.
This can be seen from the relative [Figure] [Figure] [Figure]
u
[Figure]
n t
i
[Figure]
l C o d e l
[Figure]
n g t
[Figure]
bpd
[Figure]
[Figure]
[Figure]
weights of the two terms in (4).
The relative weight of the
KL regularization diminishes when the data sequence grows longer.
This is why we see a high initial codelength for
Bayesian Mixture in Fig.
2 (a), but gradually it closes the gap to ML plug
However, for a sequence with ﬁxed length, the overhead due to prior can be signiﬁcant and is very sensitive to the choice of the prior.
Figure 3 compares the prequential codelength of
Bayesian Mixture code using Gaussion priors with different standard deviation σ .
One can see that good performance can be achieved only when σ is within a small region around 0 .
And the best description length is obtained when the prior is not used.
Similar effects were observed for VCL in (Swaroop et al., 2019), where the authors showed the choice of prior variance has great impact on the performance of
VCL.
4.2. The Variational Gap
As we describe before, in continual learning, the true posterior p ( θ | x t − 1 ) is not available, thus VCL approximates it with a variational posterior q ( θ | x t − 1 ) .
The underlying assumption is that when their KL divergence is small enough:
[Equation]
KL [
[Equation]
] <
[Equation]
, the following approximations are good enough for continual learning:
[Equation]
However, for VCL with a simple distribution family such as diagonal Gaussian, this assumption can hardly hold, as the real posterior is proportional to p ( x t − 1 | θ ) p ( θ ) , which is usually complex and multimodal.
Since the only difference between VCL and Bayesian Mixture code is the substitution of (17) by (18), the error between these two terms is entirely responsible for their large performance gap observed in Fig.
and 2.
One potential remedy to this problem is to use more complex distributions on the parameter space, for example, normalizing ﬂow as a Bayesian hypernetwork (Krueger et al., 2017).
However, unlike Gaussian distributions, the KL divergence of complex distributions usually cannot be calculated analytically.
It is also unclear whether sampling in the parameter space to minimize D KL [ q ( θ | x t − 1 ) (cid:107) p ( θ | x t − 1 )] would be any cheaper than sampling in the data space for replay.
Furthermore, the approximation error between (17) and (18) could be arbitrarily large even if [Figure] n t i
[Figure]
l
[Figure] l e n g t h [Figure] D KL [ q ( θ | x t − 1 ) (cid:107) p ( θ | x t − 1 )] < (cid:15) , which only states that log q ( θ | x t − 1 ) p ( θ | x t − 1 ) is small in its expectation over the distribution q ( θ | x t − 1 ) .
As shown in (19), the approximation error is the expectation of the same log ratio over q ( θ | x t − 1 ) p ( x t | θ ) /Z
t .
Unfortunately, this distribution could be very different from q ( θ | x t − 1 ) .
It depends on p ( x t | θ ) , which is not available at the time q ( θ | x t − 1 ) is solved.
One sufﬁcient condition to bound the substitution error is max θ | log q ( θ | x t [Equation] 1 ) p ( θ | [Equation]
t [Equation] 1 ) | < (cid:15) .
However, this involves an minimax optimization of the log ratio, which is a hard problem itself.
[Equation]
5. ML Mixture Code
In order to overcome the two limitations discussed above, we can combine the prediction strategies of Bayesian mixture and ML plug-in using a hierarchical model with hyperparameters φ .
For diagonal Gaussian distribution, φ stands for the mean and variance of θ .
The resulting prediction strategy, which we call maximum likelihood (ML) mixture , is as follows:
[Equation]
where φ ( x t ) is learned to maximize the following objective:
[Equation]
MLM [Equation] φ t − 1 minimizes L MLM t − 1 ( φ ) and q ∗ t denotes the theoretical optimal posterior that maximizes the ELBO, which means q ∗ t ( θ | x i ) =
p ( θ | x i , φ t ) .
The approximation in (21) is based on the assumption that the previous objective L MLM t − 1 is optimized good enough such that
[Equation]
For continual learning, in order to remove any dependency on previous data or previous approximate posterior
[Equation]
we optimize (21) sequentially in a greedy manner, namely, only the last two terms of (21) are optimized at time t :
[Equation]
Like VCL, the optimization involved in ML Mixture code takes the form of a KL regularization in the parameter space.
It addresses the two above-mentioned limitations of VCL.
First, the prior overhead described in Sec.
4.1 is resolved because the mixture distribution is now optimized via maximum likelihood.
Second, the approximation in (22) is more plausible than (16), because (16) tries to approximate a ﬁxed multimodal distribution with a simple distribution, while (22) has optimizable components on both sides of the approximation.
The performance of ML Mixture code in terms of forgetting and compression are also presented in Fig.1 and 2.
One can see that although both VCL and ML Mixture use diagonal Gaussian for the distribution of model parameters (corresponding to q ( θ | x
t − 1 ) in VCL and p ( θ | φ ) in ML Mixture), ML Mixture achieves much less forgetting and smaller prequential codelength.
5.1. The Intuitive Interpretation
The ML Mixture code is effectively performing ML plug-in coding with a VAE.
Unlike normal VAEs, the latent code includes the entire parameter vector of the decoder.
This means that the mapping from the latent code to the input space is predetermined by the decoder architecture.
Intuitively, ML Mixture projects each data x
i from the input space to a local posterior distribution over the parameter space through the encoder q ( θ | x i ) .
It then uses the prior distribution p ( θ | φ ) to model the projected data in the parameter space.
For each x i , there exists a large number of simple distributions q ( θ | x i ) that can be used as the encoder.
Potentially, one can select the encoder so that the mirrored data points in the parameter space obeys a simple distribution, i.e. 1 n (cid:80) n i q ( θ | x i ) is a simple distribution.
In this case, p ( θ | φ ) which is used to model the mixture distribution can also be kept simple.
One supporting evidence for this possibility is the success of normal VAE/WAE(Tolstikhin et al., 2017).
The prior distribution over the joint vector of latent code and the decoder parameters of VAE/WAE is a diagonal Gaussian, if we see the deterministic parameters as Gaussian random variables with zero variance.
5.2. Limitation and Future Improvements
There are a few limitations of the ML Mixture code that need to be solved before it is practical for continual learning.
First, as we greedily optimize only the last two terms in (21) in a sequential manner, the previous approximate posterior q t − 1 is ﬁxed once learned.
This locks the prior distribution to a local region biased to the early tasks.
As a result, ML
Mixture code learns well and retains the knowledge from early experiences.
However, the description length is only marginally improved at the later tasks (see Appendix A).
A potential ﬁx is to introduce certain level of generative replay to optimize the ﬁrst term in (21).
Second, both VCL and ML
Mixture use approximate objectives to remove dependency on previous data.
Although (22) could be more plausible than (16), the error introduced in the objective could still be arbitrarily large as pointed out earlier in Sec. 4.2.
In the future, it would be preferable to develop an alternative objective for which the approximation error is bounded.
A. Description length on each digit through out training
0 1 2 3 4 5 6 7 8 9 Class ID 0. C o d e l e
[Table] [Table]
a
[Table]
(b)
[Table]
n
[Table]
h
[Table]
(c)
[Table]
(d)
[Table]
(e)
[Table] [Table]
(f) [Table] [Table] n
[Table] [Table]
(g)
[Table]
[Table]
(h)
[Table] [Figure]