liveBook · Manning

GRU

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

A gated recurrent neural network architecture that updates a hidden state over sequence steps with reset and update gates.

A gated recurrent unit (GRU) is a recurrent architecture that makes its hidden state serve as both short- and long-term memory. Compared with an LSTM, it uses less memory, runs faster, and is simpler to implement, although it may be less accurate. section 6.6.2 section 6.6.3

Choose the PyTorch form according to how the sequence is available:

  • Use nn.GRU when all time steps are available together; it processes a sequence tensor in one operation and supports bidirectional encoding. section 11.4.1
  • Use nn.GRUCell when inputs arrive one item at a time or output length is unknown; manually preserve hidden states and iterate over steps. section 7.5.1 section 11.4.1

Character-level autoregression

Embed each character, initialize one zero hidden state per GRU layer, and iterate through the sequence one character at a time. Feed every resulting hidden state through a prediction head to estimate the next character, then sum cross-entropy across time steps. Gradient clipping helps stabilize training.

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

How deep it goes
Explains implementation choices, hidden-state handling, and layer iteration, but defers the GRU's internal gate equations.
Examples
Demonstrates character-level next-token prediction, bidirectional sequence encoding, variable-length decoding, and multilayer GRUCell construction.
What it assumes
Assumes embeddings, recurrent hidden states, sequence losses, and PyTorch modules while contrasting the design with LSTMs.
What you can do after
Build it from scratch with PyTorch nn.GRU or nn.GRUCell and integrate it into autoregressive or sequence-to-sequence models.
How it connects
Connects GRUs with recurrent neural networks, LSTMs, embeddings, attention, teacher forcing, and sequence-to-sequence models.

Also explained in

Compare how 7 books explain GRU →

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.