Start studying
Module 4 · NLP Module contents
Module 4  ·  Card 16 / 20intermediate

GRUs

A GRU is a simplified LSTM with two gates instead of three.

The reset gate decides how much past state to ignore.

The update gate decides how much new information to let in.

It has no separate cell state, so it has fewer parameters.

It trains faster than an LSTM and often performs about as well.

Learn in depth ↓
Module 04 · NLP · 20 concepts
In depth  /  15 lines

GRUs, in more detail

A GRU is a simplified LSTM that keeps most of the benefit for less machinery.

It has two gates instead of three and no separate cell state.

Memory lives entirely in the hidden state, which is passed along as usual.

The update gate decides how much of the old state to keep versus overwrite.

It does the job the forget and input gates split between them in an LSTM.

The reset gate decides how much of the past to ignore when proposing new content.

Setting it low lets the unit drop history and start fresh, which suits a sentence boundary.

Fewer gates means about three quarters of the parameters of an LSTM.

That trains faster and needs less data to fit, which matters on small datasets.

On most benchmarks the two perform within noise of each other.

LSTMs hold a small edge on very long sequences where the separate cell state helps.

GRUs are often preferred when data or compute is tight.

Neither is now the default for text, since transformers took that ground.

Both remain reasonable for short numeric sequences and low-power devices.

The general lesson held: a gated path is what lets a recurrent model remember.

Want the full technical article? Wikipedia ↗
Deep dive

What is underneath GRUs

The same idea with one gate fewer

zt=σ(Wz[ht−1,xt])\mathbf{z}_t = \sigma\big( W_z [\mathbf{h}_{t-1}, \mathbf{x}_t] \big)
rt=σ(Wr[ht−1,xt])\mathbf{r}_t = \sigma\big( W_r [\mathbf{h}_{t-1}, \mathbf{x}_t] \big)
  • zt\mathbf{z}_t: the update gate, how much of the state to replace.
  • rt\mathbf{r}_t: the reset gate, how much of the state the candidate is allowed to see.

A GRU has two gates rather than three, and no separate cell state. The hidden state is the memory.

h~t=tanh⁡(W[ rt⊙ht−1,  xt ])\tilde{\mathbf{h}}_t = \tanh\big( W [\, \mathbf{r}_t \odot \mathbf{h}_{t-1}, \; \mathbf{x}_t \,] \big)
ht=(1−zt)⊙ht−1+zt⊙h~t\mathbf{h}_t = (1 - \mathbf{z}_t) \odot \mathbf{h}_{t-1} + \mathbf{z}_t \odot \tilde{\mathbf{h}}_t

The last line is the design. Keeping and writing are tied together by one gate, so whatever fraction of the state is replaced is exactly the fraction that was forgotten.

Why that coupling is the whole difference

In an LSTM, ft\mathbf{f}_t and it\mathbf{i}_t are independent.

An LSTM can forget without writing and write without forgetting, which gives it a strictly larger set of behaviours.

GRU:ft=1−it\text{GRU} : \mathbf{f}_t = 1 - \mathbf{i}_t

A GRU cannot. The constraint removes a gate's worth of parameters and, in practice, almost none of the capability.

3 dh(dh+dx) versus 4 dh(dh+dx)3 \, d_h (d_h + d_x) \text{ versus } 4 \, d_h (d_h + d_x)

That is 25 percent fewer parameters and 25 percent less arithmetic per step, which is the practical reason to choose one.

One timestep, in order

  1. Compute the update and reset gates from the previous state and the input.
  2. Mask the previous state with the reset gate.
  3. Compute the candidate state from that masked state and the input.
  4. Blend the old state and the candidate, weighted by the update gate.
  5. Emit the result, which is both the output and the memory.

There is no output gate, so the full state is exposed at every step. A GRU cannot hold something privately the way an LSTM's cell state can.

Which to use

The honest answer from a decade of comparisons is that they perform about the same, and the difference is smaller than the difference between two random seeds.

GRUs train faster and need less data, which makes them the better default on small datasets and on anything latency-bound.

LSTMs hold an edge on tasks requiring precise long-term counting or copying, where the separate cell state and the output gate genuinely buy something.

sequential in T\text{sequential in } T

Both share the limitation that ended the era. The state at each step depends on the previous one, so neither can be parallelised across time.

Where the two are still chosen over a transformer, it is for the same reason: a fixed-size state means constant memory per token, however long the sequence runs.

Test yourself

One question on this card. Every option explains itself once you pick, right or wrong.

Question 1
How does a GRU differ from an LSTM?
NLP

20 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close