XenonStack Glossary: AI, Data and Cloud Terms Explained

Gated Recurrent Unit (GRU): How It Works vs LSTM

Written by Dr. Jagreet Kaur | 17 Mar 2023

A gated recurrent unit (GRU) is a recurrent neural network layer that uses gates to decide how much of its earlier memory to keep and how much of the new input to take in at each step of a sequence. It is a simpler relative of the LSTM and is used for text, speech, sensor readings and other sequence data.

This page is for data scientists and technical leaders choosing a sequence model. It covers how a GRU works, how it differs from an LSTM, which settings matter when you build one, and what to settle first.

What is a gated recurrent unit network?

A gated recurrent unit network is a recurrent neural network built from GRU cells. It reads a sequence one step at a time and updates a hidden state at each step. The GRU is a variant of the LSTM (long short-term memory). It keeps the LSTM's resistance to the vanishing gradient problem, but its internal structure is more straightforward, so it is quicker to train.

Why do gates matter in recurrent networks?

A plain recurrent unit struggles to carry information across long sequences. Gates give the network a learned way to keep or overwrite memory. In their comparison of recurrent units on polyphonic music and speech signal modelling, Chung et al. found that gated units (LSTM and GRU) were better than more traditional units such as tanh units, and that the GRU was comparable to the LSTM.

How does a GRU work?

According to the PyTorch GRU documentation, a GRU updates its hidden state at every time step using three components: a reset gate, an update gate and a new gate. The earlier description of a GRU with two gates refers to the reset and update gates. The new gate is the candidate state they act on.

ComponentWhat it does
Reset gateControls how much of the previous hidden state feeds into the candidate state
Update gateBalances keeping the previous hidden state against replacing it with the candidate
New gateComputes the candidate state from the current input and the reset-scaled history
Hidden stateThe blend of candidate and previous state, weighted by the update gate

How does a GRU differ from an LSTM?

The LSTM cell has input, forget and output gates. The GRU cell replaces them with the update and reset gates. The practical difference is cell complexity, and the evidence above suggests accuracy is often similar, so test both on your own data.

QuestionGRULSTM
GatesReset and update gates, plus a candidate stateInput, forget and output gates
Cell structureSimplerMore involved
Training costQuicker to trainTypically more work per step
AccuracyComparable in the Chung et al. testsComparable in the Chung et al. tests
How to chooseStart here when speed and simplicity matterTry it when the GRU underperforms on your data

What settings matter when you build a GRU?

The PyTorch documentation lists four settings worth knowing. The number of layers stacks GRUs on top of each other. A bidirectional GRU also reads the sequence in reverse, which doubles the output feature size. Dropout applies to the outputs of every layer except the last, so it has no effect on a single-layer GRU. The batch-first option changes the tensor layout to batch, sequence, feature.

How do GRUs relate to AI agents?

Agents often work on sequences: event streams, sensor logs, conversation turns. A GRU is one model choice for reading such a sequence, and it sits inside a larger system that still needs tools, memory and oversight. ElixirClaw is XenonStack's AI agents computing platform.

What should you do first?

  1. Define the sequence task and how it will be scored.
  2. Build a simple baseline, then a GRU and an LSTM with the same data split.
  3. Compare accuracy and training time, not only one of them.
  4. Record the settings and results so the choice can be reviewed later.

To map one decision your agents make from sequence data, and the data and policy it depends on, book a Context Workshop. See what happens in the workshop.

Frequently asked questions

What is a gated recurrent unit?

A gated recurrent unit is a recurrent neural network layer that uses a reset gate and an update gate to control how much earlier memory it keeps while reading a sequence.

How is a GRU different from an LSTM?

A GRU has a simpler cell with reset and update gates, while an LSTM has input, forget and output gates. In a published comparison on music and speech modelling, the GRU performed comparably to the LSTM.

What do the reset and update gates do?

The reset gate controls how much of the previous hidden state feeds into the candidate state. The update gate balances keeping the previous state against replacing it with the candidate.

When should you choose a GRU?

Choose a GRU when you want a simpler sequence model that trains quickly, and confirm on your own data that it matches an LSTM.