Metalearning Continual Learning Algorithms β part 2/5
Cleaned-text code points [15592, 30777). Bibliography omitted here; source.md includes it.
The dynamics of an SRWM layer ( Irie et al., 2022c ) are described as follows. Let d in d_{\text{in}} , d out d_{\text{out}} , t t be positive integers, and β \otimes denote outer product. At each time step t t , an SRWM πΎ t β 1 β β ( d out + 2 β d in + 1 ) Γ d in {\bm{W}}_{t-1}\in\mathbb{R}^{(d_{\text{out}}+2*d_{\text{in}}+1)\times d_{\text{in}}} observes an input π t β β d in {\bm{u}}_{t}\in\mathbb{R}^{d_{\text{in}}} , and outputs π t β β d out {\bm{o}}_{t}\in\mathbb{R}^{d_{\text{out}}} , while also updating itself from πΎ t β 1 {\bm{W}}_{t-1} to πΎ t {\bm{W}}_{t} as: [ π t , π t , π t , Ξ² t ] \displaystyle[{\bm{o}}_{t},{\bm{k}}_{t},{\bm{q}}_{t},\beta_{t}] = πΎ t β 1 β π t \displaystyle={\bm{W}}_{t-1}{\bm{u}}_{t} (1) π t = πΎ t β 1 β Ο β ( π t ) \displaystyle{\bm{v}}_{t}={\bm{W}}_{t-1}\phi({\bm{q}}_{t}) ; π Β― t = πΎ t β 1 Ο ( π t ) \displaystyle;\,\bar{{\bm{v}}}_{t}={\bm{W}}_{t-1}\phi({\bm{k}}_{t}) (2) πΎ t = πΎ t β 1 + Ο β‘ ( CLOSE \displaystyle{\bm{W}}_{t}={\bm{W}}_{t-1}+\sigma( OPEN Ξ² t ) β ( π t β π Β― t ) β Ο β‘ ( π t ) \displaystyle\beta_{t})({\bm{v}}_{t}-\bar{{\bm{v}}}_{t})\otimes\phi({\bm{k}}_{t}) (3) where π t , π Β― t β β ( d out + 2 β d in + 1 ) {\bm{v}}_{t},\bar{{\bm{v}}}_{t}\in\mathbb{R}^{(d_{\text{out}}+2*d_{\text{in}}+1)} are value vectors, π t β β d in {\bm{q}}_{t}\in\mathbb{R}^{d_{\text{in}}} and π t β β d in {\bm{k}}_{t}\in\mathbb{R}^{d_{\text{in}}} are query and key vectors, and Ο β‘ ( Ξ² t ) β β \sigma(\beta_{t})\in\mathbb{R} is the learning rate. Ο \sigma and Ο \phi denote sigmoid and softmax functions respectively. Ο \phi is typically also applied to π t {\bm{u}}_{t} in Eq. 1 ; here we follow Irie et al. (2022c) βs few-shot image classification setting, and use the variant without it. Eq. 3 corresponds to a rank-one update of the SRWM, from πΎ t β 1 {\bm{W}}_{t-1} to πΎ t {\bm{W}}_{t} , through the delta learning rule ( Widrow and Hoff, 1960 ; Schlag et al., 2021 ) where the self-generated patterns, π t {\bm{v}}_{t} , Ο β‘ ( π t ) \phi({\bm{k}}_{t}) , and Ο β‘ ( Ξ² t ) \sigma(\beta_{t}) , play the role of target , input , and learning rate of the learning rule respectively. The delta rule is crucial for the performance of LTs ( Schlag et al., 2021 ; Irie et al., 2021a ; Irie et al., 2022b ; Irie and Schmidhuber, 2023b ; Yang et al., 2024b ; Yang et al., 2024a ) .
The initial weight matrix πΎ 0 {\bm{W}}_{0} is the only set of trainable parameters of this layer, which encodes the seed self-modification algorithm. We use the multi-head version of the computation above ( Irie et al., 2022c ) to directly replace the multi-head self-attention layer in the Transformer, yielding a βRecursive Self-Transformerβ.
4-learning-rate version. In practice, we use the β4-learning rateβ version ( Irie et al., 2022c ) of SRWM that learns to use different learning rates for each of βoβ, βkβ, βqβ, β Ξ² \beta β sub-blocks of πΎ t β 1 {\bm{W}}_{t-1} by splitting πΎ t β 1 {\bm{W}}_{t-1} into sub-matrices: πΎ t β 1 = [ πΎ t β 1 o , πΎ t β 1 k , πΎ t β 1 q , πΎ t β 1 b ] {\bm{W}}_{t-1}=[{\bm{W}}^{o}_{t-1},{\bm{W}}^{k}_{t-1},{\bm{W}}^{q}_{t-1},{\bm{W}}^{b}_{t-1}] that produce π t {\bm{o}}_{t} , π t {\bm{k}}_{t} , π t {\bm{q}}_{t} , and Ξ² t \beta_{t} , respectively, in Eq. 1 . As we use 4 learning rates, the dimension of πΎ t β 1 {\bm{W}}_{t-1} becomes β ( d out + 2 β d in + 4 ) Γ d in \mathbb{R}^{(d_{\text{out}}+2*d_{\text{in}}+4)\times d_{\text{in}}} , and Ξ² t = [ Ξ² t o , Ξ² t k , Ξ² t q , Ξ² t b ] β β 4 \beta_{t}=[\beta^{o}_{t},\beta^{k}_{t},\beta^{q}_{t},\beta^{b}_{t}]\in\mathbb{R}^{4} . For example, the corresponding update equations for the βoβ-part πΎ t β 1 o {\bm{W}}^{o}_{t-1} are: π t q = πΎ t β 1 o β Ο β ( π t ) \displaystyle{\bm{o}}^{q}_{t}={\bm{W}}^{o}_{t-1}\phi({\bm{q}}_{t}) ; π t k = πΎ t β 1 o Ο ( π t ) \displaystyle;\,{\bm{o}}^{k}_{t}={\bm{W}}^{o}_{t-1}\phi({\bm{k}}_{t}) (4) πΎ t o = πΎ t β 1 o + Ο β‘ ( CLOSE \displaystyle{\bm{W}}^{o}_{t}={\bm{W}}^{o}_{t-1}+\sigma( OPEN Ξ² t o ) β ( π t q β π t k ) β Ο β‘ ( π t ) \displaystyle\beta^{o}_{t})({\bm{o}}^{q}_{t}-{\bm{o}}^{k}_{t})\otimes\phi({\bm{k}}_{t}) (5) where π t q {\bm{o}}^{q}_{t} and π t k {\bm{o}}^{k}_{t} denote the βoβ-part of π t {\bm{v}}_{t} and π Β― t \bar{{\bm{v}}}_{t} in Eq. 2 respectively, and Ξ² t o β β \beta^{o}_{t}\in\mathbb{R} is one of the four learning rates that is dedicated to the βoβ-part. The update equations for πΎ t β 1 q {\bm{W}}^{q}_{t-1} , πΎ t β 1 k {\bm{W}}^{k}_{t-1} , πΎ t β 1 Ξ² {\bm{W}}^{\beta}_{t-1} are analogous.
## 3 Method
Here we describe the proposed approach, Automated Continual Learning (ACL).
Problem Formalization. Building on the formulation of learning as sequence processing (Sec. 2.2 ), we formulate continual learning also as a long-span sequence learning task. Let D D , N N , K K , L L denote positive integers. Consider two N N -way classification tasks π {\mathbf{A}} and π {\mathbf{B}} to be learned sequentially (this can be straightforwardly extended to more tasks). We denote the respective training datasets as π \mathcal{A} and β¬ \mathcal{B} , and test sets as π β² \mathcal{A^{\prime}} and β¬ β² \mathcal{B^{\prime}} . The formulation here applies to both βmeta-trainingβ and βmeta-testβ phases (see Appendix A.1 for more on this terminology). We assume that each datapoint in these datasets consists of one input feature π β β D {\bm{x}}\in\mathbb{R}^{D} of dimension D D (generically denoted as vector π {\bm{x}} , but it is an image in all our experiments) and one label y β { 1 , β¦ , N } y\in\{1,...,N\} . We consider two sequences of L L training examples ( ( π 1 π , y 1 π ) , β¦ , ( π L π , y L π ) ) \left(({\bm{x}}^{\mathcal{A}}_{1},y^{\mathcal{A}}_{1}),...,({\bm{x}}^{\mathcal{A}}_{L},y^{\mathcal{A}}_{L})\right) and ( ( π 1 β¬ , y 1 β¬ ) , β¦ , ( π L β¬ , y L β¬ ) ) \left(({\bm{x}}^{\mathcal{B}}_{1},y^{\mathcal{B}}_{1}),...,({\bm{x}}^{\mathcal{B}}_{L},y^{\mathcal{B}}_{L})\right) sampled from the respective training sets π \mathcal{A} and β¬ \mathcal{B} . In practice, L = N β K L=NK where K K is the number of training examples for each class. By concatenating these two sequences, we obtain one long sequence representing CL examples to be presented to a (left-to-right processing) auto-regressive sequence model. At the end of the sequence, the model is tasked to make predictions on test/query examples sampled from both π β² \mathcal{A^{\prime}} and β¬ β² \mathcal{B^{\prime}} ; we assume a single query example for each task (hence, without index): ( π π β² , y π β² ) ({\bm{x}}^{\mathcal{A^{\prime}}},y^{\mathcal{A^{\prime}}}) and ( π β¬ β² , y β¬ β² ) ({\bm{x}}^{\mathcal{B^{\prime}}},y^{\mathcal{B^{\prime}}}) respectively; which we further denote as ( π query π , y target π ) ({\bm{x}}^{\mathcal{A}}_{\text{{\color[rgb]{0,0,0}query}}},y^{\mathcal{A}}_{\text{{\color[rgb]{0,0,0}target}}}) and ( π query β¬ , y target β¬ ) ({\bm{x}}^{\mathcal{B}}_{\text{{\color[rgb]{0,0,0}query}}},y^{\mathcal{B}}_{\text{{\color[rgb]{0,0,0}target}}}) for clarity.
Our model is a self-referential NN that modifies its own weight matrices as a function of input observations. To simplify the notation, we denote the state of our self-referential NN as a single SRWM πΎ β {\bm{W}}_{*} (even though the model may contain many of them in practice) where weβll replace β * by various symbols representing the context/inputs fed to the model. Given a sequence ( ( π 1 π , y 1 π ) , β¦ , ( π L π , y L π ) , ( π 1 β¬ , y 1 β¬ ) , β¦ , ( π L β¬ , y L β¬ ) ) \left(({\bm{x}}^{\mathcal{A}}_{1},y^{\mathcal{A}}_{1}),...,({\bm{x}}^{\mathcal{A}}_{L},y^{\mathcal{A}}_{L}),({\bm{x}}^{\mathcal{B}}_{1},y^{\mathcal{B}}_{1}),...,({\bm{x}}^{\mathcal{B}}_{L},y^{\mathcal{B}}_{L})\right) , the model processes one x-y pair as input at a time, from left to right, in an auto-regressive manner. Let πΎ π {\bm{W}}_{\mathcal{A}} denote the state of the SRWM that has consumed the first part of the sequence, i.e., the examples from Task π {\mathbf{A}} , ( π 1 π , y 1 π ) , β¦ , ( π L π , y L π ) ({\bm{x}}^{\mathcal{A}}_{1},y^{\mathcal{A}}_{1}),...,({\bm{x}}^{\mathcal{A}}_{L},y^{\mathcal{A}}_{L}) , and let πΎ π , β¬ {\bm{W}}_{\mathcal{A},\mathcal{B}} denote the state of the SRWM after having observed the entire sequence.
ACL Meta-Training Objectives. The ACL meta-training objective consists in correctly predicting the target for queries of all the tasks learned so far, at every task boundary. That is, in the case of two-task scenario described above (learning Task π {\mathbf{A}} then Task π {\mathbf{B}} ), we use the weight matrix πΎ π {\bm{W}}_{\mathcal{A}} to predict the label y target π y^{\mathcal{A}}_{\text{{\color[rgb]{0,0,0}target}}} from input ( π query π , β
) ({\bm{x}}^{\mathcal{A}}_{\text{{\color[rgb]{0,0,0}query}}},\varnothing) ; and we use the weight matrix πΎ π , β¬ {\bm{W}}_{\mathcal{A},\mathcal{B}} to predict the label y target β¬ y^{\mathcal{B}}_{\text{{\color[rgb]{0,0,0}target}}} from input ( π query β¬ , β
) ({\bm{x}}^{\mathcal{B}}_{\text{{\color[rgb]{0,0,0}query}}},\varnothing) as well as the label y target π y^{\mathcal{A}}_{\text{{\color[rgb]{0,0,0}target}}} from input ( π query π , β
) ({\bm{x}}^{\mathcal{A}}_{\text{{\color[rgb]{0,0,0}query}}},\varnothing) . Figure 1 provides an illustration.
Let p β‘ ( y | π ; πΎ β ) p(y|{\bm{x}};{\bm{W}}_{*}) denote the modelβs output probability for label y β { 1 , . . , N } y\in\{1,..,N\} given input π {\bm{x}} and model state πΎ β {\bm{W}}_{*} . The ACL objective can be expressed as: β‘ m β i β n β i β m β i β z β e ΞΈ β ( log β‘ ( p β‘ ( y target π | π query π ; πΎ π β ( ΞΈ ) ) ) + log β‘ ( p β‘ ( y target β¬ | π query β¬ ; πΎ π , β¬ β ( ΞΈ ) ) ) + log β‘ ( p β‘ ( y target π | π query π ; πΎ π , β¬ β ( ΞΈ ) ) ) ) \displaystyle\mathop{\text{}}{minimize}_{\theta}-\left(\log(p(y^{\mathcal{A}}_{\text{{\color[rgb]{0,0,0}target}}}|{\bm{x}}^{\mathcal{A}}_{\text{{\color[rgb]{0,0,0}query}}};{\bm{W}}_{\mathcal{A}}{\color[rgb]{0,0,0}(\theta)}))+\log(p(y^{\mathcal{B}}_{\text{{\color[rgb]{0,0,0}target}}}|{\bm{x}}^{\mathcal{B}}_{\text{{\color[rgb]{0,0,0}query}}};{\bm{W}}_{\mathcal{A,B}}{\color[rgb]{0,0,0}(\theta)}))+\log(p(y^{\mathcal{A}}_{\text{{\color[rgb]{0,0,0}target}}}|{\bm{x}}^{\mathcal{A}}_{\text{{\color[rgb]{0,0,0}query}}};{\bm{W}}_{\mathcal{A,B}}{\color[rgb]{0,0,0}(\theta)}))\right) (6) for an arbitrary meta-training sequence ( ( π 1 π , y 1 π ) , β¦ , ( π L π , y L π ) , ( π 1 β¬ , y 1 β¬ ) , β¦ , ( π L β¬ , y L β¬ ) ) \left(({\bm{x}}^{\mathcal{A}}_{1},y^{\mathcal{A}}_{1}),...,({\bm{x}}^{\mathcal{A}}_{L},y^{\mathcal{A}}_{L}),({\bm{x}}^{\mathcal{B}}_{1},y^{\mathcal{B}}_{1}),...,({\bm{x}}^{\mathcal{B}}_{L},y^{\mathcal{B}}_{L})\right) (extensible to mini-batches using multiple such sequences), where ΞΈ \theta denotes the model parameters (e.g., initial weights πΎ 0 {\bm{W}}_{0} for an SRWM layer) which are trained using βmemory-efficientβ backpropagation through time of Irie et al. (2022c) .
The ACL objective function above (Eq. 6 ) is simple but encapsulates desiderata of continual learning (Sec. 2.1 ). The last term of Eq. 6 with p β‘ ( y target π | π query π ; πΎ π , β¬ ) p(y^{\mathcal{A}}_{\text{{\color[rgb]{0,0,0}target}}}|{\bm{x}}^{\mathcal{A}}_{\text{{\color[rgb]{0,0,0}query}}};{\bm{W}}_{\mathcal{A,B}}) or schematically π β‘ ( π β² | π , β¬ ) {\bm{p}}(\mathcal{A}^{\prime}|\mathcal{A},\mathcal{B}) , optimizes for backward transfer : (1) remembering the first task π {\mathbf{A}} after learning π {\mathbf{B}} (combatting catastrophic forgetting), and (2) leveraging learning of π {\mathbf{B}} to improve performance on the past task π {\mathbf{A}} . The second term of Eq. 6 , p β‘ ( y target β¬ | π query β¬ ; πΎ π , β¬ ) p(y^{\mathcal{B}}_{\text{{\color[rgb]{0,0,0}target}}}|{\bm{x}}^{\mathcal{B}}_{\text{{\color[rgb]{0,0,0}query}}};{\bm{W}}_{\mathcal{A,B}}) or π β‘ ( β¬ β² | π , β¬ ) {\bm{p}}(\mathcal{B}^{\prime}|\mathcal{A},\mathcal{B}) , optimizes forward transfer leveraging the past learning experience of π {\mathbf{A}} to improve predictions in the second task π {\mathbf{B}} , in addition to simply learning to solve Task π {\mathbf{B}} from the corresponding demonstrations. Finally, the first term of Eq. 6 incentivizes the model to learn Task π {\mathbf{A}} as soon as Task π {\mathbf{A}} demos are observed.
Overall Model Architecture. As discussed in Sec. 2.3 , in our model, the core sequential dynamics of CL are learned by the self-referential layers. However, as an image-processing NN, our model makes use of a vision backend: We use the βConv-4β architecture ( Vinyals et al., 2016 ) in all our experiments, except in the last one where we use a pre-trained vision Transformer ( Dosovitskiy et al., 2021 ) . Overall, the model takes an ( π {\bm{x}} /image, y y /label)-pair as input; the image is processed through a feedforward vision NN to yield a feature vector, and the label is encoded as a one-hot vector. We concatenate these two vectors, and feed it to a linear projection layer to obtain the input ( π t {\bm{u}}_{t} ; Eq. 1 ) for the first SRWM layer. Note that this is one of the limitations of this work: more general ACL should also learn to self-modify the vision components. 2 2 2 One βstraightforwardβ architecture fitting the bill is the MLP-mixer architecture ( Tolstikhin et al. (2021) ; built of several linear layers), where all linear layers are replaced by the self-referential linear layers of Sec. 2.3 . While we implemented such a model, it turned out to be too slow for us to conduct corresponding experiments. Our code includes a βself-referential MLP-mixerβ implementation, but for further experiments, future work on such an architecture may require a more efficient implementation.
Another crucial architectural choice that is specific to continual/multi-task image processing is normalization layers (see also related discussion in Bronskill et al. (2020) ). Typical NNs used in few-shot learning (e.g., Vinyals et al. (2016) ) contain batch normalization layers (BN; Ioffe and Szegedy (2015) ) in the vision backend. All our models use instance normalization (IN; Ulyanov et al. (2016) ) instead of BN because in our preliminary experiments, we expectably found IN to generalize much better than BN layers in the CL setting.
## 4 Experiments
98.2
54.6
46.2
53.0
81.5
51.8
68.2
52.5
### 4.1 Two-Task Setting: Comprehensible Study
Similar to how conventional learning algorithms suffer from catastrophic forgetting in the continual learning setting, we first show that in-context learning also suffers from βin-context catastrophic forgetting,β and that the ACL method (Sec. 3 ) can effectively help overcome it. As a minimal case to illustrate this, we focus on the two-task βdomain-incrementalβ CL setting (see Appendix A.1 for details regarding this standard CL terminology). We consider two scenarios for meta-training datasets to be used to sample tasks : Omniglot ( Lake et al., 2015 ) and Mini-ImageNet ( Vinyals et al., 2016 ; Ravi and Larochelle, 2017 ) ; or FC100 ( Oreshkin et al. (2018) , based on CIFAR100; Krizhevsky (2009) ) and Mini-ImageNet (see Appendix A.2 for data details). The order of the datasets used to sample the two tasks within the meta-training sequences is alternated for every batch. We compare the models with and without the backward transfer term in the ACL loss (the last term in Eq. 6 ).