Neural Differential Equations for Learning to Program Neural Nets Through Continuous Learning Rules
Abstract
Neural ordinary differential equations (ODEs) have attracted much attention as continuous-time counterparts of deep residual neural networks (NNs), and numerous extensions for recurrent NNs have been proposed.
Since the 1980s, ODEs have also been used to derive theoretical results for NN learning rules, e.g., the famous connection between Oja’s rule and principal component analysis.
Such rules are typically expressed as additive iterative update processes which have straightforward ODE counterparts.
Here we introduce a novel combination of learning rules and Neural ODEs to build continuous-time sequence processing nets that learn to manipulate short-term memory in rapidly changing synaptic connections of other nets.
This yields continuous-time counterparts of Fast Weight Programmers and linear Transformers.
Our novel models outperform the best existing Neural Controlled
Differential Equation based models on various time series classification tasks, while also addressing their fundamental scalability limitations.
Our code is public.
Introduction
Neural ordinary differential equations (NODEs) [1] have opened a new perspective on continuoustime computation with neural networks (NNs) as a practical framework for machine learning based on differential equations.
While the original approach—proposed as a continuous-depth version of deep feed-forward residual NNs [2, 3]—only covers autonomous ODEs entirely determined by the initial conditions, more recent extensions deal with sequential data (reviewed in Sec. 2.1) in a way similar to what is typically done with standard recurrent NNs (RNNs) in the discrete-time scenario.
This potential for continuous-time (CT) sequence processing (CTSP) is particularly interesting, since there are many applications where datapoints are observed at irregularly spaced time steps and CT sequence models might better deal with such data than their discrete-time counterparts.
However, the development of NODEs for CTSP is still at an early stage.
For example, a popular approach of
Neural Controlled Differential Equations [4] (NCDEs; also reviewed in Sec. 2.1) has in practice only one architectural variant corresponding to the “vanilla” RNN [5].
Discrete-time processing, however, exploits many different RNN architectures as well as Transformers [6].
While it is not straightforward to transform the standard Transformer into a CT sequence processor, we’ll show that the closely related Fast Weight Programmers (FWPs) [7, 8, 9, 10] and linear Transformers [11] (reviewed in Sec. 2.3) have direct CT counterparts.
In FWPs, temporal processing of short-term memory (stored in fast weight matrices) uses learnable sequences of learning rules .
Hence
CT versions of FWPs will require differential equations to model the learning rules.
This relates to a trend of the 1980s/90s.
Among many old connections between NNs and dynamical systems described by ODEs (e.g., [12, 13, 14, 15, 16, 17]), the theoretical analysis of NN learning rules in the ODE framework has been particularly fruitful.
Consider the famous example of Oja’s rule [18] (briefly reviewed in Sec. 2.2): many results on its stability, convergence, and connection to Principal Component Analysis [19, 20] were obtained using its ODE counterpart (e.g., [18, 21, 22, 23, 24, 25, 26, 27]).
Here we propose a novel combination of Neural ODEs and learning rules, to obtain a new class of sequence processing Neural ODEs which are continuous-time counterparts of Fast Weight Programmers and linear Transformers.
The resulting models are general-purpose CT sequence-processing
NNs, which can directly replace the standard Neural CDE models typically used for supervised CT sequence processing tasks.
To the best of our knowledge, there is no previous work on Neural ODEbased Transformer families for CT sequence processing, despite their popularity in important types of discrete time computation such as Natural Language Processing and beyond.
We also show how our approach solves the fundamental limitation of existing Neural CDEs in terms of model size scalability.
We conduct experiments on three standard time series classification tasks covering various scenarios (regularly sampled, irregularly sampled with missing values, and very long time series).
We demonstrate that our novel models outperform existing Neural ODE-based sequence processors, in some cases by a large margin.
Background
We briefly review the main background concepts this work builds upon: NODEs for sequence processing (Sec. 2.1), NN learning rules and their connection to ODEs (Sec. 2.2), and Fast Weight
Programmers whose memory update is based on learning rules controlled by an NN (Sec. 2.3).
2.1 Neural ODEs (NODEs) and Their Extensions for Sequence Processing
Here we review the core idea of NODEs [1].
In what follows, let n , N , d , d in denote positive integers,
T be a positive real number, and θ denote an arbitrary set of real numbers.
We consider a residual layer (say, the n -th layer with a dimension d ) in an N -layer deep NN which transforms an input h n − 1 ∈ R d to an output h n ∈ R d with a parameterised function f θ : R d → R d as follows:
[Equation]
This coincides [28, 29, 30, 31, 32, 33, 34, 1] with the following equation for ϵ =
[Equation]
where h : [0 , T ] → R d is a function such that h ( t n )
=
h n holds for all n : 0 ≤ n ≤ N and t n ∈ [0 , T ] such that t n − t n − 1 = ϵ > 0 if n ≥ 1 .
This equation is a forward Euler discretisation of the ordinary differential equation defined for all t ∈ ( t 0 , T ] as
[Equation]
where h ′ denotes the first order derivative.
This establishes the connection between the ODE and the deep residual net with parameters θ shared across layers 2 : given the initial condition
h
( t 0 )
=
h 0 , the solution to this equation evaluated at time T , i.e., h ( T ) , corresponds to the output of this deep residual
NN, which can be computed by an ODE solver.
We denote it as a function ODESolve taking four variables: h ( T ) =
ODESolve( f θ , h 0 , t 0 , T ) .
During training, instead of backpropagating through the ODE solver’s operations, the continuous adjoint sensitivity method [35] (which essentially solves another ODE but backward in time) can compute gradients with O ( d ) memory requirement, constant w.r.t.
T [1].
A natural next step is to extend this formulation for RNNs, i.e., the index n now denotes the time step, and we assume an external input x n ∈ R d in at each step n to update the hidden state h n − 1 to h n as
[Equation]
[Equation]
Depending on the property of external inputs ( x n ) Nn =1 = ( x 1 , ...,
[Equation]
) , there are different ways of defining NODEs for sequence processing.
We mainly distinguish three cases.
First , when there is a possibility to construct a differentiable control signal x : t (cid:55)→ x ( t ) ∈ R d in for t ∈ [ t 0 , T ] from the inputs ( x n ) Nn =1 ; an attractive approach by Kidger et al.
[4] handles the corresponding dynamics in a neural controlled differential equation (NCDE):
[Equation]
where F θ is a parameterised function (typically a few-layer NN) which maps a vector h ( s ) ∈ R d to a matrix F θ ( h ( s ))
∈ R
d × d in (we already relate this component to Recurrent Fast Weight Programmers below) and thus, F θ ( h ( s ))
d x ( s ) denotes a matrix-vector multiplication.
There are several methods to construct the control x : [ t 0 , T ] → R d in based on the discrete data points ( x n ) Nn =1 , such that its differentiability is guaranteed.
In this work, we follow Kidger et al.
[4] and mainly use natural cubic splines over all data points (which, however, makes it incompatible with auto-regressive processing); for better alternatives, we refer to Morrill et al.
Since the final equation is again an NODE with a vector field of form g θ, x ′ ( s, h ( s ))
=
F θ ( h ( s )) x ′ ( s ) , all methods described above are applicable:
ODE solver for evaluation and continuous adjoint method for memory efficient training.
A notable extension of Neural CDEs is the use of log-signatures to sub-sample the input sequence [37].
The resulting NCDEs are called neural rough differential equations (NRDEs), which are relevant for processing long sequences.
One fundamental limitation of the NCDEs above is the lack of scalability of F θ : R d → R d × d in .
For example, if we naively parameterise F θ using a linear layer, the size of its weight matrix is d 2 ∗ d in which quadratically increases with the hidden state size d .
Previous attempts [38] do not successfully resolve this issue without performance degradation.
In Sec. 5, we’ll discuss how our models (Sec. 3.2) naturally circumvent this limitation while remaining powerful NCDEs.
On a side note, the NCDE is often referred to as the “continuous-time analogue” to RNNs [4], but this is a bit misleading: discrete-time RNN equations corresponding to the continuous-time Eq.
5 do not reflect the standard RNN of Eq.
4 but:
[Equation]
where one network (Eq. 6) learns to translate the variation of inputs ( x n − x n − 1 ) into a change in the state space, using a weight matrix W n − 1 which itself is generated by another network ( F θ : R d → R d × d in ; Eq. 7) on the fly from the hidden state.
This model is thus a kind of Recurrent
FWP [39, 40, 10].
Second , even if x is not differentiable, having access to x defined and bounded over an interval of interest [ t 0 , T ] is enough to define a sequence processing NODE, by making it part of the vector field:
[Equation]
where the vector field f θ ( h ( t ) , x ( t ))
=
g θ, x ( t, h ( t )) can effectively be evaluated at any time t ∈
[ t 0 , T ] .
We refer to this second approach as a direct NODE method.
While Kidger et al.
[4] theoretically and empirically show that this approach is less expressive than the NCDEs above, we’ll show how in our case of learning rules one can derive interesting models within this framework, which empirically perform on par with the CDE variants.
Finally , when no control function with one of the above properties can be constructed, a mainstream approach dissociates the continuous-time hidden state update via ODE for the time between two observations (e.g., Eq. 9 below) from integration of the new data (Eq. 10 below).
Notable examples of this category include ODE-RNNs [41, 42] which transform the hidden states h n − 1 to h n for each observation x n available at time t n as follows:
[Equation]
where Eq. 9 autonomously updates the hidden state between two observations using a function f θparameterised by θ 1 , while in Eq.
10, function ϕ θ 2 parameterised by θ 2 integrates the new input x n into the hidden state.
In Latent ODE-RNN [41], a popular extension of this approach to the variational setting, the initial recurrent state h 0 is sampled from a prior (during training, an additional encoder is trained to map sequences of inputs to parameters of the prior).
While this third case is not our focus, we’ll also show how to use FWPs in this scenario in Sec.
3.3 for the sake of completeness.
[Equation]
2.2 Learning Rules and Their Connections to ODEs
Learning rules of artificial NNs describe the process which modifies their weights in response to some inputs.
This includes the standard backpropagation rule (also known as the reverse mode of automatic differentiation) derived for the case of supervised learning, as well as rules inspired by Hebb’s informal rule [43] in “unsupervised” settings.
Here we focus on the latter.
Let n , d in d out be positive integers.
Given a linear layer with a weight matrix W n ∈ R d out × d in (the single output neuron case d out = 1 is the focus of the classic works) at time n which transforms input x n ∈ R d in to output y n ∈ R d out as
[Equation]
(11) the pure Hebb-style additive learning rule modifies the weights according to
[Equation]
12) where ⊗ denotes outer product and η n ∈ R + is a learning rate at time n .
Oja [18] proposed stability improvements to this rule through a decay term
[Equation] [Equation]
whose theoretical analysis has since the 1980s been a subject of many researchers covering stability, convergence, and relation to Principal Component Analysis [18, 21, 22, 23, 24, 25, 26, 27, 44].
One key approach for such theoretical analysis is to view the equation above as a discretisation of the following ODE:
[Equation]
On a related note, the study of RNNs has also profited from ODEs (e.g., [45, 46]).
2.3 Fast Weight Programmers & Linear Transformers
Fast Weight Programmers (FWP; [7, 8, 9, 10]) are general-purpose (auto-regressive) sequence processing NNs.
In general, an FWP is a system of two NNs: a slow NN, the programmer , rapidly generates during runtime weight changes of another neural network, the fast NN.
The (slow) weights of the slow net are typically trained by gradient descent.
Variants of FWPs whose weight generation is based on outer products between keys and values [7] have been shown [9] to be equivalent to Linear
Transformers [11] (using the mathematical equivalence known from perceptron/kernel machine duality [47, 48]).
These FWPs use sequences of learning rules to update short-term memory in form of a fast weight matrix.
A practical example of such FWPs is the DeltaNet [9] which transforms an input x n ∈ R d in into an output y n ∈ R d out at each time step n while updating its fast weight matrix
W n − 1 ∈ R d out × d key as follows:
[Equation]
where the slow net (Eq. 15; with weights W slow ∈ R (1+2 ∗ d key + d out ) × d in ) generates key/value vectors k n ∈ R d key and v n ∈ R d out as well as a scalar β n ∈ R to obtain a dynamic learning rate by applying a sigmoid function σ , and ϕ is an element-wise activation function whose output elements are positive and sum up to one (typically softmax).
These fast dynamic variables generated by a slow NN are used in a learning rule (Eq. 16) akin to the classic delta rule [49] to update the fast weight matrix.
The output is finally produced by the forward computation of the fast NN, i.e., by querying the fast weight matrix by the generated query vector q n ∈ R d key (Eq. 17).
An intuitive interpretation of the fast weight matrix is a key-value associative memory with write and read operations defined by Eq.
16 and 17, respectively.
This encourages intuitive thoughts about memory capacity (limited by the number of “keys” we can store without interference) [9].
For instance, if we replace the learning rule (i.e., memory writing operation) of Eq.
16 by a pure additive Hebb-style rule (and a fixed learning rate of 1.0): W n = W n − 1 + v n ⊗ ϕ ( k n ) , we obtain the Linear Transformer [11] (we refer to prior work [9] for further explanations of the omission of attention normalisation).
Such a purely additive learning rule often suffers from long term dependencies, unlike the delta rule [9].
We’ll confirm this trend also in the CT models (using the EigenWorms dataset).
For later convenience, we introduce a notation
FWP which denotes generic FWP operations: y n , W n = FWP( x n , W n − 1 ; W slow ) .
Continuous-Time Fast Weight Programmers
We propose continuous-time counterparts of Fast Weight Programmers (Sec. 2.3) which naturally combine ODEs for learning rules (Sec. 2.2) and existing approaches for sequence processing with
NODEs (Sec. 2.1).
We present three types of these CT FWP models in line with the categorisation of
Sec.
2.1 while the main focus of this work is on the two first cases.
3.1 Direct NODE-based FWPs
In the direct NODE approach (reviewed in Sec. 2.1), we assume a (bounded) control signal x : t
(cid:55)→ x ( t ) defined over an interval [ t 0 , T ] .
We make it part of the vector field to define an ODE describing a continuous-time learning rule for a fast weight matrix W ( t ) :
[Equation]
[Equation]
where W : t (cid:55)→ W ( t ) ∈ R
d out ×
d key is a function defined on [ t 0 , T ] , and F θ is an NN parameterised by θ which maps onto R d out × d key .
This is a neural differential equation for learning to program a neural net through continuous learning rules, that is, to train a fast weight matrix W ( t ) of a fast NN (Eq. 20 below) for each sequential control x .
Like in the discrete-time FWPs (Sec. 2.3), the output y ( T )
∈
R d out is obtained by querying this fast weight matrix 3 (e.g., at the last time step T ):
[Equation] [Equation]
(20) where W q ∈ R d key ×
d
in is a slow weight matrix used to generate
the query q ( T ) ∈
R d key (Eq. 19).
Now we need to specify F θ in Eq.
18 to fully define the learning rule.
We focus on three variants:
[Equation]
Hebb-style
[Equation]
Delta-style (21) where [ β ( s ) , k ( s ) , v ( s )]
=
W slow x
( s ) with a slow weight matrix W slow ∈ R (1+ d key + d out ) ×
d in .
As in the discrete-time FWP (Sec. 2.3), the slow NN generates β ( s ) ∈ R (to which we apply the sigmoid function σ to obtain a learning rate),
key k ( s ) ∈ R d key and value v ( s ) ∈
R d out vectors from input x ( s ) .
These variants are inspired by the respective classic learning rules of the same name, while they are crucially different from the classic ones in the sense that all variables involved (key, value, learning rate) are continually generated by the slow NN.
In the experimental section, we’ll comment on how some of these design choices can result in task-dependent performance gaps.
In practice, we use the multi-head version of the operations above (i.e., by letting H be a positive integer denoting the number of heads, query/key/value vectors are split into H sub-vectors and Eqs.
20-21 are conducted independently for each head).
The output is followed by the standard feed-forward block like in
Transformers [6].
Possible extensions for deeper models are discussed in Appendix C.1.
3.2 NCDE-based FWPs
Here we present models based on NCDEs (reviewed in Sec. 2.1).
We assume availability of a differentiable control signal x ( t ) , whose first order derivative is denoted by x ′ ( t ) .
Given the NCDE formulation of Eq.
5, the most straight-forward approach to obtain a CT Fast Weight Programmer is to extend the dimensionality of the recurrent hidden state, i.e., we introduce a parameterised function
F θ which maps
a matrix W ( t ) ∈ R d out × d key to a third-order tensor F θ ( W
[Equation]
t )
[Equation]
key
[Equation]
However, this approach is obviously not scalable since the input and output dimensions ( d out × d key and d out × d key × d in ) of F θ can be too large in practice.
A more tractable CDE-based approach can be obtained by providing x and/or x ′ to the vector field:
[Equation] [Equation]
While this equation still remains a CDE because of the multiplication from the right by d x = x ′ ( s ) ds , the additional inputs to the vector field offer a way of making use of various learning rules, as in the case of direct NODE approach above (Sec. 3.1).
To be specific, either x and x ′ or only x ′ is required in the vector field to obtain these tractable CDEs.
Here we present the version which uses both x and x ′ 4 .
The resulting vector fields for different cases are:
[Equation]
Delta
[Equation] [Equation]
As can be seen above, the use of CDEs to describe a continuous fast weight learning rule thus naturally results in a key/value memory where x ′ is used to generate either key or value vectors.
Because of the multiplication from the right by x ′ , the role of x ′ changes depending on the choice of learning rule: x ′ is used to generate the key in the Delta case but the value vector in the case of
Oja.
In the case of Hebb, the choice made in Eq.
24 of using x for keys and x ′ for values is arbitrary since Eq.
24 is symmetric in terms of roles of keys and values (see an ablation study in Appendix C. for the other case where we use x ′ to generate the key and x for the value).
The querying operation (analogous to Eqs.
19-20 for the direct NODE case) is also modified accordingly, depending on the choice of learning rule, such that the same input ( x or x ′ ) is used to generate both key and query:
[Equation]
Note that since the proposed vector field F θ (cid:0) W ( s ) , x ( s ) , x ′ ( s ) (cid:1) x ′ ( s ) is more general than the one used in the original NCDE F θ (cid:0) W ( s ) (cid:1) x ′ ( s ) , any theoretical results on the CDE remain valid (which, however, does not tell us anything about the best choice for its exact parameterisation).
3.3 ODE-RFWP and Latent ODE-RFWP
The main focus of this work is the setting of Kidger et al.
[4] where we assume the existence of some control signal x (Sec. 3.1 and 3.2 above).
However, here we also show a way of using FWPs in the third/last case presented in Sec.
2.1 where no control x
( t ) is available (or can be constructed), i.e., we only have access to discrete observations ( x n ) Nn =0 .
Here we cannot directly define the vector field involving continuous transformations using the inputs.
We follow the existing approaches (ODERNN or Latent ODE; Sec. 2.1) which use two separate update functions: A discrete recurrent state update is executed every time a new observation is available to the model, while a continuous update using an autonomous ODE is conducted in between observations.
Unlike with standard recurrent state vectors, however, it is not practical to autonomously evolve high-dimensional fast weight matrices 5 .
We therefore opt for using a Recurrent FWP (RFWP) [10] and combine it with an ODE:
[Equation] [Equation]
27) where we keep the fast weight learning rule itself discrete (Eq. 27), but evolve the recurrent state vector u n using an ODE (Eq. 26) such that the information to be read/written to the fast weight matrix is controlled by a variable which is continuously updated between observations.
We refer to this model as ODE-RFWP and its variational variant as Latent ODE-RFWP.
Since we focus on continuous-time learning rules, the case above is not of central interest as the learning rule remains discrete here (Eq. 27).
Nevertheless, in Appendix C.3, we also provide some experimental results for model-based reinforcement learning settings corresponding to this case.
[Table]
Experiments
We consider three datasets covering three types of time series which are regularly sampled (Speech
Commands [50]), irregularly sampled with partially missing features (PhysioNet Sepsis [51])
[Table]
or very long (EigenWorms [52]).
We compare the proposed direct NODE and CDE based FWP models (Sec. 3.1 & 3.2) to NODE baselines previously reported on the same datasets [4, 36].
Appendix B provides further experimental details including hyper-parameters.
Speech Commands.
The Speech Commands [50] is a single word speech recognition task.
The datapoints are regularly sampled, and the sequence lengths are relatively short ( ≤ 160 frames), which makes this task a popular sanity check.
Following prior work on NCDEs [4], we use 20 mel frequency cepstral coefficients as speech features and classify the resulting sequence to one out of ten keywords.
The middle column of Table 1 shows the results.
The table is split into the direct NODE (top) and
CDE (bottom) based approaches.
We first observe that among the direct NODE approaches, all
our
FWPs largely outperform ( ≥ 80% accuracy) the baseline GRU-ODE performance of 47.9% (the best direct NODE baseline from Kidger et al.
This demonstrates that with a good parameterisation of the vector field, the direct NODE approach can achieve competitive performance.
On the other hand, all CDE-based approaches yield similar performance.
We also only see slight differences in terms of performance among different learning rules, without a clear winner for this task.
This may indicate that the ordinary nature of this task (regularly sampled; short sequences) does not allow for differentiating among these CDE models, including the baseline.
PhysioNet Sepsis.
The PhysioNet Sepsis is a dataset of the sepsis prediction task from the PhysioNet challenge 2019 [51].
This is again a dataset used by Kidger et al.
[4] to evaluate NCDEs.
The task is a binary prediction of sepsis from a time series consisting of measurements of 34 medical features (e.g., respiration rate) of patients’ stays at an ICU.
Each sequence is additionally labelled by five static features of the patient (e.g., age) which are fed to the model to generate the initial state of the ODE.
Sequences are relatively short ( ≤ 72 frames) but datapoints are irregularly sampled and many entries are missing, which makes this task challenging.
It comes in two versions: with and without the so-called observation intensity information (denoted as “OI” and “no-OI”) which is one extra input feature indicating each observation’s time stamp (providing the models with information on measurement frequency).
This distinction is important since the prior work [4] has reported that existing ODE/CDE-based approaches struggle with the no-OI case of this task.
Following the previous work, we report the performance in terms of Area Under the ROC Curve (AUC).
The right part of Table 1 shows the results.
We obtain large improvements in the no-IO case (from 77.6 to 85.7% for the CDEs and from 77.1 to 84.5% for the direct NODEs), while also obtaining small improvements in the OI case (from 85.2 to 90.4% for direct NODEs, and from 88.0 to 91.2% for
CDEs).
The no-OI performance of our models is also comparable to the best overall performance reported by Kidger [38]: 85.0 % (1.3) achieved by GRU-D [53].
This demonstrates the efficacy of
[Table]
CT FWP model variants for handling irregularly sampled data with partially missing features even in the case without frequency information.
Differences between various learning rules are rather small again.
In some cases, we observe performance to be very sensitive to hyper-parameters.
For example, the best Oja-CDE configuration achieves 85.1% (2.5) with a learning rate of 6e-5, while this goes down to 79.6% (4.7) when the learning rate is changed to 5e-5.
EigenWorms.
The EigenWorms dataset (which is part of the UEA benchmark [52]) is a 5-way classification of roundworm types based on time series tracking their movements.
To be more specific, motions of a worm are represented by six features corresponding to their projections to six template movement shapes, called “eigenworms.”
While this dataset contains only 259 examples, it is notable for its very long sequences (raw sequence lengths exceed 17 K) and long-span temporal dependencies [37, 54, 55].
We use the same train/validation/test split ratio as the prior work [37] which reports Neural RDEs (NRDEs) as achieving the best NODE model performance on this dataset.
The equations of our CT FWPs for the RDE case can be straightforwardly obtained by replacing the input x in Eqs.
18-19 of the direct NODE formulation (or, x and x ′ in Eqs.
23-25 of the NCDEs) by the corresponding log-signatures.
Table 2 shows the results, where “Step” denotes the time subsampling rate which is fixed to 4 for which the prior work [37] reports the best NRDE and NCDE performance.
“Sig-Depth” denotes the depth of the log-signature (the deeper, the more log-signature terms we take into account, thus ending up with a larger input feature vector; we refer to the original paper [37] for further details).
We consider two values for this parameter: 1 and 2.
When set to 1, the input feature contains only the first derivative x ′ ( s ) and thus the NRDE is reduced to an NCDE (with controls constructed via linear interpolation).
We take the best NCDE performance from Morrill et al.
[37] as the depth-1 baseline.
Morrill et al.
[37] report the best overall performance for the depthNRDE (depth-2 baseline in our table).
In both cases, we first note a large performance gap between models with different learning rules.
While the naive Hebb and Oja based models struggle with this very long sequence processing (sequence length still exceeds 4 K with a down-sampling step size of 4), the Delta rule performs very well.
This confirms the prior result in the discrete-time domain [9] which motivated the Delta rule design by its potential for handling long sequences (we refer to prior work [9] for further explanations).
Since its performance on other tasks is comparable to the one of
Hebb and Oja variants, the Delta rule is a natural default choice for parameterising the CT FWPs.
In both the depth-1 and depth-2 cases, we obtain large improvements compared to the respective baselines.
It is counter-intuitive to find certain depth-2 models underperforming their depth-1 counterparts, but this trend has also been observed in the original NRDEs [36].
Our best overall performance is obtained in the depth-1 case: 91.8 % (3.4) exceeds the previous best NRDE based model performance of 83.8 % (3.0) [36].
This almost matches the state-of-the-art accuracy of 92.8 % (1.8) reported by Rusch et al.
[55] (using an ODE-inspired discrete-time model).
Our model’s performance variance is high (best single seed performance is 97.4% while the standard deviation is 3.4).
The wall clock time is similar for our best model (last row in Table 2) and the NRDE baseline (36s/epoch on a GeForce RTX 2080 Ti) and their sizes are comparable (87 K vs. 65 K parameters respectively).
Discussions
Scalability Advantage Compared to Standard NCDEs.
In addition to the good empirical results shown above, our FWP approach also addresses an important limitation of existing NCDEs [4]: their scalability in terms of model size.
The vector field in standard NCDEs (Eq. 5) requires an
NN F θ which takes a vector h ( s ) ∈ R d as an input to produce a matrix of size R d × d in .
This can be very challenging when d in or/and d is large.
Actually, the same bottleneck is present in the weight generation of FWPs [7].
The use of outer products can remediate this issue in discrete FWPs as well as in CT FWPs: the computations in our FWP-based NODE/NCDEs only involve “firstorder” dimensions (i.e., no multiplication between different dimensions, such as d × d in ) for NN outputs.
This can scale well with increased model size, making feasible larger scale tasks infeasible for existing NCDEs.
On the other hand, Kidger et al.
[4] report that using outer products (in their “Sec. 6.1 on limitations”) in standard NCDEs does not perform well.
Why do outer products work well in our models but not in the original NCDEs?
The answer may be simple.
In the original NCDEs (Eq. 5), multiplications occur at each (infinitesimal) time step between the generated rank-one weight matrix F θ ( h ( s )) and x ′ ( s ) before the sum.
All these transformations are thus of rank one while we expect expressive transformations to be necessary to translate x ′ ( s ) into changes in the state space.
In contrast, in our CT FWPs, the ODE only parameterises the weight generation process of another net, and thus the rank-one matrices are never used in isolation: they are summed up over time (Eq.or 23) to form an expressive weight matrix which is only then used for matrix multiplication (Eq.or 25.
The proposed FWP-NODE/NCDEs thus offer scalable alternatives to existing NCDEs, also yielding good empirical performance (Sec. 4).
Importance of Memory Efficient Backpropagation for FWPs.
Memory efficiency of continuous adjoint backpropagation may be not so important for standard NCDEs of state size O ( d ) , but is crucial for FWPs of state size O ( d 2 ) which can quickly become prohibitive for long sequences, as naive backpropagation stores all states used in the forward pass.
Prior works on discrete FWPs [9, 56, 10] solve this problem by a custom memory-efficient implementation.
Here, the continuous adjoint method naturally addresses this problem.
Limitations.
Our ablation studies and hyper-parameter tuning focus on optimising the model configuration/architecture.
From the NODE perspective, other parameters may further improve performance or alleviate performance variability/stability issues observed in some cases (Sec. 4).
For example, we use the numerical solver configurations of the baselines (see Appendix B) without tuning them.
Similarly, we use natural cubic splines to construct the differentiable control signals for
NCDEs in the Speech Commands and PhysioNet Sepsis tasks, following the original NCDE paper [4].
Morrill et al.
[36] report performance enhancements by improving the corresponding interpolation methods (e.g., 93.7% on Speech Commands).
Such further optimisation is not conducted here.
Generally speaking, real benefits of using continuous-time sequence processing models are yet to be proved.
While we achieve improvements over the best existing NODE/NCDE models on multiple datasets, discrete-time models tailored to the corresponding problem still perform as well or even better than our improved CT models (e.g., Rusch et al.
[55] for EigenWorms and Che et al.
[53] for
PhysioNet Sepsis; see Sec. 4).
Related Work on Parameter/Weight ODEs.
Other works use ODEs to parameterise the timeevolving weights of some model.
However, they are limited to autonomous ODEs (i.e., no external control x is involved).
Zhang et al.
[57] and Choromanski et al.
[58] study coupled ODEs where one
ODE is used for temporal evolution of parameters of the main Neural ODE.
The scope of these two works is limited to autonomous ODEs corresponding to continuous-depth residual NNs with different parameters per depth.
Deleu et al.
[59] consider an ODE version of a gradient descent learning process for adaptation, but also formulated as an autonomous ODE.
In contrast, our focus is really on sequence processing where the model continuously receives external controls x and translates them into weight changes of another network.
Conclusion
We introduced novel continuous-time sequence processing neural networks that learn to use sequences of ODE-based continuous learning rules as elementary programming instructions to manipulate shortterm memory in rapidly changing synaptic connections of another network.
The proposed models are continuous-time counterparts of Fast Weight Programmers and linear Transformers.
Our new models experimentally outperform by a large margin existing Neural ODE based sequence processors on very long or irregularly sampled time series.
Our Neural ODE/CDE based FWPs also address the fundamental scalability problem of the original Neural CDEs, which is highly promising for future applications of ODE based sequence processors to large scale problems.
Acknowledgements
We would like to thank Kidger et al.
[4], Morrill et al.
[37] and Du et al.
[60] for their public code.
This research was partially funded by ERC Advanced grant no: 742870, project AlgoRNN and by
Swiss National Science Foundation grant no: 200021_192356, project NEUSYM.
We are thankful for hardware donations from NVIDIA and IBM.
The resources used for this work were partially provided by Swiss National Supercomputing Centre (CSCS) project s1145 and s1154.
A Further Model Specifications
For better readability, Sec. 3 omitted element-wise activation functions for query/key/value vectors.
For example, for Eq. 21, the generation of key and value vectors, k and v , can be fully described as
[Equation]
Eq.
19 for the query generation has to be replaced by
[Equation]
These specifications are analogous in the CDE cases, i.e., in Eqs.
While softmax has already been identified as a crucial component for stability in prior works on discrete-time FWPs [9], we apply an additional tanh to the value vectors (Eq. 30).
Such usage of tanh in the output of vector fields for CDEs has been advocated by Kidger et al.
[4] to improve the stability of the ODE solver.
Indeed, we also generally found this beneficial, and sometimes crucial, for stable training of our models.
For the Delta rule (Eq. 24), since we modify the value vector after projection (to take into account the “value” which is currently associated with the key vector), we consider two different ways of applying tanh as follows:
[Equation]
For the task involving very long sequences ( > 4000 frames), we found the “post-delta” version to be crucial for successful training.
B Further Experimental Details
Our basic settings for data preparation and training are based on those used by prior works [4, 37] (we use their public implementations) for fair comparisons with the corresponding baselines.
Dataset/Task details.
The essential information about the datasets has already been presented in
Sec. 4.
The number of sequences in the training set is about 24 K for the Speech Commands dataset and about 28 K for the PhysioNet Sepsis dataset.
Model/Training details.
As mentioned in Sec. 3, all our FWP models make use of multiple computational heads, and their NODE/NCDE layer is followed by the standard Transformer feedforward block.
The number of heads n head and the feedforward inner dimension d ff are hyper-parameters of the model, in addition to the size d model of the NODE/NCDE layer.
For all models considered in the main text, the number of layers is one (see Sec.
C.1 below for a discussion of deeper models).
We conducted hyper-parameter search in the following ranges, and selected the best configuration for each setting based on its validation performance.
For Speech Commands: d model ∈ { 32 , 80 , 128 , 160 } , n head ∈ { 4 , 8 , 16 , 32 } and d ff = { 80 , 4 ∗ d model } , with a learning rate η ∈ { 1 e − 5 , 5 e − 5 } and a batch size of 1024.
The best Delta CDE model is obtained for ( d model = 80 , n head = 4 , d ff = 320 , η = 5 e − 5 ).
For PhysioNet Sepsis: d model ∈ { 32 , 80 , 128 , 160 } , n head ∈ { 8 , 16 , 32 } and d ff ∈ { 64 , 4 ∗ d model } , with a learning rate η ∈ { 1 e − 5 , 2 e − 5 , 3 e − 5 , 4 e − 5 , 5 e − 5 , 6 e − 5 , 8 e − 5 , 1 e − 4 } and a batch size of 1024.
The best Delta CDE model is obtained for ( d model = 80 , n head = 16 , d ff = 64 , η = 3 e − 5 ) in the “OI” case, and for ( d model = 160 , n head = 32 , d ff = 64 , η = 4 e − 5 ) in the “no-OI” setting.
For EigenWorms: d model ∈ { 64 , 128 , 160 } , n head ∈ { 8 , 16 , 32 } and d ff ∈ { 32 , 64 , 80 , 128 } , with a learning rate η ∈ { 5 e − 5 , 1 e − 4 , 3 e − 4 , 5 e − 4 } and a batch size set to 181 to include all training sequences (70% of the 259 total sequences in this dataset, again following the prior work [37]).
The best overall Delta CDE model is obtained for ( d model = 128 , n head = 16 , d ff = 64 , η = 1 e − 4 ) in the log-signature depth-1 case.
The best hyper-parameters for each model are listed in Table 3.
Their definitions can be found in Appendix B. H/O/D denote
Hebb/Oja/Delta variants respectively.
The top part shows hyper-parameters of the direct NODE models for Speech Commands and PhysioNet Sepsis, and those of the NRDE models for EigenWorms.
The bottom part is for the NCDE models.
[Table]
Numerical solver details.
For all tasks, we use the numerical solver settings of the baseline models.
For all supervised learning experiments in the main text, the ‘ rk4 ’ Runge-Kutta variant with default tolerance parameters in https://github.com/rtqichen/torchdiffeq [1] is used: relative/absolute tolerance values are 1e-7/1e-9.
For the RL experiment (Sec. C.3), ‘ dopri5 ’ is used instead, with relative/absolute tolerance values of 1e-5/1e-6.
As mentioned in Sec.
5, we do not tune these configurations specifically for our models.
Further enhancements in terms of performance or stability may be obtained by tuning them.
For any further details, we refer to our code.
C Extra Experiments C.1 Deeper Models
As the datasets used here were rather small, one-layer models yielded satisfactory performance.
In general, however, deeper architectures are common for Transformers [61].
Here we show ways of increasing the depth of FWP-based NODE/NCDE models.
While the possibility of stacking multiple
NCDE layers has been mentioned previously [38], no practical result has been reported.
The following equations are for the direct NODE case of our FWP models (the CDE case is analogous).
Let L and l denote positive integers.
The forward computation of layer l in an L -layer model at step t is as follows
[Equation]
where FFN denotes the standard Transformer feedforward block, W ( t, l ) denotes the fast weight matrix, F ( l ) θ l is the vector field with parameters θ l , and x ( t, l ) denotes the output of layer l ≥ 1 while x ( t, 0) is the external control signal.
The output of layer l , x ( t, l ) , thus becomes the control signal for the next layer l + 1 , and so on.
This yields a system of L coupled ODEs .
The fast weight matrix for each layer at time T can be obtained by calling the ODE solver for the corresponding coupled ODEs
[Equation]
The final output x ( T, L ) can be computed recursively via Eq.
34 for t =
T starting from l = 1 .
We conducted experiments in the EigenWorms dataset with the goal of improving our best singlelayer model of Table 2.
We tuned the 2-layer model using the same hyper-parameter search space used for the 1-layer model.
However, the best obtained 2-layer performance is 86.7 % (4.1) which is worse than the best 1-layer performance of 91.8 % (3.4).
A natural next step towards obtaining potential performance gains from deeper/larger models is to apply regularisation techniques to our models (we leave that to future work).
C.2 Ablation Studies on CDE-based Models
In Sec. 3.2 on NCDE based FWPs, we mentioned two optional model variations skipped in the main text: the Hebb variant which uses x ′ to generate keys and x to generate values, and NCDE based models which only use x ′ (instead of x and x ′ ) in the vector field (see footnote 4).
Here we provide the corresponding ablation studies.
Using x ′ for key and x for value generation in the Hebb variant.
In Sec. 3.2 on FWP based
CDEs, we noted that there are two possible formulations for the Hebb variant.
The following equations highlight the difference between the two formulations (depending on the variable, x or x ′ , used to generate keys/values):
[Equation]
We also use different equations for the fast net forward computation where, for consistency, we generate the query from the same input ( x or x ′ ) used to generate keys (even if this is not a strict requirement):
[Equation]
Experimentally, we found this second variant (“ x -values, x ′ -keys”) to perform worse on the Speech
Commands task.
It obtained a test accuracy of 83.9 % (0.4) compared to 89.5 % (0.3) achieved by the first variant we reported in the main text (Table 1).
FWP based NCDEs using only x ′ .
In Sec. 3.2, we noted that tractable FWP based NCDEs can also be obtained by using only x ′ in the vector field (instead of x and x ′ ).
The equations for the corresponding models can be obtained by replacing x by x ′ in Eq.
[Equation]
Delta
[Equation]
On the Speech Commands task, we found it crucial to use both x and x ′ .
The second variants using only x ′ perform much worse (< 65 %) than the variants using both x and x ′ , across all three learning rule schemes.
C.3 Model-based Reinforcement Learning (RL)
The main focus of this paper is the one of Kidger et al.
[4] where it is assumed that at least some bounded control signal x ( t ) defined on [ t 0 , T ] is available.
However, for the sake of completeness, in Sec. 3.3, we also present the ODE-RFWP and its latent variant in the case where we only have access to discrete inputs.
Here we provide some experimental results with working examples of such models in a model-based RL setting previously proposed by Du et al.
Settings.
We use the MuJoCo environments [62].
Our setting follows the version with action repetitions [63] proposed by Du et al.
[60], formalised as semi-Markov decision processes [64].
The core difference to the standard setting is that there is a (state-dependent) time gap τ > 0 between the time when an agent takes an action in state s and when it observes a new state s ′ (and can take a new action), resulting in irregularly timed observations.
The time gap τ is a deterministic function of the state s .
Du et al.
[60] proposed a model-based planning approach where an environmental model is parameterised as an ODE-RNN or Latent ODE-RNN such that an ODE is used to model the latent state transitions between observations.
The model is trained to predict state transitions (using mean squared error for ODE-RNNs and negative evidence lower bounds for Latent ODE-RNNs) and time gaps between observations, and it is used for model predictive control (MPC) [65, 66, 67].
The agent is trained by Deep Deterministic Policy Gradient (DDPG) [68, 69] with actor-critic [70, 71, 72] where the predictions of policy and value networks are conditioned on the recurrent (latent) state of the environment model.
In Du et al.
[60]’s work, the Latent ODE-RNN was shown to outperform the ODE-RNN and the model-free baseline in terms of sample efficiency in Hopper , Swimmer and
Half Cheetah environments.
Therefore, we compare our Latent ODE-RFWP to the baseline Latent
ODE-RNN.
We conducted our experiments in Hopper and Swimmer environments (we excluded
Half Cheetah which was reported [60] to require larger models and thus more compute).
On a side note, there are other works [73] with a focus on RL in continuous-time environments.
However, the available environments are still limited in terms of complexity (e.g., CartPole).
Training/Model details.
Each training iteration consists of interactions with the environment to collect trajectories, training of the environmental model, and policy optimisation.
Following Du et al.
[60], each iteration consists of 5 K environmental steps, and we train for up to 400 K steps (corresponding to a total of 80 iterations) in addition to the initial random interactions of 15 K steps.
The planning horizon for MPC is set to 10 steps.
We set the hidden state size of our RFWP models to 128 like in the baseline.
We use 16 computational heads, and a feedforward block size of 512.
We found that we can use the same RNN-based encoder used in the baseline also for our RFWP models without notable difference in terms of performance compared to an FWP-based encoder.
The same training/model configurations are used for both Swimmer and Hopper .
They are identical to those used by Du et al.
[60] (we use their base implementation), apart from the fact that we use the continuous adjoint method to train all models.
For further details, we refer to our code.
Results.
Figures 1a and 1b show learning curves of baseline Latent ODE-RNN and our RFWP variant in Swimmer and Hopper environments, respectively.
Given a high variability of results across seeds, we present an average over ten training runs.
We observe that final performance and sample efficiency of both models are comparable on Swimmer , while the RFWP model yields better performance on Hopper .
These results indicate that the Latent ODE-RFWP model presented in
Sec. 3.3 can effectively in practice be used as a replacement of the standard Latent ODE-RNN.
We note, however, that the final performance of baseline Latent ODE-RNN is below the one reported by Du et al.
[60] (which exceeds an expected return of 350).
The only change we introduced to the original setting is to consistently use the continuous adjoint method to train all models (we may need further ablation studies to evaluate the impact of this change), and to use ten seeds instead of four.
[Figure]