LSTM

Machine Learning
Introduced by
Hochreiter, S. & Schmidhuber, J.
Year
1997
Type
Recurrent neural network (gated memory cell)

What does it do?

LSTM (Long Short-Term Memory) is a recurrent neural network architecture introduced by Sepp Hochreiter and Jürgen Schmidhuber in 1997.

Its gated memory cells let it learn dependencies that span long stretches of a sequence, and it is commonly applied to time-series forecasting and sequence prediction.

The intuition behind the method

Ordinary recurrent networks struggle to carry information across long sequences because the learning signal decays the further back it has to reach. LSTM addresses this by giving each unit a memory cell that can hold a value over time, plus gates that control what is written to the cell, what is kept, and what is passed on. The network can therefore connect events that are far apart in a sequence, which is what time-series and sequence problems often require.

History

Sepp Hochreiter and Jürgen Schmidhuber introduced LSTM in 1997 in Neural Computation. The paper argued that recurrent backpropagation learns very slowly over long time intervals because error backflow is insufficient and decays, and it proposed the gated memory cell with constant error flow to address this. The architecture later became a standard choice for sequence modelling and time-series prediction.

When to use it

Choose an LSTM for forecasting or prediction on ordered sequences, such as time series or longitudinal data, when dependencies may span many time steps and enough data are available. As a rough rule of thumb, around 500 observations or more are usually needed; this is a heuristic rather than a validated threshold, and the requirement depends on sequence length and the number of features. With less data the network is prone to overfitting, and a simpler model is usually the safer starting point. Do not choose an LSTM when the data are small, when the inputs have no sequential order, or when the effect of individual inputs must be read directly from the fitted model, since its gates and weights are hard to interpret. Scale the inputs before training, as is standard practice. Benchmark an LSTM against simpler models such as random forest or logistic regression on held-out data: in one applied study of firm performance prediction from annual reports, a random forest achieved higher accuracy, precision and AUC than the LSTM, although the LSTM had a higher F-measure.

Limitations and considerations

  • Training typically needs a substantial dataset; as a rough heuristic, around 500 observations or more, which is not a validated threshold.
  • The gated architecture has many trainable weights relative to the sample, so overfitting is a concrete risk on small sequential datasets.
  • Results depend on preprocessing: inputs should be scaled before training, and unscaled inputs can slow or destabilise training.
  • Sequential processing makes training computationally heavy, and GPU acceleration is strongly preferred for practical use.
  • The trained gate values and weights are hard to interpret directly, so explaining individual predictions is difficult.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Gated memory cells allow information to persist across long time lags; in the original 1997 experiments, LSTM bridged minimal time lags of more than 1000 discrete time steps.
  • The constant error flow through the memory cell addresses the decaying error signal that prevents ordinary recurrent networks from learning long-range dependencies.
  • In the original 1997 analysis, the computational complexity per time step and weight is O(1), so the cost of each update does not depend on how long the history is.
  • Well suited to predicting a target that depends on earlier inputs at varying lags, as in time-series forecasting.

Applications

  • Time-series forecasting on ordered or date-indexed observations.
  • Sequence prediction where the target depends on inputs many steps earlier.
  • Modelling longitudinal data in which earlier observations influence later ones.
  • Predictive tasks on large sequential datasets where temporal memory is essential.

How it works

How it works

1

Each LSTM unit carries a memory cell whose state runs forward through the sequence. The original paper designs this cell to keep a constant error flow over time, so a signal can persist across many time steps instead of fading after a few. This is the property that allows the network to learn long-term dependencies.

2

Gates regulate the memory cell. The 1997 design uses multiplicative gate units that learn to open and close access to the constant error flow, so the network can control when information is stored and when it is read. The gates are learned from the data. Modern LSTM implementations usually add a forget gate, which controls how much of the previous cell state is kept; this gate was introduced after the original paper and is not part of the 1997 design.

3

As the sequence is processed step by step, the hidden state at each step feeds an output layer that produces the prediction. The output layer follows the task: a dense layer with a linear output suits a numeric target such as the next value in a time series, while a sigmoid output suits a binary target, as in the similarity classifier example in the Keras text. Each sample is a sequence of vectors, so the input shape is (time steps, features), and the look-back window sets how many past time steps each sample contains. Inputs should be normalised before training, as is standard practice, and training on sequential data is computationally demanding, so GPU acceleration is generally preferred.

Formula
\hat{y}_t = f(h_t)

Common pitfalls

  • Feeding unnormalised inputs, which can destabilise training and degrade the result.
  • Training on a few hundred observations and trusting the output instead of comparing it with a simpler model.
  • Reporting in-sample fit as predictive performance; for sequential data, evaluation should use held-out later time segments rather than randomly shuffled samples.
  • Applying an LSTM to data without sequential structure, where a standard model would be simpler and less prone to overfitting.

Frequently asked questions

How much data does an LSTM need?

As a rough heuristic, around 500 observations or more; this is not a validated threshold and depends on sequence length and the number of features. With less data the network is prone to overfitting, and a simpler model is the safer choice.

Do I have to normalise the inputs?

Yes, in practice. Scaling the inputs is standard practice, and unscaled inputs can slow or destabilise training and degrade the result.

What makes LSTM different from a plain recurrent network?

A plain recurrent network loses information over long sequences because its learning signal decays. The LSTM memory cell and its gates are designed to keep a constant error flow over time, so the network can learn long-term dependencies that plain recurrent networks often fail to learn.

Is a GPU required?

It is not strictly required, but GPU acceleration is generally preferred because training on large sequential datasets is computationally heavy.

Related methods

Sources

  1. Hochreiter, S. & Schmidhuber, J. (1997). Long Short-Term Memory. Neural Computation, 9(8), 1735–1780.

    Open DOI reference
  2. Data Science for Financial Econometrics (2021), 'Applying LSTM to Predict Firm Performance Based on Annual Reports', pp. 620–621

  3. Chollet, F. & Allaire, J. J., Deep Learning with R, p. 239