liveBook · Manning

LSTM

As explained in Inside Deep Learning: Math, Algorithms, Models

A gated recurrent neural-network architecture designed to learn long-range dependencies.

An LSTM is a recurrent neural-network architecture for carrying useful information across many time steps. It addresses the difficulty of training ordinary RNNs when gradients must transport signals far backward through a sequence. section 6.6 section 6.6.2

Each step maintains two states: the hidden state h_t, which performs the current computation, and the context state C_t, which preserves valuable information for later use. Three gates regulate that information: the forget gate removes context, the input gate adds content, and the output gate exposes context through h_t. section 6.6.2

Gates produce values from 0 to 1, using sigmoid activation, so multiplication can close, open, or partially regulate an information path. The tanh and sigmoid functions therefore provide the bounded controls used to manage short- and long-term information. section 6.6.2 section 6.8

A practical PyTorch LSTM workflow includes:

  • Reuse the sequence dataset and embedding pipeline, then replace an nn.RNN layer with nn.LSTM. section 6.6.3
  • Keep a LastTimeStep layer when the classifier needs one representation per sequence; the LSTM returns outputs together with hidden and context states. section 6.6.3
  • Use gradient clipping with recurrent networks, including LSTMs, and monitor validation behavior because the example begins overfitting after roughly four epochs. section 6.6.3

Classifying names by language

A three-layer, non-bidirectional RNN baseline is upgraded by changing nn.RNN to nn.LSTM in an embedding-to-classifier pipeline. The LSTM improves test results over the RNN, while its training curve suggests reducing neurons or stopping after about four epochs. section 6.6.3

Figure 6.14 Diagram showing the detailed operations of an LSTM and how each gate is implemented and connected. The × indicates two values being multiplied together, and the + shows values being added together. The same color coding applies (red for the forget gate, blue for the input gate, and green for the output gate).

Use the detailed gate diagram to trace forget, input, and output operations, including the multiplications and additions connecting C_t and h_t. section 6.6.2

How Inside Deep Learning: Math, Algorithms, Models covers it

How deep it goes
Explains hidden and context states, three gates, bounded activations, PyTorch construction, and training behavior without deriving full gate equations.
Examples
Demonstrates LSTM classification with embedded names, three layers, LastTimeStep reduction, accuracy curves, and an RNN comparison.
What it assumes
Assumes familiarity with RNN sequence models, embeddings, data loaders, and sequence-output reduction while reinforcing hidden-state handling.
What you can do after
Apply it via PyTorch by replacing nn.RNN with nn.LSTM, preserving sequence reduction, clipping gradients, and evaluating accuracy.
How it connects
Connects LSTMs to RNNs, gating, sigmoid, tanh, gradient clipping, bidirectional networks, and GRUs.

Also explained in

Compare how 8 books explain LSTM →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Inside Deep Learning: Math, Algorithms, Models. The section links point to the parts of the book it draws on.