A Dual-Stage Attention-Based Recurrent Neural Network for Time Series Prediction
Paper · 2017 · Yao Qin, Dongjin Song, Haifeng Chen et al.
Summary
Estimating a room’s temperature from a house full of sensors raises a question that the temperature record alone cannot answer. Which other measurements should influence the estimate, and when in the observation window is the useful information concentrated? Estimating a stock index from company prices poses the same questions with more inputs. The paper studies a setup called nonlinear autoregression with exogenous inputs, or NARX. It supplies earlier readings of the quantity to be estimated, along with readings from other series through the time of the estimate. DA-RNN, the authors’ recurrent neural network, learns to choose how much of that information to use as it produces a single numerical prediction.
The network makes its choices in two places. An encoder weights each supporting series before incorporating that series’ current reading into its memory. The weights can change as the encoder proceeds through the window, and its scoring function has access to each series’ full window. The encoder saves the representation it produces at each position. A decoder then assigns weights to those saved representations, combines them into a context, and uses the context alongside earlier observations of the target. The first selection takes place among measurements made at the same time. The second takes place among representations associated with different times. Training ties both choices to the accuracy of the final estimate.
On the SML 2010 indoor-temperature data and the NASDAQ 100 stock data, the authors report that DA-RNN leads their comparison on mean absolute error, mean absolute percentage error, and root mean squared error. Comparisons with networks that use a single stage of attention help locate the gains. Weighting the input series improves on simpler encoding arrangements in the reported tests, and adding temporal attention to input attention is particularly helpful toward the longer end of the windows the authors test. In a separate NASDAQ 100 experiment, adding randomly reordered copies of the stock histories yields a mean absolute error of 0.28 ± 0.007 and a root mean squared error of 0.42 ± 0.009. The trained network generally gives the reordered channels less weight than the intact ones.
That last experiment gives the paper’s clearest evidence for interpretability. The weights reveal a specific operation inside the predictor, namely which measurements it scales up relative to their competitors before encoding. They leave open the causal role of those measurements and the full explanation of any individual prediction. The results on longer windows also have a definite scope. They concern retrieval from a supplied span of observations, with the supporting series already measured at the time whose target value is being estimated.
Deep dive: A Dual-Stage Attention-Based Recurrent Neural Network for Time Series Prediction
How DA-RNN predicts a time series by weighting related measurements and their encoded history, with evidence from temperature and stock-index tests. · about 36 minutes to read
The problem and its context
A missing value at the end of a window
A time series records a quantity in order. In this paper, the prediction problem starts with the recent record of one quantity, the target, and a collection of other records observed at corresponding times. The target history ends just before the position to be predicted. At that position, measurements from the other records are already available. The authors call these records driving series. The two applications give concrete meanings to that term. A monitoring system in a house produces several measurements alongside room temperature. In the market data, individual company prices accompany a stock index.
The name NARX describes the information and the function that connects it to the output. Autoregression supplies earlier values of the target itself. The exogenous inputs are the separate series passed to the predictor. A nonlinear function can make their effects depend on one another and on the observed history. For example, the architecture allows a measurement to have a different effect when the encoder’s memory reflects a different preceding sequence. The paper uses “driving” in this predictive sense. It supplies neither a causal definition of the inputs nor an experimental intervention on the house or the market.
Even with observations arranged in a window, there are two distinct sources of difficulty. Across channels, useful measurements can sit alongside measurements with little predictive value. Across time, some relevant information may be associated with an earlier part of the window and be hard to recover from its final representation. Channels and positions are easy to distinguish in the input data. They become entangled as a recurrent network combines measurements and memory. The paper asks whether separate mechanisms can give the predictor control over both kinds of selection.
The authors situate the problem in applications that include financial prediction, weather forecasting, and analysis of dynamical systems. Their argument starts from a common requirement across such applications. A useful predictor may need both the recent development of the output and a set of related signals whose roles differ. How much of the past the predictor can use and how it treats the signals are therefore architectural questions, as well as questions about what data is available.
Why use a recurrent network?
The historical starting point in the paper is the autoregressive moving average family, abbreviated ARMA. Autoregressive terms draw on previous observations and moving-average terms describe dependence involving past errors. The authors credit ARMA and its variants with practical success. They identify limitations in the forms they discuss for learning nonlinear relationships and for differentiating the driving terms. Earlier research on nonlinear autoregression with additional inputs addressed the first of those limitations through a variety of techniques.
The paper mentions kernel methods, ensembles, and Gaussian processes among previous approaches to nonlinear prediction. Its objection concerns the extent to which a predetermined nonlinear form can capture the relationship in a particular sequence. The authors turn to recurrent networks for a flexible function learned from data. A recurrent network applies an update repeatedly, with each update receiving a state handed on from the preceding position. That state gives later computations access to the effects of earlier observations without spelling out a fixed equation for every possible interaction.
Ordinary recurrence brings a learning problem. During training, the error signal reaching an early update can become weak as it is propagated back through successive transformations. This is the vanishing gradient problem. It can be hard to teach an early update to preserve something valuable much later in the sequence, even when the architecture can in principle pass information forward. The paper points to gated recurrent units and long short-term memory units as developments that address this difficulty. DA-RNN uses long short-term memory, or LSTM, in both halves of the network.
The LSTM separates a memory vector from the hidden vector it exposes to the rest of the computation. It can keep part of the previous memory and add new content to it, with learned gates controlling those operations. This additive route through memory is the reason the authors give for using it. A mechanism for preserving information still leaves open what ought to enter memory and how the downstream predictor will find the useful parts. Those are the jobs that motivate the two forms of attention.
What the architecture takes from translation
The division into an encoder and a decoder comes from work on machine translation. An encoder reads a source sentence and constructs a representation. A decoder uses that representation to produce the translated sequence. In a basic implementation, a vector of fixed size has to carry what the decoder needs from the source, whatever its length. The paper invokes the deterioration with longer inputs discussed in On the Properties of Neural Machine Translation: Encoder-Decoder Approaches. Its analogous concern is that an encoder’s final summary may have to carry too much of a long numerical sequence.
An alternative is to retain the intermediate representations and let the decoder consult them. The paper draws that approach from Bahdanau and colleagues’ work on alignment and translation. The decoder scores the stored representations in light of what it is currently processing, then assembles a weighted combination. In translation this allows the decoder to draw different information from the source while generating different parts of the output. For DA-RNN, it allows changing access to the records of the driving inputs while the decoder incorporates the target history.
The paper also discusses attention in image captioning and hierarchical attention in document classification. What matters for DA-RNN is the structure of the input it takes from the prediction task. A single position has several contemporaneous readings whose individual roles deserve explicit treatment. Consulting encoder states can retrieve a useful representation for a time position. Once those readings have been mixed by the encoder, that operation alone gives the decoder no separate control for each original input. DA-RNN puts another attention mechanism upstream of the mixture.
The authors connect this ordering to an account of human attention that distinguishes early selection of basic stimulus features from a later stage that uses information to interpret the stimulus. In the network, the distinction is implemented as a pair of learned weighting operations. One changes the values presented to the encoder. The other changes the mixture of the encoder’s records presented to the decoder. The connection to human attention explains part of the design’s inspiration. The paper’s evidence concerns how those computations behave in numerical prediction.
The method, step by step
Two ways to read the driving data
Consider a rectangular array with a row for each supporting measurement and a column for each position in the observation window. Reading down a column gives everything that was measured at one time. Reading along a row gives the history of a particular measurement. DA-RNN needs both views. Its input attention examines the history of each series when assigning its weight, then uses that weight to scale the series’ reading at the current encoder position.
The notation below uses brackets for time indices and superscripts for series indices where both appear. Juxtaposition denotes a product, and a superscript ᵀ denotes transpose. The authors describe the input matrix in the following form.
X = (x¹, x², …, xⁿ)ᵀ = (x[1], x[2], …, x[T]) ∈ ℝ^(n×T)
Here X is the entire array, n is the number of driving series, and T is the number of time positions in the window. Each x with a superscript is the sequence of readings for one channel, arranged as a row of X by the transpose in the first representation. Each x with a bracketed index is a column of X. The ellipses stand for the intervening channels or positions, and ℝ^(n×T) indicates a matrix of real numbers with n rows and T columns.
xᵏ = (xᵏ[1], xᵏ[2], …, xᵏ[T])ᵀ ∈ ℝ^T
The vector xᵏ lists the readings of driving series k at successive positions. The expression xᵏ[T] is the last such reading. The transpose arranges these readings as a column when used separately from the data matrix, and ℝ^T indicates T real entries.
x[t] = (x¹[t], x²[t], …, xⁿ[t])ᵀ ∈ ℝ^n
The vector x[t] contains the readings at position t, with xᵏ[t] the scalar from channel k. The superscripts run from the first channel to channel n. The transpose again gives a column, here of n real numbers. This view is the one the encoder uses for its time-by-time updates.
ŷ[T] = F(y[1], …, y[T−1], x[1], …, x[T])
The value ŷ[T] is the estimate of the unknown target y[T]. The unadorned y entries inside the parentheses are observed scalar target values. Their indices end at T−1, the position immediately before T. The driving vectors x extend to T. F names the nonlinear function learned by the network. The same information boundary holds for training inputs and for prediction. Training additionally supplies y[T] as the value against which to assess the output.
How DA-RNN turns an observation window into an estimate
The steps in order.
What stays in encoder memory
The encoder visits the positions in order. A hidden state is the vector it passes forward and makes accessible for later use. The recurrent update uses the preceding hidden state and the current input. The authors first give that update for an encoder consuming unweighted measurements.
h[t] = f₁(h[t−1], x[t])
The vector h[t] is the encoder’s hidden state with m components at position t. The previous vector is h[t−1]. The function f₁ is the recurrent update and x[t] is its input. This compact notation leaves implicit the cell memory that an LSTM carries between positions. The detailed equations include it.
It helps to distinguish the memory carried by the LSTM from what the network exposes at each position. The cell can retain material that the current hidden state exposes only weakly. It can also admit new information while preserving part of the old memory. These choices are made component by component, so a single update can retain one part of its memory while changing another. In the encoder, each of the gates is computed from the same pair of inputs, the previous hidden state and the new measurement vector.
f[t] = σ(W_f [h[t−1]; x[t]] + b_f)
The vector f[t] is the forget gate, which sets how much of the preceding memory remains. The brackets with a semicolon denote concatenation, the joining of h[t−1] and x[t] into a vector of length m+n. W_f and b_f are its learned matrix and bias. The logistic sigmoid σ converts each resulting component to a gate value between zero and one.
i[t] = σ(W_i [h[t−1]; x[t]] + b_i)
The vector i[t] is the input gate, which controls how much candidate information is added. The matrix W_i operates on the concatenated old hidden state and input, and b_i is the associated bias. The plus sign adds the bias before σ acts componentwise. The input gate uses its own parameters, so memory retention and new content can be controlled independently.
o[t] = σ(W_o [h[t−1]; x[t]] + b_o)
The vector o[t] is the output gate. W_o and b_o are the learned matrix and bias for this gate. Its argument again joins h[t−1], the old hidden state, with x[t], the measurement vector at t. The componentwise sigmoid σ sets how much of the updated and transformed memory the LSTM will expose.
s[t] = f[t] ⊙ s[t−1] + i[t] ⊙ tanh(W_s [h[t−1]; x[t]] + b_s)
The cell state s[t] is the new memory and s[t−1] is the old memory. The operator ⊙ multiplies matching components. Thus f[t] scales what was in the cell, while i[t] scales the new candidate. W_s and b_s are the learned matrix and bias used to construct that candidate from the same concatenated inputs. The function tanh is the hyperbolic tangent applied to each component. The addition combines the retained memory and the admitted update.
h[t] = o[t] ⊙ tanh(s[t])
The exposed hidden state h[t] results from applying tanh to the new cell state s[t] and multiplying componentwise by o[t], the output gate. Each of the four learned matrices for the encoder maps a vector of length m+n to one of length m. The corresponding biases, gates, and cell state have m components. The additive update gives memory a path from one position to the next on which the forget gate can preserve previously stored material. This is the property the paper uses to motivate its choice of recurrent unit.
Decide how much of each reading to admit
The input attention mechanism goes in front of that update. For each channel, it asks how the history of the channel fits the state the encoder has reached. The scorer uses the same learned parameters for each channel in this computation. It receives the previous hidden state and cell state together, so it can respond both to information the encoder exposed and to information it retained internally.
eᵏ[t] = v_eᵀ tanh(W_e [h[t−1]; s[t−1]] + U_e xᵏ)
The scalar eᵏ[t] is the score of channel k at encoder position t. The vectors h[t−1] and s[t−1] are the preceding encoder hidden and cell states. The brackets join them. W_e maps that joined state to a vector of length T, and U_e maps the complete driving history xᵏ into another vector of length T. The matrices have dimensions T × 2m and T × T, respectively. After addition and componentwise tanh, the transpose of the learned vector v_e takes a dot product to produce the scalar. The vector v_e has T entries. The authors omit bias terms from the displayed scorer.
Two details give this equation much of its meaning. First, xᵏ contains every reading of channel k in the window. At an early encoder position, the score can take account of readings that lie later in the same window. The measurements being scaled are those at the current position, but the decision can reflect the shape of the whole driving history. Second, the state used for scoring is the state before the current encoder update. The scorer can therefore change its emphasis as the encoder takes in more measurements, even though the driving history supplied to that scorer stays the same for the window.
αᵏ[t] = exp(eᵏ[t]) / ∑_{i=1}^n exp(eⁱ[t])
Here αᵏ[t] is the weight for channel k and exp is the exponential function. The denominator adds the exponentiated scores eⁱ[t] for all channels, with i indexing the n available series. This operation is called softmax. All the weights are positive and their sum is 1. The scale has meaning relative to other channels in the same window and at the same encoder position. Changing a competing score changes the denominator and therefore can change αᵏ[t] even when eᵏ[t] stays fixed.
x̃[t] = (α¹[t] x¹[t], α²[t] x²[t], …, αⁿ[t] xⁿ[t])ᵀ
The vector x̃[t] contains the readings that will enter the encoder at t. Each component is the measured value xᵏ[t] multiplied by its weight αᵏ[t]. The ellipsis continues the products through channel n and the transpose arranges them in a column. This gives a graded form of selection. Every channel has an entry, and a small weight attenuates its reading before the encoder’s learned matrices combine it with other readings and the state.
h[t] = f₁(h[t−1], x̃[t])
In this version, h[t] is the hidden state produced by applying the LSTM update f₁ with the previous state h[t−1] and the weighted input x̃[t]. The detailed memory and gate equations use that weighted vector in place of x[t]. The cell state still moves forward alongside h[t]. This affects more than the stored representation at t. Because the updated states also enter the next attention calculation, weighting a measurement can influence the encoder’s subsequent selection decisions.
At the end of this process the network has a sequence of hidden vectors. Each vector belongs to a position and reflects the encoder’s preceding updates as well as the newly weighted measurements. The full driving window can already influence earlier updates through input scoring. The resulting sequence therefore serves as a set of learned representations associated with time positions, with a richer information content than a sequence of raw measurements or strictly prefix-only summaries.
Retrieve from the sequence of encoder states
The decoder has its own hidden state and LSTM memory. It can compare its previous state and memory with each encoder hidden vector. This allows it to assemble the context needed at a particular decoder step while keeping the same encoded window available at the next step. In the equations, t now indexes a step of the decoder and i indexes a candidate position in the encoder. Keeping these indices separate matters because an early or late decoder step can consult any position in the encoded window.
lⁱ[t] = v_dᵀ tanh(W_d [d[t−1]; s′[t−1]] + U_d h[i]), 1 ≤ i ≤ T
The scalar lⁱ[t] scores encoder state h[i] at decoder step t, for encoder indices from 1 to T. The vector d[t−1] is the previous decoder hidden state and s′[t−1] is its previous cell state. The prime distinguishes the decoder’s memory from the encoder’s. Both have p entries, where p is the decoder hidden size. W_d maps their concatenation from 2p entries to m, U_d maps h[i] within m dimensions, and v_d is the learned m-component vector whose transpose converts the activated sum into a number. The mapping uses componentwise tanh. Biases are again omitted in the authors’ written scoring expression.
βⁱ[t] = exp(lⁱ[t]) / ∑_{j=1}^T exp(lʲ[t])
The weight βⁱ[t] is assigned to the encoder representation at i for the decoder’s current calculation. The exponential exp is applied to the score in the numerator. The denominator repeats that operation over all encoder positions j up to T and sums the results. This softmax allocates weight among positions in the window. The earlier softmax allocates weight among channels within an encoder position. Neither allocation fixes the other.
c[t] = ∑_{i=1}^T βⁱ[t] h[i]
The vector c[t] is the context for decoder step t. The sum multiplies each encoder state h[i] by its scalar weight βⁱ[t] and adds the resulting vectors. Each summand has m components, so the context keeps that dimension. It gives the decoder a compact input whose contents can vary with the decoder state while the full collection of encoder vectors remains accessible.
This mechanism provides a direct route from an intermediate encoder state into the downstream prediction. Such a route is valuable if a representation useful to the decoder would be difficult to recover from the final encoder state alone. A large weight on h[i] gives that representation more influence in the weighted sum. It can bring along information accumulated through earlier updates. Temporal attention therefore has a precise operation over the stored vectors, while the influence of an individual original reading is distributed through the wider network.
Bring the observed target into the decoder
The target readings enter through a different route from the supporting measurements. The decoder combines an observed target scalar with the corresponding context and reduces the combination to a scalar for its LSTM update. In the written recurrence the input at step t uses the observation and context indexed by t−1. The context indexed by T also goes into the final readout.
ỹ[t−1] = w̃ᵀ [y[t−1]; c[t−1]] + b̃
The scalar ỹ[t−1] is the transformed decoder input. The vector inside brackets joins the observed target y[t−1] to the context c[t−1]. The learned vector w̃ has m+1 entries and its transpose gives a dot product with that joined vector. The scalar b̃ is a learned bias. The input therefore carries a learned linear combination of the previous target reading and the selected encoder information.
d[t] = f₂(d[t−1], ỹ[t−1])
The vector d[t] is the updated decoder hidden state, d[t−1] is its predecessor, and the function f₂ is the decoder LSTM update. The scalar ỹ[t−1] supplies its external input. As with f₁, the short form suppresses the cell memory argument, which appears in the detailed gate equations. The decoder uses parameters distinct from the encoder’s, and the dimensions reflect its scalar input.
f′[t] = σ(W′_f [d[t−1]; ỹ[t−1]] + b′_f)
The decoder forget gate f′[t] regulates how much old decoder memory is retained. W′_f is its learned matrix and b′_f its learned bias. The brackets concatenate the p-component hidden state d[t−1] with the scalar ỹ[t−1]. The sigmoid σ acts separately on each component of the result.
i′[t] = σ(W′_i [d[t−1]; ỹ[t−1]] + b′_i)
The vector i′[t] is the gate for admitting new information. Its matrix W′_i and bias b′_i are learned from the prediction task. As in the forget gate, the arguments are the old hidden state d[t−1] and transformed target-and-context input ỹ[t−1], and σ is the componentwise logistic sigmoid.
o′[t] = σ(W′_o [d[t−1]; ỹ[t−1]] + b′_o)
The vector o′[t] is the gate that determines how strongly updated memory appears in the next hidden state. W′_o and b′_o are the separate learned parameters for that operation. The concatenated hidden vector and scalar input go through the matrix and bias before the sigmoid σ sets each gate value.
s′[t] = f′[t] ⊙ s′[t−1] + i′[t] ⊙ tanh(W′_s [d[t−1]; ỹ[t−1]] + b′_s)
The new cell state s′[t] adds two terms. The first multiplies the old cell state s′[t−1] by the forget gate f′[t], component by component as indicated by ⊙. The second multiplies the input gate i′[t] by a candidate update. For that update, W′_s and b′_s transform the concatenated hidden state and input, and tanh bounds the result componentwise. The memory is thus free to retain some accumulated evidence while adding new evidence about the target and driving inputs.
d[t] = o′[t] ⊙ tanh(s′[t])
The decoder hidden vector d[t] exposes the updated cell state s′[t] after a componentwise hyperbolic tangent and scaling by the output gate o′[t]. Each of the decoder matrices in the gate and memory equations maps p+1 inputs to p outputs, with a bias vector of size p. The resulting hidden state can affect the attention scores at the next decoder calculation. This gives the target history an indirect effect on subsequent retrieval from the encoder, in addition to its direct contribution through the decoder input.
Produce one estimate and train all the parts together
The last readout uses the decoder state that has processed the available target history and the final context from the encoder. The context thus has a route to the output in addition to its earlier role in shaping the decoder’s memory.
ŷ[T] = v_yᵀ (W_y [d[T]; c[T]] + b_w) + b_v
The scalar ŷ[T] is the estimate at the last window position. The bracketed vector joins the final decoder state d[T] to the final context c[T]. W_y maps that p+m component vector to p components, and b_w is the associated p-component bias. The learned vector v_y has p entries. Its transpose forms the final dot product, and b_v supplies the scalar output bias. The readout is affine in the joined representation. The recurrent transformations and attention calculations supply the nonlinearity of the mapping from the original data.
The goal of training is to make this estimate close to the observed value at the prediction position. The authors use mean squared error. Training examples provide the target value to compute the loss once the forward calculation has produced its prediction.
𝒪(y[T], ŷ[T]) = (1/N) ∑_{i=1}^N (ŷⁱ[T] − yⁱ[T])²
Here 𝒪 denotes the training objective. N is the number of samples over which it is evaluated, and i indexes a sample. The scalar yⁱ[T] is the recorded target for that sample and ŷⁱ[T] is the network’s estimate. The difference is squared, the sum runs over the samples, and division by N takes the mean. The i superscript in this formula belongs to a sample, which is distinct from a channel or an encoder position.
Because the operations are differentiable, back-propagation carries the effect of the output error through the readout, decoder, and encoder, including both scoring networks. The same prediction objective teaches the gates how to retain memory and teaches attention how to distribute its weights. Training does not require an annotation describing which sensor, price series, or time position should be selected. The network learns allocations that work with its other parameters to reduce squared error.
The authors implement the network in TensorFlow. They use stochastic gradient updates on minibatches of 128, with Adam as the optimizer. The learning rate starts at 0.001 and the authors decrease it by 10% after each 10,000 iterations. They distinguish these optimization choices from the architecture choices made on the validation data. The window length specifies how much driving history is visible, including in the input attention scorer. The hidden dimensions set the capacities of the recurrent states and determine the sizes of several learned transformations. Results from changing those settings are evaluated separately from the comparison among architectures.
Experiments and results
Predicting temperature from household measurements
SML 2010 is a public collection from monitoring equipment installed in a house. The target in the experiment is room temperature. The authors select 16 driving series from roughly 40 days of monitoring. The equipment collected readings every minute, and the sequence was smoothed with 15 minute means. Thus the metrics refer to the prediction problem on the smoothed measurements. They do not quantify errors for each of the original minute readings before smoothing.
The split follows the order of the data. The first 3,200 points make up the training set, the following 400 make up the validation set, and the last 537 make up the test set. Training can learn regularities from the first part. Validation provides a later portion on which to select settings. The test portion supplies the held-out comparison. The paper specifies the sizes in data points, which are the observations from which the prediction windows are made.
In this task, temperature history and the other household readings take distinct pathways. The encoder processes the driving measurements, while the past values of room temperature enter the decoder. The authors’ comparison asks whether specialized handling of the driving series and access to several positions in their encoded histories improve temperature prediction given that division of inputs. The smaller collection of channels also gives a setting in which to examine the methods alongside the substantially wider stock-price input.
Predicting an index from company prices
In the NASDAQ 100 Stock dataset, the target is the recorded index value and the sources are prices from 81 companies in the NASDAQ 100. The records are minute-by-minute and cover July 26, 2016 to December 22, 2016, a span the paper describes as 105 days of data. A usual market day contributes 390 data points. The paper specifies 210 observations on November 25 and 180 on December 22. These are counts of recorded positions, with coverage from market opening to closing as described by the authors.
The first 35,100 data points are used for training. The next 2,730 go to validation and the final 2,730 to testing. Like the household experiment, this tests on a later segment of the collection. The authors make the stock dataset publicly available and state that they intend to enlarge it. The financial task supplies a setting in which the first attention stage has many candidate measurements to weigh at every encoder position.
The configuration exploits an important feature of the dataset as a prediction task. The prices supplied to the network extend through the index position being estimated. The preceding index readings supply additional information to the decoder. The numbers in the experiment characterize an estimate made with those data in hand. This is a different practical question from how accurately the index can be projected before the associated company prices are observed.
Which parts of the comparison share the same inputs?
ARIMA, or autoregressive integrated moving average, is the conventional reference in the experiments. As implemented in the comparison, it receives the target’s history. The other series give the recurrent approaches an information source ARIMA does not have in this setup. The authors use this fact to explain why ARIMA’s root mean squared error is generally poorer. Its result compares complete prediction setups, with the available observations among the differences.
The recurrent comparisons are closer. NARX RNN represents a conventional recurrent approach to learning from the target history and driving measurements. The basic Encoder-Decoder represents the approach of encoding the driving window and decoding from its representation with the earlier target readings. Attention RNN adds the capability to consult multiple positions in the encoded history. Input-Attn-RNN takes up the complementary question by applying channel weights on the encoder side. The full DA-RNN combines channel weighting and temporal retrieval.
The paper adapts the two translation-derived baselines, Encoder-Decoder and Attention RNN, to produce a scalar trained with squared error. The driving series replace source words, and the decoder is supplied with the prior target observations. More generally, the authors describe the recurrent comparison as giving the methods driving windows of the same length and previously observed targets. This lets the reader interpret performance differences among the recurrent methods in terms of what the networks do with the observations. The difference in information available to ARIMA does not carry over to that part of the comparison.
Validation, repetition, and the meaning of the errors
The authors search window lengths of 3, 5, 10, 15, and 25 positions, and select T=10 using validation performance for the main testing. They set the encoder and decoder hidden sizes equal in the search. The shared widths they examine are 16, 32, 64, 128, and 256. The settings m=p=64 and m=p=128 give the best validation performance among those considered and are retained for the main evaluation. The paper also studies the effects of moving away from those settings.
The recurrent approaches are trained 10 times, and the authors report averages and standard deviations. A training run produces its own fitted predictor and associated error measures. Repetition makes it possible to describe variation with training alongside the typical score. It leaves the chronological split in place. The spread across runs measures variability under repeated training on the experimental setup, rather than variability across different houses or market periods.
The three evaluation measures summarize different aspects of prediction error. All reward smaller deviations. In the following equations, t identifies the target position and i ranges over the N samples included in the evaluation.
MAE = (1/N) ∑_{i=1}^N |yⁱ[t] − ŷⁱ[t]|
Mean absolute error, MAE, averages the magnitude of the difference between the observed target yⁱ[t] and the corresponding prediction ŷⁱ[t]. The bars denote absolute value and N is the number of evaluated samples. Each individual deviation enters in the target’s own units, so an error of a given size contributes the same amount wherever it occurs in the evaluated sequence.
RMSE = √((1/N) ∑_{i=1}^N (yⁱ[t] − ŷⁱ[t])²)
Root mean squared error, RMSE, squares the errors between the observed values yⁱ[t] and the estimates ŷⁱ[t], averages over the N samples, and uses the square root √ to return the result to the target’s units. The exponent gives larger deviations more influence over the score. MAE and RMSE can therefore distinguish predictors that make errors of different sizes and frequencies even when both are evaluated on the same series.
MAPE = (1/N) ∑_{i=1}^N |(yⁱ[t] − ŷⁱ[t]) / yⁱ[t]| × 100%
Mean absolute percentage error, MAPE, divides each difference between the observation yⁱ[t] and its estimate ŷⁱ[t] by the observation itself and takes the absolute value. It averages the resulting quantities over N samples and the factor 100% expresses the average as a percentage. The formula measures error relative to the level of the target. A smaller observation makes an error of a given absolute size count more. The fraction requires a non-zero observation. Its use of a relative deviation gives it a different interpretation from the measures reported in the target’s own units.
The headline result and the prediction traces
The authors report that DA-RNN obtains the best MAE, MAPE, and RMSE in the comparison across SML 2010 and NASDAQ 100. Among the other recurrent methods, the NARX RNN and the basic encoder–decoder yield comparable results. Attention RNN generally improves on the basic encoder–decoder. The authors also report that the input-attention network with hidden size 128 consistently exceeds both the basic encoder–decoder and Attention RNN. The main comparison can thus be read as a ranking over ways of using the same types of observations, with the best reported performance coming from combining the two selections. The ranking alone gives no numerical size for the gaps.
The paper shows NASDAQ 100 prediction traces for the basic encoder–decoder and Attention RNN with m=p=128, alongside DA-RNN with m=p=64. The authors describe the full network’s trace as agreeing better with the recorded index. The trace supplies a view of the pointwise predictions behind the aggregate measurement. Because the illustrated configurations have different hidden widths, the plot compares those fitted configurations as a whole. The separate comparison with Input-Attn-RNN provides more direct evidence on what temporal attention contributes.
Prediction when shuffled channels are added
The paper gives exact errors for an additional test on the NASDAQ 100 data. Along with the 81 unchanged driving histories, the authors provide 81 additional series generated by randomly permuting those histories. This keeps the original predictive information available while adding channels in which the original ordering has been disturbed. The observations making up a shuffled channel come from an original series. Their arrangement in time and alignment with other observations are changed.
NASDAQ 100 comparison settings by number of driving channels
The augmented setting adds shuffled histories while retaining the original price series.
The numbers
| System or setting | driving channels |
|---|---|
| Original inputs | 81 |
| DA-RNN with added shuffled inputs (this paper) | 162 |
The channel count indicates the size of the extra selection problem. A larger value means more inputs to handle. Prediction quality is assessed by the error measures, which the paper reports for the augmented setup at T=10 and m=p=128. On the NASDAQ 100 test with added shuffled series, DA-RNN has MAE of 0.28 ± 0.007, MAPE of (0.56 ± 0.01) × 10⁻², and RMSE of 0.42 ± 0.009. The authors describe these results as comparable to DA-RNN’s performance with the original channels. The clear numerical result is the error reached under the augmented condition. The comparison with clean inputs supports the authors’ claim about tolerance of this particular corruption.
The authors also look inside the predictor under the augmented condition. They plot the input weights for the intact and shuffled groups in both the training and test sets. The plots matter because a similar error score could in principle accompany different internal responses to the added channels. The distinction they observe, with smaller weights generally assigned to the shuffles, motivates a closer reading of the architectural comparisons.
What the ablations show
The value of selecting channels before they enter memory
The basic encoder–decoder, the temporal-attention baseline, and the input-attention-only version establish useful intermediate comparisons. The basic architecture can transform the driving window and use the target history in a recurrent decoder. The temporal-attention baseline changes the decoder’s access to encoded representations. The input-attention-only network changes the handling of measurements before they are encoded. Those variants ask whether an improvement requires a specific place to make the selection.
The advantage reported for Input-Attn-RNN at hidden width 128 over the basic encoder–decoder supports the value of weighting measurements on entry. Its advantage over Attention RNN is also informative. A decoder’s ability to draw on different positions in the window addresses whether information is accessible after encoding. This result suggests that there is predictive value in changing what gets encoded in the first place. In the tested cases, input attention can help sufficiently for the single-stage input variant to outperform a variant with only access to the encoded history.
The result concerns the input attention mechanism as implemented. Its channel scores depend on the previous hidden state, previous cell state, and the driving trajectory for each channel. Its softmax turns those scores into relative weights. Comparing a network equipped with this mechanism to one without it gives evidence about the whole change. It leaves the respective contributions of the hidden state, cell state, trajectory transformation, and normalization unresolved. It also leaves open how much of the improvement a fixed weighting learned across examples could capture, since the comparison does not include that intermediate case.
What the decoder gains from a longer encoded history
The temporal attention comparison takes Input-Attn-RNN as the starting point. It compares that network to the full DA-RNN over windows of 3, 5, 10, 15, and 25 positions, with the recurrent widths fixed at m=p=128 for the plotted sweep. Both networks perform channel selection. DA-RNN additionally forms contexts from the sequence of stored encoder vectors. That makes this a more focused test of the second stage than the comparison with ARIMA or the displayed index traces.
The authors report that the full design outperforms the input-only network more clearly when the windows are relatively long. The mechanism provides a reason to expect such a pattern. As the number of encoded positions grows, an intermediate representation can supply information that would otherwise have to be preserved in the final encoder summary. With temporal attention, the decoder can increase the share of that representation in the context whenever its state makes the representation useful. The observed error pattern supports access to the stored representations as a way to exploit the longer tested windows.
Both networks show worse performance when the window is too short or too long, with the full approach relatively more tolerant of the choice. A short window limits what the predictor can see. A longer one offers more observations to handle and changes what the input scorer processes. The sweep shows the combined effect of those changes. It does not identify a particular lag as the source of improvement, and a favorable comparison on the longer windows can coexist with worsening absolute performance at an extreme of the sweep.
The phrase “long-term dependencies” accordingly has a concrete experimental meaning here. The evidence comes from a change in error as the length of the supplied window varies within the studied grid. The architectures can be compared on their ability to use those observations. The experiment does not directly give the network an isolated signal of known age and measure whether it retrieves that signal. As a consequence, the error curves support the proposed temporal mechanism without locating the dependency in the original input sequence.
What the shuffling experiment says about the weights
Adding permuted series gives the input attention mechanism a task with a known difference between groups of channels. One group preserves the observed company-price histories. The other draws on the same original series with their temporal ordering disturbed. Because both groups occur in the same input window, the softmax must distribute weight across them together. Lower weights for the shuffled group indicate reduced emphasis at the point where the current readings enter the encoder.
The authors’ plot arranges the intact series in the first 81 positions and their shuffled counterparts in the last 81. It shows weights from a single encoder step for training and test data. The authors report that other steps give similar patterns. The larger weights on the intact group in the displayed examples are consistent with a mechanism that uses temporal structure to distinguish helpful inputs from the added distractors. This is more specific evidence about the computation than the aggregate error comparison supplies on its own.
There is a distinction between the way the weights are trained and the way they are used. The loss from forecasting performance trains the attention network along with the rest of DA-RNN. For an individual window, that fitted attention network computes weights from the inputs and encoder state. The experiments show that it can produce the observed group distinction during processing. They do not establish that a network fitted completely on the original channels would handle newly appended channels without being trained for the augmented setup.
The noise experiment and the architecture comparisons answer complementary questions. The partial architectures indicate whether allowing channel weights and temporal retrieval is associated with better prediction. The noise analysis shows how one of those mechanisms distributes weight under a particular corruption. It does not report an error comparison between the full network and all the partial networks under the same augmentation. Its evidence therefore ties the observed behavior to the input attention operation, while leaving the size of that operation’s specific contribution to noise tolerance unmeasured.
How sensitive the result is to recurrent width
For the width sweep, the authors fix T=10 and vary the shared hidden size over 16, 32, 64, 128, and 256. DA-RNN typically reaches its best performance with widths of 64 or 128. This shows that enlarging both recurrent states does not produce a monotonic gain in the experiments. The authors also describe the full network as less sensitive to the chosen width than Input-Attn-RNN.
The shared-width sweep changes several things at once. It changes how much state the encoder and decoder can carry, how many components are in each stored encoder vector, and the dimensions of the transformations that read those states. The authors vary the common width while holding the input window fixed, so the sweep helps distinguish sensitivity to representational size from sensitivity to the span of observations. It leaves open whether an experiment with separate widths would favor a larger encoder, a larger decoder, or the same balance used here.
Taken together, the comparisons locate benefits at different stages of computation. Channel attention changes the measurements the recurrent encoder works with. Temporal attention changes which products of that encoding remain accessible during target prediction. The window sweep helps identify when the latter mechanism is particularly valuable. The shuffled-input analysis supplies evidence about what the former mechanism actually does when presented with inputs whose order has been disrupted.
Limitations
Qualifications made by the authors
The authors report dependence on the length of the window and the size of the recurrent states. In their experiments, using too little or too much history can worsen the errors. They choose a window by validation and find that the middle of the tested width range tends to give better results. The network learns what to emphasize within the chosen window, while validation and experimental design determine what span of observations it has access to.
The conclusion describes computer vision as a potential application of the architecture for learning features. It identifies ranking and binary coding as directions the authors intend to pursue. These proposals have a different evidentiary status from the indoor-temperature and stock-index results. The experiments train and assess a scalar time-series predictor, leaving those proposed tasks for further investigation.
Limits that follow from the prediction setup
The latest supporting measurements are part of the input when the target is predicted. An application requiring a prediction for a time at which the corresponding driving measurements are unavailable has less information than the experiments supply. The results give no estimate of the resulting change in error. In the stock example, that distinction determines whether the experiment says anything about predicting the index before the company prices for that position arrive. The reported experiment is about the estimate with those prices available.
The internal meaning of time also deserves care. For input attention at encoder position t, the scorer sees the channel’s entire window. It can use values from later positions within that window to decide how strongly to scale the measurement at t. At prediction time the window ends at the specified information boundary, so the scoring equation uses available driving data. An encoder state associated with an earlier internal step nonetheless has access, indirectly through those scores, to driving observations beyond that step. This constrains claims about processing a stream strictly as each sample arrives.
The equations also leave a boundary detail open for readers reconstructing the network. The decoder update uses the preceding target value and context, while the prediction problem describes observed targets starting at the first position of the window. The presentation does not specify a starting target and context outside that sequence for the earliest index implied by the recurrence. The equations identify the roles of the states and establish the final readout. They leave an implementation to account for its initial indexing and state.
The attention parameters also depend on window length. In particular, the matrix that acts on each driving history has dimensions tied to T. The window sweep establishes how the configuration behaves at several chosen lengths. It gives no evidence that a single fitted set of those parameters can be applied unchanged to an arbitrary longer history. The difference matters when interpreting the claim about long-range information as a claim about access within a fitted predictor’s window.
Limits of the evidence on importance and robustness
Input weights describe a relative scaling before the LSTM update. Two channels can have different weights and very different raw values. The effect of their weighted readings also depends on the recurrent matrices, gates, and current memory. A large input weight is therefore evidence about how the scaler treats a channel in that computation. The channel’s independent effect on the prediction would require another analysis. Dependence among stock prices or among household readings makes that distinction especially relevant, since several channels can carry overlapping information.
Temporal weights have an analogous limitation. They apply to learned vectors. The vector associated with a given time incorporates the encoder’s memory and its updates, with scoring that uses complete driving histories. A temporal coefficient can show which encoded position contributes strongly to the context without identifying which original reading accounts for the result. The final estimate also depends on the decoder state, which incorporates the observed target history and previous context. A full explanation of a particular estimate would have to account for these pathways together.
The shuffled-input analysis has a known construction and a visible grouping, which makes the direction of the weights easy to assess. The plots show selected weights and the authors describe similar behavior at other steps. They do not give a distribution over all observations and positions. The corruption preserves the collection of values within a permuted series while disrupting their order. Bias in a sensor, delayed measurements, missing channels, or a misleading input with strong temporal structure present different conditions. Even on the same task, the reported robustness result applies to the evaluated permutation setup.
Limits of the comparisons and generalization
ARIMA’s weaker results involve a difference in available information along with a difference in architecture. Evidence about attention comes more directly from comparisons within the group of recurrent predictors. Within that group, the illustrative stock-index traces use different hidden widths. Those plots demonstrate the behavior of the displayed configurations. The numerical evaluation and the controlled sweeps supply the grounds for conclusions about the effects of the architecture.
The standard deviations describe repeated training. They leave uncertainty about how a comparison might change if the observed period or the source of the measurements changed. The authors describe the full network’s advantage over the input-attention-only variant on longer windows, but give no formal testing procedure in that discussion. The wording establishes the direction of the reported empirical comparison without assigning a statistical significance level.
The datasets cover different domains, with a selected set of driving measurements in one monitored house and a defined collection of prices over one market period. Chronological separation tests prediction on later data from each collection. It leaves open how the architecture would behave in other houses, in different market conditions, or in other applications where target-time drivers are measured differently. The paper also focuses on prediction errors. Retaining an encoder history and computing its weights adds operations, but the experiments give no measured comparison of runtime or memory costs. Those costs remain distinct from the evidence about predictive quality.
What came after
No subsequent study is identified here that establishes how later researchers adapted DA-RNN or measured its effects on another task. The paper itself points toward feature learning for computer vision and names ranking and binary coding as planned directions. These are prospective uses of the architecture. The evidence for separating channel selection from retrieval of encoded time positions comes from the temperature and stock-index experiments.
Cite
Cite as Yao Qin, Dongjin Song, Haifeng Chen, Wei Cheng, Guofei Jiang and Garrison W. Cottrell. 2017. A Dual-Stage Attention-Based Recurrent Neural Network for Time Series Prediction. International Joint Conference on Artificial Intelligence.
@inproceedings{qin2017dual,
title = {{A Dual-Stage Attention-Based Recurrent Neural Network for Time Series Prediction}},
author = {Yao Qin, Dongjin Song, Haifeng Chen, Wei Cheng, Guofei Jiang and Garrison W. Cottrell},
booktitle = {International Joint Conference on Artificial Intelligence},
year = {2017},
doi = {10.24963/ijcai.2017/366},
eprint = {1704.02971},
archivePrefix = {arXiv},
url = {https://doi.org/10.24963/ijcai.2017/366}
}This page in Markdown https://md.research.elamur.ai/free/en/papers/qin-2017-dual-stage-attention-based-recurrent/
References
- Martın Abadi, Ashish Agarwal, Paul Barham, Eugene Brevdo, Zhifeng Chen, Craig Citro, Greg S Corrado, Andy Davis, Jeffrey Dean, Matthieu Devin, et al. Tensorflow: Large-scale machine learning on heterogeneous systems. 2015. OpenAlex ↗ · Scholar ↗
- Dimitros Asteriou and Stephen G Hall. Arima models and the box-jenkins methodology. Applied Econometrics, 2(2):265–286, 2011. OpenAlex ↗ · Scholar ↗
- Dzmitry Bahdanau, Kyunghyun Cho, and Yoshua Bengio. Neural machine translation by jointly learning to align and translate. arXiv:1409.0473, 2014. our card
- Yoshua Bengio, Patrice Simard, and Paolo Frasconi. Learning long-term dependencies with gradient descent is difficult. IEEE Transactions on Neural Networks, 5(2):157–166, 1994. OpenAlex ↗ · Scholar ↗
- Abdelhamid Bouchachia and Saliha Bouchachia. Ensemble learning for time series prediction. In Proceedings of the 1st International Workshop on Nonlinear Dynamics and Synchronization, 2008. OpenAlex ↗ · Scholar ↗
- Peter J. Brockwell and Richard A Davis. Time Series: Theory and Methods (2nd ed.). Springer, 2009. OpenAlex ↗ · Scholar ↗
- Prithwish Chakraborty, Manish Marwah, Martin F Arlitt, and Naren Ramakrishnan. Fine-grained photovoltaic output prediction using a bayesian ensemble. In AAAI, 2012. OpenAlex ↗ · Scholar ↗
- S. Chen, X. X. Wang, and C. J. Harris. Narx-based nonlinear system identification using orthogonal least squares basis hunting. IEEE Transactions on Control Systems Technology, 16(1):78–84, 2008. OpenAlex ↗ · Scholar ↗
- Kyunghyun Cho, Bart Van Merriënboer, Dzmitry Bahdanau, and Yoshua Bengio. On the properties of neural machine translation: Encoder-decoder approaches. arXiv:1409.1259, 2014. our card
- Kyunghyun Cho, Bart Van Merriënboer, Caglar Gulcehre, Dzmitry Bahdanau, Fethi Bougares, Holger Schwenk, and Yoshua Bengio. Learning phrase representations using rnn encoder-decoder for statistical machine translation. arXiv:1406.1078, 2014. our card
- Eugen Diaconescu. The use of NARX neural networks to predict chaotic time series. WSEA Transactions on Computer Research, 3(3), 2008. OpenAlex ↗ · Scholar ↗
- Jeffrey L Elman. Distributed representations, simple recurrent networks, and grammatical structure. Machine learning, 7(2-3):195–225, 1991. OpenAlex ↗ · Scholar ↗
- R. Frigola and C. E. Rasmussen. Integrated pre-processing for bayesian nonlinear system identification with gaussian processes. In IEEE Conference on Decision and Control, pages 552–560, 2014. OpenAlex ↗ · Scholar ↗
- Yang Gao and Meng Joo Er. Narmax time series model prediction: feedforward and recurrent fuzzy neural network approaches. Fuzzy Sets and Systems, 150(2):331–350, 2005. OpenAlex ↗ · Scholar ↗
- Alex Graves, Abdel-rahman Mohamed, and Geoffrey Hinton. Speech recognition with deep recurrent neural networks. In ICASSP, pages 6645–6649, 2013. our card
- Sepp Hochreiter and Jürgen Schmidhuber. Long short-term memory. Neural Computation, 9(8):1735–1780, 1997. OpenAlex ↗ · Scholar ↗
- Ronald Hübner, Marco Steinhauser, and Carola Lehle. A dual-stage two-phase model of selective attention. Psychological Review, 117(3):759–784, 2010. OpenAlex ↗ · Scholar ↗
- Nal Kalchbrenner and Phil Blunsom. Recurrent continuous translation models. In EMNLP, volume 3, pages 413–422, 2013. our card
- Andrej Karpathy and Fei-Fei Li. Deep visual-semantic alignments for generating image descriptions. In CVPR, pages 3128–3137, 2015. our card
- Diederik Kingma and Jimmy Ba. Adam: A method for stochastic optimization. arXiv:1412.6980, 2014. our card
- Tsungnan Lin, Bill G. Horne, Peter Tino, and C. Lee Giles. Learning long-term dependencies in NARX recurrent neural networks. IEEE Transactions on Neural Networks, 7(6):1329–1338, 1996. OpenAlex ↗ · Scholar ↗
- Zitao Liu and Milos Hauskrecht. A regularized linear dynamical system framework for multivariate time series analysis. In AAAI, pages 1798–1805, 2015. OpenAlex ↗ · Scholar ↗
- Mark Plutowski, Garrison Cottrell, and Halbert White. Experience with selecting exemplars from clean data. Neural Networks, 9(2):273–294, 1996. OpenAlex ↗ · Scholar ↗
- Yunchen Pu, Martin Renqiang Min, Zhe Gan, and Lawrence Carin. Adaptive feature abstraction for translating video to language. arXiv preprint arXiv:1611.07837, 2016. OpenAlex ↗ · Scholar ↗
- Yao Qin, Huchuan Lu, Yiqun Xu, and He Wang. Saliency detection via cellular automata. In CVPR, pages 110–119, 2015. OpenAlex ↗ · Scholar ↗
- David E Rumelhart, Geoffrey E Hinton, and Ronald J Williams. Learning representations by back-propagating errors. Nature, 323(9):533–536, 1986. OpenAlex ↗ · Scholar ↗
- Dongjin Song, Wei Liu, Rongrong Ji, David A Meyer, and John R Smith. Top rank supervised binary coding for visual search. In ICCV, pages 1922–1930, 2015. OpenAlex ↗ · Scholar ↗
- Dongjin Song, Wei Liu, and David A Meyer. Fast structural binary coding. In IJCAI, pages 2018–2024, 2016. OpenAlex ↗ · Scholar ↗
- Ilya Sutskever, Oriol Vinyals, and Quoc V Le. Sequence to sequence learning with neural networks. In NIPS, pages 3104–3112, 2014. our card
- Paul J Werbos. Backpropagation through time: what it does and how to do it. Proceedings of the IEEE, 78(10):1550–1560, 1990. OpenAlex ↗ · Scholar ↗
- P. Whittle. Hypothesis Testing in Time Series Analysis. PhD thesis, 1951. OpenAlex ↗ · Scholar ↗
- Yue Wu, José Miguel Hernández-Lobato, and Zoubin Ghahramani. Dynamic covariance models for multivariate financial time series. In ICML, pages 558–566, 2013. OpenAlex ↗ · Scholar ↗
- Kelvin Xu, Jimmy Ba, Ryan Kiros, Kyunghyun Cho, Aaron C Courville, Ruslan Salakhutdinov, Richard S Zemel, and Yoshua Bengio. Show, attend and tell: Neural image caption generation with visual attention. In ICML, volume 14, pages 77–81, 2015. our card
- Linjun Yan, Ahmed Elgamal, and Garrison W. Cottrell. Substructure vibration NARX neural network approach for statistical damage inference. Journal of Engineering Mechanics, 139:737–747, 2013. OpenAlex ↗ · Scholar ↗
- Zichao Yang, Diyi Yang, Chris Dyer, Xiaodong He, Alex Smola, and Eduard Hovy. Hierarchical attention networks for document classification. In NAACL, 2016. our card