Machine Learning

Long Short-Term Memory (LSTM)

Long short-term memory is a type of recurrent neural network with gates that control what information is kept, updated, or forgotten, allowing it to learn patterns that span long sequences.

What is long short-term memory?

Long short-term memory (LSTM) is a recurrent neural network architecture that can remember information across long sequences. A plain recurrent network loses track of anything more than a few dozen steps back, because the training signal fades as it passes through each step. The LSTM adds a separate memory track, called the cell state, and a set of gates that control what is written to it, what is read from it, and what is erased.

The result is a model that can connect a cause and an effect separated by hundreds of steps, such as a promotion announced in one week and a sales spike three weeks later, or the subject of a sentence and a verb far down the line.

How LSTM works

At each time step the LSTM cell receives the new input and the previous hidden state and computes three gates, each a number between zero and one. The forget gate decides how much of the old cell state to keep. The input gate decides how much of the new information to add. The output gate decides how much of the cell state to expose as this step’s output. The gates are themselves small neural layers, so the network learns from the data when to remember and when to forget. The gated recurrent unit (GRU) is a simplified relative with two gates and similar performance.

LSTM in practice

A food distributor forecasts daily demand for perishable items at each of its depots. An LSTM reads ninety days of sales, promotions, weekday flags, and local weather and predicts the next seven days per item. Compared with the previous moving-average method, forecast error on the held-out quarter drops enough to reduce both spoilage and stockouts. In a machine shop, an LSTM trained on normal sensor sequences from a CNC spindle predicts the next reading, and a persistent gap between prediction and reality becomes an early warning of bearing wear.

What to watch for

  • Transformers have displaced LSTMs for language, but for many time-series problems a small LSTM remains competitive and cheap to run.
  • Always benchmark against a classic time-series method first, since a tuned seasonal model often matches a neural one.
  • LSTMs need the inputs scaled and the sequence length chosen with care, and both affect results more than most other settings.
  • Explaining why an LSTM forecast moved is hard, so pair it with feature importance or simpler diagnostics for planners.

← Back to AI Glossary