This specification relates to training recurrent neural networks.
Neural networks are machine learning models that employ one or more layers of nonlinear units to predict an output for a received input. Some neural networks include one or more hidden layers in addition to an output layer. The output of each hidden layer is used as input to the next layer in the network, i.e., the next hidden layer or the output layer. Each layer of the network generates an output from a received input in accordance with current values of a respective set of parameters.
Some neural networks are recurrent neural networks. A recurrent neural network is a neural network that receives an input sequence and generates an output sequence from the input sequence. In particular, a recurrent neural network maintains an internal hidden state and can use some or all of the internal hidden state of the network from a previous time step in computing an output at a current time step.
An example of a recurrent neural network is a long short term (LSTM) neural network that includes one or more LSTM memory blocks. Each LSTM memory block can include one or more cells that each include an input gate, a forget gate, and an output gate that allow the cell to store previous states for the cell, e.g., for use in generating a current activation or to be provided to other components of the LSTM neural network. Another example of a recurrent neural network is a GRU (gated recurrent unit), which also maintains a cell state but has a simpler structure and combines the input gate and forget gate into an update gate.
This specification describes a computer-implemented method for training a recurrent neural network using forward propagation rather than back propagation through time. The method is particularly but not exclusively suited to training sparse recurrent neural networks, and may be implemented on specialized hardware.
In one aspect there is described a computer-implemented method of training a recurrent neural network using forward propagation, the recurrent neural network having a plurality of network parameters, e.g., weights and/or biases. The method may comprise receiving training data at each of a sequence of time steps, and for a succession, e.g., each of the time steps, determining, using the training data, a gradient of an optimization function with respect to the network parameters from a Jacobian matrix for the time step. The Jacobian matrix for the time step may define a derivative of a current hidden state of the recurrent neural network with respect to the network parameters.
The method may further comprise adjusting the network parameters (θ) dependent on the gradient of the optimization, e.g., loss, function
for example according to
where η is a learning rate. The optimization function may depend on a difference between a predicted output derived from the recurrent neural network for the training data, and a target output.
Determining the Jacobian matrix for the time step may comprises determining a dynamics Jacobian matrix for the time step defining a derivative of a current hidden state of the recurrent neural network with respect to a previous hidden state (for example, the immediately previous hidden state) of the recurrent neural network (for example if the current and previous hidden state each have k elements the dynamics Jacobian matrix may be a k×k matrix Dt), and determining a product of the dynamics Jacobian matrix for the time step and the Jacobian matrix for a previous time step. The method may then comprise imposing sparsity on the product and determining the Jacobian matrix for the time step based on the product,
In implementations, imposing sparsity on the product to determine the Jacobian matrix for the time step may involve setting a proportion of the elements of the Jacobian matrix for the previous time step to zero. As described later, the Jacobian matrix on which the (additional) sparsity is imposed may be one which already represents a sparse recurrent neural network, e.g., a dense version of a sparse Jacobian matrix representing the sparse recurrent neural network.
In general in a recurrent neural network, because of the recurrence each of the hidden units (neurons) may be influenced by many or all of the network parameters over a long time scale. However only one hidden unit may be directly influenced by a network parameter, and over a small number of recurrence time steps only a few hidden units may be indirectly influenced. Thus the computational load can be reduced without significantly impacting the performance of the recurrent neural network, by limiting the elements of the Jacobian matrix for the time step used in a gradient update computation. In practice, because of the typical size of the Jacobian matrix, this can reduce the memory and particularly compute requirements by orders of magnitude.
In some implementations imposing sparsity on the Jacobian matrix comprises applying a sparsity mask to the Jacobian matrix for the previous time step. The sparsity mask may identify elements of the Jacobian matrix for the previous time step to be set to zero, e.g., it may define elements allowed to be non-zero. The matrix product may then be used to define the Jacobian matrix for the time step. In this way the sparsity mask may be re-imposed each time the Jacobian matrix for a time step is calculated. The sparsity mask may be chosen according to the number of time steps over which the influence of a network parameter on the value (output) of a hidden unit is allowed to propagate. The sparsity mask may define a proportion of Jacobian matrix elements allowed to be non-zero of, e.g., less than 50%, 20%, 10%, 5%, 2%, or 1%. Determining the product of the dynamics Jacobian matrix for the time step and the Jacobian matrix for the previous time step may thus comprise performing a sparse matrix multiply.
In implementations elements of the Jacobian matrix for the time step may each define a derivative of a dimension of the current hidden state with respect to one of the network parameters. The Jacobian matrix may have at least one entry in each row and column of the matrix.
The sparsity matrix may identify as permitted to be non-zero, i.e., as not defined as set to zero, (only) elements of the Jacobian matrix for the previous time step corresponding to hidden state units or dimensions which are directly affected by one of the network parameters, i.e., affected by one of the network parameters in a single iteration of processing by the recurrent neural network.
Alternatively the sparsity matrix may identify as non-zero (only) elements of the Jacobian matrix for the previous time step corresponding to hidden state units which are affected by one of the network parameters after no more than two, or in general N, forward iterations of processing by the recurrent neural network. Each recurrent iteration typically involves updating the hidden state according to a function defined by the network parameters, and optionally stored memory. An element of the Jacobian matrix may be identified by a hidden state unit (dimension) and a network parameter. The sparsity matrix may identify an element as permitted to be non-zero if after no more than N iterations a value of the hidden state unit (dimension) is influenced by the corresponding network parameter of the Jacobian matrix.
Put differently, a hidden state of the recurrent neural network is defined by a plurality of hidden state variables. The sparsity mask may be configured to retain terms of the masked matrix product which correspond to a combination of a hidden state variable and a network parameter which directly influences a value of the hidden state variable for the time step. Alternatively the sparsity mask may be configured to retain sets of two-step terms in the masked matrix product, where a set of two-step terms comprises, for each particular unit, the terms which send input directly to the particular unit from the previous time step.
Also or instead, imposing sparsity on the product for a time step may comprise retaining only elements of the product for the time step which have one of the top M values of the elements. In some implementations M is determined by a dimension of the hidden state (e.g., number of hidden units); for example M=k, or some multiple or fraction of k. Here elements of the Jacobian matrix for the time step each define a derivative of a dimension of the current hidden state with respect to one of the network parameters.
Determining the Jacobian matrix for a time step may further comprise adding a (sparse) immediate Jacobian matrix for the time step to the product of the dynamics Jacobian matrix for the time step and the Jacobian matrix for the previous time step. This may be done before or after imposing sparsity on the product. The immediate Jacobian matrix for the time step may comprise elements which each define a derivative of a dimension of the current hidden state with respect to a current value of one of the network parameters
Elements of the Jacobian matrix for the time step may each define a derivative of a dimension of the current hidden state with respect to one of the network parameters. The sparsity mask may identify as non-zero elements of the Jacobian matrix for the previous time step corresponding to hidden state units which are affected by one of the network parameters in a single iteration of processing by the recurrent neural network, and the sparsity mask may retain an element of the Jacobian matrix for the previous time step Jt−1 only if the corresponding element in the immediate Jacobian matrix is non-zero.
Determining the gradient of the optimization function with respect to the network parameters may involve determining a product of the Jacobian matrix for the time step and a gradient of the optimization function with respect to the current hidden state of the recurrent neural network
In implementations the dynamics Jacobian matrix may be sparse matrix, e.g., with a sparsity of greater than 50%. The method may involve forming the Jacobian matrix for each time step to exclude rows or columns with zero value. A row or column with zero value may be defined by the (sparse) dynamics Jacobian matrix.
Some implementations of the method may be configured for implementation on dense matrix multiply-accumulate hardware or a dense matrix processing systolic array. The recurrent neural network may be a sparse recurrent neural network, e.g., in the sense that a parameter matrix with elements defining for each dimension of the current hidden state, the network parameters directly influencing the dimensions (i.e., in a single time step), is a sparse matrix with a sparsity of 90% or more. Then method may use a dense version of the Jacobian matrix for the time step, i.e., a version of the Jacobian matrix for the time step in which columns or rows of all zero values are removed. The method may use sparse matrix multiply hardware to determine the product of the dynamics Jacobian matrix for the time step and the Jacobian matrix for a previous time step.
There is also contemplated a method of implementing Real Time Recurrent Learning (RTRL) training of a sparse recurrent neural network in tensor processing hardware. The method may comprise receiving the training data in a first processor, and using the tensor processing hardware to determine a gradient of an optimization function as previously described by controlling the tensor processing hardware to determine the matrix product of the dynamics Jacobian matrix for the time step and the Jacobian matrix for the previous time step, and to re-impose sparsity on the product. Further features of such a method may be as previously described.
Another aspect of the present disclosure provides computer-implemented method of training a recurrent neural network using forward propagation, the recurrent neural network having a plurality of network parameters. The method comprises: receiving training data at each of a sequence of time steps and, for a succession of, e.g., for each of, the time steps: determining, using the training data, a gradient of an optimization function with respect to the network parameters from a Jacobian matrix for the time step, wherein the Jacobian matrix for the time step defines a gradient of a current hidden state of the recurrent neural network with respect to the network parameters; and adjusting the network parameters dependent on the gradient of the optimization function. Determining the Jacobian matrix for the time step comprises: determining a dynamics Jacobian matrix for the time step, defining a derivative of a current hidden state of the recurrent neural network with respect to a previous hidden state of the recurrent neural network; determining a product of the dynamics Jacobian matrix for the time step and the Jacobian matrix for a previous time step, and imposing sparsity on the product to determine the Jacobian matrix for the time step. In this aspect imposing sparsity on the Jacobian matrix for the time step may comprise applying a sparsity mask to the product to determine a masked matrix product, wherein the sparsity mask identifies elements of the Jacobian matrix for the time step to be set to zero, and wherein the masked matrix product defines the Jacobian matrix for the time step. The sparsity mask may identify as non-zero elements of the Jacobian matrix for the time step corresponding to hidden state units which are affected by one of the network parameters in a single iteration of processing by the recurrent neural network. Alternatively, the sparsity mask may identify as non-zero elements of the Jacobian matrix for the time step corresponding to hidden state units which are affected by one of the network parameters after no more than two, or in general after N, iterations of processing by the recurrent neural network.
Another aspect provides one or more computer storage media, which may be non-transitory storage media, storing instructions that when executed by one or more computers cause the one or more computers to implement a method according to any aspect or implementation described herein. A further aspect provides a system comprising one or more computers and one or more storage devices storing instructions that when executed by the one or more computers cause the one or more computers to perform operations to implement a method according to any aspect or implementation described herein.
A method of training as described herein may be used to train a recurrent neural network to process training data such as audio, image or video data in order to perform a range of tasks. For example image data may be processed as sequential data representing a sequence of pixels defining a raster pattern over the image, or for video across multiple image frames. In another example a complete image frame may be processed in a time step (in which case the hidden state may characterize a history of image frames); each time step may then define a frame of video data. In another example data processed by the recurrent neural network may comprise audio data such as a time sequence of digitized audio samples in the time and/or frequency domain, e.g., representing speech. In another example data processed by the recurrent neural network may comprise a sequence of phonemes, graphemes, word pieces or words of a natural language. In another example data processed by the recurrent neural network may comprise a sequence of medical data, e.g., a time series of observations of one or more bodily characteristics of a patient. In another example data processed by the recurrent neural network may comprise a sequence of observations from one or more sensors of a robot, vehicle, mechanical agent, or manufacturing process. In some implementations sequences of data from more than one type of data source may be combined.
A method as described herein may be used may be used to train a recurrent neural network operating on its own or as part of some larger system, for example as part of an end-to-end training process of a neural network system in which the recurrent neural network is incorporated. Such a recurrent neural network or system may be trained to perform tasks such as: converting sequential input data to sequential output data, i.e., interconverting between any of the previously described data types, e.g., for speech recognition (audio in, natural language out), speech generation (natural language in, audio out), machine translation (audio and/or natural language in and out). Other tasks include: generating example data items of a similar type to the training data, e.g., audio or image/video data, e.g., for predicting a future content of the audio or image/video (or sensor data) data for planning purposes, e.g., in reinforcement learning; classifying data items of the types previously described, e.g., to identify one or more objects or items in an image, video, or speech; processing image/video or speech, e.g., to modify a quality or content of the image/video or speech, or to improve a quality of the image/video or speech; compressing or decompressing image/video or speech data; and reasoning over image/video, speech, natural language, or other data, e.g., to answer questions about the data.
The subject matter described in this specification can be implemented in particular embodiments so as to realize one or more of the following advantages.
Conventionally a recurrent neural network is trained by back propagation through time, but this involves memorizing a historical sequence of internal hidden states so the entire state history must be stored, meaning that the memory cost grows linearly with the sequence length. For sequences too long to fit in memory, the use of Truncated BPTT (TBPTT) has been proposed. Unfortunately the truncation length used by TBPTT also limits the duration over which temporal structure can be reliably learned. By contrast training using forward propagation such as real time recurrent learning (RTRL) does not require memorizing hidden states, but RTRL is computationally intractable for all but the smallest networks. Implementations of the techniques described herein can reduce both the memory and computation requirements of training a recurrent neural network using forward propagation by orders of magnitude compared to some conventional techniques.
Thus a recurrent neural network trained as described herein can be trained faster, and may provide improved overall performance, e.g., increased accuracy, compared with other techniques. Sparse recurrent neural networks appear able to provide better performance than dense recurrent neural networks with the same number of parameters, and the techniques described herein are particularly suitable for training sparse recurrent neural networks. Some implementations of the techniques are also suitable for specialized hardware.
The details of one or more embodiments of the subject matter of this specification are set forth in the accompanying drawings and the description below. Other features, aspects, and advantages of the subject matter will become apparent from the description, the drawings, and the claims.
Like reference numbers and designations in the drawings indicate like elements.
Recurrent neural networks generate, for a current time step, an output that is informed by other outputs generated for one or more previous time steps. Some recurrent neural networks employ gated activation units. Such recurrent neural networks may be referred to as gated recurrent neural networks. Gated activation units maintain a type of memory by implementing functions that control how much information generated in a previous time step should be remembered and how much should be forgotten. Common gated activation units include Long Short Term Memory units (LSTM units), Gated Recurrent Units (GRUs), several variants thereof.
In general, a gated activation unit updates a current hidden state using at least the previous hidden state and a current input. Updating the hidden state generally involves one or more linear transformations and one or more nonlinear activations. Each linear transformation can use a weight matrix and a bias vector. Training a gated recurrent neural network thus involves learning the weight matrices and bias vectors for each gated activation unit.
The operations of the LSTM unit 100 can be defined by the following equations, in which the previous hidden state ht−1 corresponds to ht−1 103, a previous cell state ct−1 corresponds to ct−1 105, and the current input xt corresponds to xt 107. In this context, “*” refers to pointwise multiplication, “+” refers to pointwise addition, and “[” is a sigmoid activation function. The notation “Wx[ht−1, xt]” refers to matrix multiplication of a matrix Wx by a vector of ht−1 concatenated with xt. Some literature splits each matrix Wx into two matrices, W and U, in which case W is multiplied with ht−1 and U is multiplied by xt.
f
t=[(Wf[ht−1,xt]+bf) (1)
i
t=[(Wi[ht−1,xt]+bi) (2)
o
t=[(Wo[ht−1,xt]+bo) (3)
c_bart=tan h(Wc[ht−1,xt]+bc) (4)
c
t
=f
t
*c
t−1
+i
t
*c_bart (5)
h
t
=o
t*tan h(ct) (6)
The forget gate 110 corresponds to Equation (1) and generates ft 115; an input gate 120 corresponds to Equation (2) and generates it 125; and an output gate 130 corresponds to Equation (3) and generates ot 135. A tan h layer 140 corresponds to Equation (4) and generates a vector of candidates c_bart 145 for adding to the current cell state. A current cell state ct 155 is given by Equation (5). A last tan h layer 150 uses the computed cell state ct 155 to generate the current hidden state ht 165 according to Equation (6).
Each of Equations (1), (2), (3), and (4) specifies performing a matrix operation between a respective weight matrix Wn for the corresponding layer and the current input vectors xt and ht−1. The result is then added to a respective bias vector bn to the result. The result of these calculations is then fed through nonlinear activation functions [ and tan h to generate a final output vector ht for time step t.
The operations of the GRU 200 are generally defined by the following equations, in which the previous hidden state ht−1 corresponds to ht−1 203 and the current input xt corresponds to xt 207.
z
t=[(Wz[ht−1,xt]+bz) (7)
r
t=[(Wr[ht−1,xt]+br) (8)
h_bart=tan h(Wh[rt*ht−1,xt]+bh) (9)
h
t=(1−zt)*ht−1+zt*h_bart (10)
A reset gate 210 corresponds to Equation (8) and generates rt 215. An update gate 220 corresponds to Equation (7) and generates zt 225. A tan h layer 230 corresponds to Equation (9) and generates h_bart 235. The final hidden state ht 265 is then computed according to Equation (10).
As can be seen, the GRU 200 is somewhat simpler than the LSTM unit 100 in that it implements fewer gates and activation functions. But like the LSTM 100, the GRU 200 also uses a number of matrix operations using a weight matrix Wn and a current input xt, and a respective bias vector bn is then added to the result. The result of these calculations is also then fed through respective nonlinear activation functions [ or tan h.
As problems that exhibit long-term temporal structure are being confronted, scaling up the capacity of RNNs and training them on long sequences is desirable. Existing methods for training RNNs are, however, limited in this regard. A known technique of training RNNs, Backpropagation Through Time (BPTT), must cache the entire history of hidden state values of the RNN during the window of time over which gradients are computed when implemented naively. Whilst there are techniques for mitigating this problem it is still not possible to scale training to arbitrarily long sequences, as would be required by a continual learning agent operating on the single trajectory of experience comprising its lifetime.
Real Time Recurrent Learning (RTRL) can train RNNs fully online without backtracking, enabling gradient computation over arbitrarily long sequences with the fixed memory requirements of maintaining a single fixed-size state variable and updating it at every time step. This size of the object that needs to be stored for this purpose is O(kp) where k is the state size of the RNN and p is the number of parameters in the RNN cell. Storing even one copy of this object is challenging for realistically sized RNNs. Updating it is even more expensive, with a cost of O(k2p).
A RNN may be a “sparse” RNN or a “dense” RNN, where a “sparse” RNN is one in which many of the entries in θ (the network parameters) are zero. It has been found that, for a constant parameter and flop budget, sparser RNNs may have more capacity per parameter that a denser RNN. This suggests that training large sparse RNNs could yield powerful sequence models, but the memory required to store the history of (now much larger) states required for training using BPTT becomes prohibitive for long sequences.
This specification considers, as an example, recurrent networks whose dynamics are governed by ht=fθ(ht−1, xt) where ht ∈k is the state, xt∈
a is an input, and θ∈
p are the network parameters. At each step t∈{1, . . . , T}, the state is mapped to an output yt=gϕ(ht), and the network receives a loss
t(yt). The system optimizes the total loss
=Σt
t with respect to parameters by following the gradient ∇θ
.
RTRL computes the gradient as:
This can be viewed as an iterative algorithm, updating
from the intermediate quantity
To simplify equation (11) the following notation is introduced:
J stands for “Jacobian”, I for “immediate Jacobian”, and D for “dynamics Jacobian”. J may also be referred to as the “influence matrix”. Then the recursion can be written (as also illustrated in
J
t
=I
t
+D
t
J
t−1 (12)
Jt□ is a matrix in k×|θ|, which can be on the order of gigabytes for even modestly sized RNNs. Furthermore, performing the operation DtJt−1 involves multiplying a k×k matrix by a k×|θ| matrix each timestep. That requires |θ| times more computation than the forward pass of the RNN core. To make explicit just how expensive RTRL is, this is a factor of roughly one million for a classic RNN with 1000 hidden units.
In analogy to Truncated BPTT, it has been proposed to perform a gradient update partway through a training sequence (at time t) but still passing forward a stale state and a stale influence Jacobian Jt rather than resetting both to zero after the update. This enables more frequent weight updating at the cost of a staleness bias. The Jacobian becomes “stale” because it tracks the sensitivity of the state to old parameters. This trade-off can be favorable toward more frequent updates. However, much of the work on RTRL assumes that the parameters are updated at every time step t (known as fully online”) and the Jacobian is never reset, at least until the start of a new sequence.
Aspects of the described techniques relate to a new sparse approximation for RTRL. The algorithm tracks only the influence of a parameter of the RNN cell on other cells that are affected by it within N steps of the RNN. The cost of the algorithm is controlled by N and by the amount of sparsity in the Jacobian of the RNN cell—thus, a larger value of N can be coupled with increased sparsity to keep the cost of the algorithm fixed. The approximation approaches full RTL as N increases.
This specification describes an approximation to RTRL called the “Sparse N-Step Approximation” (SnAp) which reduces substantially the computational requirements for RTRL.
In outline, the SnAp approximation imposes sparsity on the Jacobian J even though it is in general dense (where “dense” means that few of the entries in j are non-zero.) This may be done by applying a sparsity pattern, or sparsity mask, to the Jacobian. The sparsity pattern or mask is chosen to be the locations that are non-zero after N steps of the RNN.
Locations that are non-zero after N steps of the RNN are illustrated in
In the case of the dense network the initial connection i influences all nodes in the network when N≥2, as shown in the lower part of
In a some implementations the same sparsity pattern is used for all steps, though this is not a requirement. This means that the sparsity pattern of Jt—and so of Jt−1—is known and can be used to reduce the amount of computation required to determine the product DtJt−1 by applying a sparsity mask or pattern to Jt−1 to reduce the number of non-zero entries in Jt−1 that are involved in the determination of the product DtJt−1. An alternative strategy for performing SnAp-1 and SnAp-2 would be to perform the full multiplication of DtJt−1 and then only keep the top-k values. This would reduce the bias of the approximation but increase its cost.
More formally, the following approximation for all values of t may be adopted:
The computational costs of the methods of RTRL, sparse RTRL, SnAp-1 and SnAp-2 and BPTT are compared in Table 1.
In Table 1, T denotes the sequence length, k denotes the number of hidden units of the RNN, p denotes the number of recurrent parameters, and d=1−s, where the sparsity s is the proportion of elements that are non-zero.
Examples of ways in which sparsity may be imposed on the product Dt Jt−1 are now described by way of illustration.
Sparse One-Step Approximation (SnAp-1)
Even for a fully dense RNN, each parameter will usually immediately influence only the single hidden unit it is directly connected. This means that the immediate Jacobian It tends to be extremely sparse. For example, a classic (or “vanilla”) RNN will have only one nonzero element per column, which is a sparsity level of (k−1)/k. Storing only the nonzero elements of It saves a significant amount of memory without making any approximations. It is the same shape as the Jt matrix whereas the nonzero values are the same size as θ. The immediate Jacobian It can become more dense in architectures such as GRU and LSTM.
In the Sparse One-Step Approximation, entries in Jt−1 are kept only if they are nonzero in It as shown in
SnAp-1 is effectively diagonal, in the sense that the effect of parameter j on hidden unit i is maintained through time, but ignoring the indirect effect of parameter j on hidden unit i via paths through other units i′. More formally, one can define u(j) as the one component in the state ht that is connected directly to the parameter j (which has at the other end of the connection some other entry i′ within ht−1 or xt. Let I=u(j). The imposition of the one-step sparsity pattern means only the entry in row i will be kept for column j in Jt. Inspecting the update for this particular entry,
This equality follows from the assumption that (Jt−1)mj=0 if m≠j.
Optimizations for Full RTRL with Sparse Networks
When the RNN is sparse, the costs of even full (un-approximated) RTRL can be alleviated to a surprising extent, and it is possible to save computation proportional to a factor of the sparsity squared. It is assumed that proportion s of the entries in both θ and Dt are equal to zero, and the quantity s is defined as the sparsity in the RNN. For convenience, the “density” of the RNN is defined as d=1−s. With a classic RNN, this correspondence between parameter sparsity and dynamics sparsity holds exactly, although for gating architectures such as GRU and LSTM the relationship is more complicated More complex recurrent architectures involving attention would require an independent mechanism for inducing sparsity in Dt. However it is generally assumed in the following description that sparsity in θ corresponds to sparsity in Dt.
If the sparsity level of θ is s, then so is the sparsity in J because the columns corresponding to parameters which are clamped to zero have no effect on the gradient computation. The columns of J that contain non-zero parameters maybe extracted into a new dense matrix for use everywhere with no effect on the gradient computation. Similarly, the columns of I that contain non-zero parameters maybe extracted into a new dense matrix
, so that the update rule becomes:
{tilde over (J)}
t
=Ĩ
t
+D
t
,{tilde over (J)}
t−1
These optimizations taken together reduce the storage requirements by 1/d (because is d times the size of J) and the computational requirements by 1/d2 because Dt in the sparse
matrix multiplication Dt
−1 l has density d, saving an extra factor of 1/d.
Sparse N-Step Approximation (SnAp-N)
In the Sparse One-Step Approximation, entries in Jt−1 are retained if they correspond to hidden state units which are affected by one of the network parameters in a single iteration of processing by the recurrent neural network. In the SnAp-2 approximation [SnAp-N approximation], entries in Jt−1 are retained if they correspond to hidden state units which are affected by one of the network parameters in two iterations [N iterations] of processing by the recurrent neural network (that is a retained element in the Jacobian matrix for the previous time step corresponds to a combination of a hidden state unit and a parameter that affects that hidden state unit in two time steps [N time steps]). SnAp-N for N>1 is both strictly less biased and strictly more computationally expensive (as can be seen by comparing
SnAp-2 or SnAP-n may be used with sparse networks. As can be seen from the dense network in the lower part of
Even when Dt is sparse, the computation graph linking nodes (neurons) in the hidden state over time should still be connected, meaning that eventually becomes fully dense because after enough iterations every (non-zero) parameter will have influenced every hidden unit in the state. Thus, sparse approximation are available, and are required to obtain an efficient algorithm. For sparse RNNs, SnAp may be used to impose further sparsity on
rather than Jt.
Jacobian Sparsity of GRUs and LSTMs
Unlike classic (“vanilla”) RNNs whose dynamics Jacobian De has sparsity exactly equal to the sparsity of the weight matrix, GRUs and LSTMs have inter-cell interactions which increase the Jacobians' density. In particular, the choice of GRU variant can have a very large impact on the density of the “dynamics” Jacobian Dt and the parameter Jacobians It and Jt. For the standard LSTM formulation given in equations 1 to 6 above, an individual parameter will directly affect only one entry in each gate (it, ft, ot) and the candidate cell c_bart. These in turn produce the next cell ct and next hidden state ht with element-wise operations. In this case,
However, for a GRU there are multiple formulations in which a parameter or hidden unit can influence many units of the next state. For the formulation in equations (7) to (10) above, the parameters influencing rt further influence every unit of h_bart because of the matrix multiplication in equation (9). They therefore influence every unit of ht within one recurrent step, which means that the dynamics Jacobian Dt and the immediate parameter Jacobian It are fully dense.
In an alternative formulation, equation (9) may be modified to move the reset gate to be after the matrix multiplication, thus avoiding the composition of parameterized linear maps within a single RNN step. The modeling performance of the two variants is largely the same, but the second variant is faster and results in sparser Dt and It.
Once the network is trained, it may be used to process input data, to perform tasks such as: converting sequential input data to sequential output data, i.e., interconverting between any of the previously described data types, e.g., for speech recognition (audio data in, natural language out), speech generation (natural language in, audio out), machine translation (audio and/or natural language in and out). Other tasks include: generating example data items of a similar type to the training data, e.g., audio or image/video data, e.g., for predicting a future content of the audio or image/video (or sensor data) data for planning purposes, e.g., in reinforcement learning; classifying data items of the types previously described, e.g., to identify one or more objects or items in an image, video, or speech; processing image/video or speech, e.g., to modify a quality or content of the image/video or speech, or to improve a quality of the image/video or speech; compressing or decompressing image/video or speech data; and reasoning over image/video, speech, natural language, or other data, e.g., to answer questions about the data.
Determining the gradient of the optimization function with respect to the network parameters from the Jacobian matrix for the time step may comprise determining a product of the Jacobian matrix for the time step and a gradient of the optimization function with respect to the current hidden state of the recurrent neural network.
Determining the product of the dynamics Jacobian matrix for the time step and the Jacobian matrix for the previous time step may be done using any suitable matrix multiplication technique. Where both the dynamics Jacobian matrix for the time step and the Jacobian matrix for the previous time step are sparse matrices, determining the product may use a sparse matrix multiplication technique to provide further computational savings.
Imposing sparsity on the product may be done by imposing sparsity on the Jacobian matrix for the previous time step, for example by applying a sparsity mask to the Jacobian matrix for the previous time step where the sparsity mask identifies elements of the Jacobian matrix for the previous time step to beset to zero. The product of the dynamics Jacobian matrix for the time step and the Jacobian matrix for the previous time step is then determined using the sparsified Jacobian matrix for the previous time step.
In this implementation the sparsity mask may identify as non-zero those elements of the Jacobian matrix for the previous time step that correspond to hidden state units which are affected by one of the network parameters in a single iteration of processing by the recurrent neural network. This is the SnAp-1 approximation implementation. In this implementation, as noted above and as shown in
The SnAp-1 approximation may be looked at another way. If a hidden state of the recurrent neural network is defined by a plurality of hidden state variables, the sparsity mask is configured to retain terms (Jt−1)ij in the Jacobian for the previous time step which correspond to a combination of a hidden state variable (i) and a network parameter (j) which directly influences a value of the hidden state variable for the time step.
Alternatively, the sparsity mask may identify as non-zero those elements of the Jacobian matrix for the previous time step that correspond to hidden state units which are affected by one of the network parameters after no more than 2 iterations of processing by the recurrent neural network. This is the SnAp-2 approximation implementation.
The SnAp-2 approximation may again be looked at another way. If a hidden state of the recurrent neural network is defined by a plurality of hidden state variables, the sparsity mask is configured to retain sets of two-step terms in the Jacobian for the previous time step. A two-step term corresponds to a combination of a hidden state variable and a network parameter which influences a value of the hidden state variable for the second time step.
As a further alternative, the sparsity mask may identify as non-zero those elements of the Jacobian matrix for the previous time step that correspond to hidden state units which are affected by one of the network parameters after no more than N iterations of processing by the recurrent neural network, where N>2. This is the SnAp-N approximation implementation.
In a further implementation that is applicable to a sparse RNN, the Jacobian matrix for each time step may be formed to exclude rows or columns with zero value, where a row or column with zero value is defined by the sparse dynamics Jacobian matrix. Such a Jacobian is referred to as , and determining the gradient of an optimization function with respect to the network parameter may be effected using the product multiplication Dt
−1. In the case of a sparse RNN the SnAp approximation techniques described herein may be used to impose additional sparsity on
−1 rather than on Jt−1.
In a yet further implementation, imposing sparsity on the product for the time step comprises retaining only elements of the product for the time step which have one of the top M values. The number M of values to be retained may be determined in any suitable way. For example, M may be determined based on a dimension of the hidden state (e.g., based on the number k of hidden units).
Embodiments of the described techniques may be implemented on any suitable computer or computing system. For example, a method as described may be configured for implementation on dense matrix multiply-accumulate hardware or a dense matrix processing systolic array. This may be done where the recurrent neural network is a sparse recurrent neural network such that a parameter matrix with elements defining for each dimension of the current hidden state, the network parameters directly influencing the dimensions, is a sparse matrix, for example with a sparsity of 90% or more. In this case the method uses a dense version of the Jacobian matrix comprising a version of the Jacobian matrix in which columns or rows of all zero values are removed. The SnAp approximation techniques described herein may be used to impose additional sparsity on
−1.
Alternatively, a training method as described may be implemented using tensor processing hardware, with the method comprising receiving the training data in a first processor; and using the tensor processing hardware to determine the gradient of the optimization function by controlling the tensor processing hardware to determine the matrix product of the dynamics Jacobian matrix for the time step and the Jacobian matrix for the previous time step according to any embodiment described herein to impose sparsity.
For a system of one or more computers to be configured to perform particular operations or actions means that the system has installed on it software, firmware, hardware, or a combination of them that in operation cause the system to perform the operations or actions. For one or more computer programs to be configured to perform particular operations or actions means that the one or more programs include instructions that, when executed by data processing apparatus, cause the apparatus to perform the operations or actions.
Embodiments of the subject matter and the functional operations described in this specification can be implemented in digital electronic circuitry, in tangibly-embodied computer software or firmware, in computer hardware, including the structures disclosed in this specification and their structural equivalents, or in combinations of one or more of them. Embodiments of the subject matter described in this specification can be implemented as one or more computer programs, i.e., one or more modules of computer program instructions encoded on a tangible non-transitory program carrier for execution by, or to control the operation of, data processing apparatus. Alternatively or in addition, the program instructions can be encoded on an artificially-generated propagated signal, e.g., a machine-generated electrical, optical, or electromagnetic signal, that is generated to encode information for transmission to suitable receiver apparatus for execution by a data processing apparatus. The computer storage medium can be a machine-readable storage device, a machine-readable storage substrate, a random or serial access memory device, or a combination of one or more of them.
The term “data processing apparatus” refers to data processing hardware and encompasses all kinds of apparatus, devices, and machines for processing data, including by way of example a programmable processor, a computer, or multiple processors or computers. The apparatus can also be or further include special purpose logic circuitry, e.g., an FPGA (field programmable gate array) or an ASIC (application-specific integrated circuit). The apparatus can optionally include, in addition to hardware, code that creates an execution environment for computer programs, e.g., code that constitutes processor firmware, a protocol stack, a database management system, an operating system, or a combination of one or more of them.
A computer program (which may also be referred to or described as a program, software, a software application, a module, a software module, a script, or code) can be written in any form of programming language, including compiled or interpreted languages, or declarative or procedural languages, and it can be deployed in any form, including as a stand-alone program or as a module, component, subroutine, or other unit suitable for use in a computing environment. A computer program may, but need not, correspond to a file in a file system. A program can be stored in a portion of a file that holds other programs or data, e.g., one or more scripts stored in a markup language document, in a single file dedicated to the program in question, or in multiple coordinated files, e.g., files that store one or more modules, sub-programs, or portions of code. A computer program can be deployed to be executed on one computer or on multiple computers that are located at one site or distributed across multiple sites and interconnected by a communication network.
The processes and logic flows described in this specification can be performed by one or more programmable computers executing one or more computer programs to perform functions by operating on input data and generating output. The processes and logic flows can also be performed by, and apparatus can also be implemented as, special purpose logic circuitry, e.g., an FPGA (field programmable gate array) or an ASIC (application-specific integrated circuit).
Computers suitable for the execution of a computer program include, by way of example, can be based on general or special purpose microprocessors or both, or any other kind of central processing unit. Generally, a central processing unit will receive instructions and data from a read-only memory or a random access memory or both. The elements of a computer are a central processing unit for performing or executing instructions and one or more memory devices for storing instructions and data. Generally, a computer will also include, or be operatively coupled to receive data from or transfer data to, or both, one or more mass storage devices for storing data, e.g., magnetic, magneto-optical disks, or optical disks. However, a computer need not have such devices. Moreover, a computer can be embedded in another device, e.g., a mobile telephone, a personal digital assistant (PDA), a mobile audio or video player, a game console, a Global Positioning System (GPS) receiver, or a portable storage device, e.g., a universal serial bus (USB) flash drive, to name just a few.
Computer-readable media suitable for storing computer program instructions and data include all forms of non-volatile memory, media and memory devices, including by way of example semiconductor memory devices, e.g., EPROM, EEPROM, and flash memory devices; magnetic disks, e.g., internal hard disks or removable disks; magneto-optical disks; and CD-ROM and DVD-ROM disks. The processor and the memory can be supplemented by, or incorporated in, special purpose logic circuitry.
To provide for interaction with a user, embodiments of the subject matter described in this specification can be implemented on a computer having a display device, e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor, for displaying information to the user and a keyboard and a pointing device, e.g., a mouse or a trackball, by which the user can provide input to the computer. Other kinds of devices can be used to provide for interaction with a user as well; for example, feedback provided to the user can be any form of sensory feedback, e.g., visual feedback, auditory feedback, or tactile feedback; and input from the user can be received in any form, including acoustic, speech, or tactile input. In addition, a computer can interact with a user by sending documents to and receiving documents from a device that is used by the user; for example, by sending web pages to a web browser on a user's client device in response to requests received from the web browser.
Embodiments of the subject matter described in this specification can be implemented in a computing system that includes a back-end component, e.g., as a data server, or that includes a middleware component, e.g., an application server, or that includes a front-end component, e.g., a client computer having a relationship graphical user interface or a Web browser through which a user can interact with an implementation of the subject matter described in this specification, or any combination of one or more such back-end, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication, e.g., a communication network. Examples of communication networks include a local area network (“LAN”) and a wide area network (“WAN”), e.g., the Internet.
The computing system can include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other.
While this specification contains many specific implementation details, these should not be construed as limitations on the scope of any invention or of what may be claimed, but rather as descriptions of features that may be specific to particular embodiments of particular inventions. Certain features that are described in this specification in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features that are described in the context of a single embodiment can also be implemented in multiple embodiments separately or in any suitable subcombination. Moreover, although features may be described above as acting in certain combinations and even initially claimed as such, one or more features from a claimed combination can in some cases be excised from the combination, and the claimed combination may be directed to a subcombination or variation of a subcombination.
Similarly, while operations are depicted in the drawings in a particular order, this should not be understood as requiring that such operations be performed in the particular order shown or in sequential order, or that all illustrated operations be performed, to achieve desirable results. In certain circumstances, multitasking and parallel processing may be advantageous. Moreover, the separation of various system modules and components in the embodiments described above should not be understood as requiring such separation in all embodiments, and it should be understood that the described program components and systems can generally be integrated together in a single software product or packaged into multiple software products.
Particular embodiments of the subject matter have been described. Other embodiments are within the scope of the following claims. For example, the actions recited in the claims can be performed in a different order and still achieve desirable results. As one example, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In certain implementations, multitasking and parallel processing may be advantageous.
This application claims priority to U.S. Provisional Application No. 62/971,566, filed on Feb. 7, 2020. The disclosure of the prior application is considered part of and is incorporated by reference in the disclosure of this application.
Number | Date | Country | |
---|---|---|---|
62971566 | Feb 2020 | US |