DL0074 GRU vs LSTM

How does a GRU differ from an LSTM, and when would you prefer one over the other?

Answer

Both are gated recurrent cells that replace the vanilla RNN’s repeated multiplication by an additive state update, which is what keeps gradients alive across long sequences. The LSTM carries two state tensors (the cell state c_t and the hidden state h_t) and three gates: forget, input, and output. The GRU is a leaner reparameterization that keeps one state: it merges forget and input into a single update gate z_t whose two branches are tied as z_t and 1 - z_t, deletes the output gate so the full state is exposed to the next layer, and adds a reset gate r_t that suppresses the previous state inside the candidate. The practical consequence is three weight blocks instead of four, so roughly 25% fewer recurrent parameters and matmuls per step, plus one less tensor to carry and initialize. Accuracy is usually close (Chung et al. 2014; Greff et al. 2017), so the choice is driven by data size, latency, and whether the task needs the LSTM’s unbounded memory.

(1) Gate Inventory: LSTM has forget, input, and output gates; the GRU has update and reset only, because tying the write and erase decisions into z_t and 1 - z_t removes one gate and dropping the output gate removes another.
(2) One State vs Two: the LSTM’s protected cell state c_t is never squashed on the recurrent path and is only revealed through the output gate, while the GRU’s single h_t is both the memory and the emitted representation.
(3) Parameter and Compute Ratio: with input width D and hidden width H, the GRU costs exactly 3/4 of the LSTM’s recurrent parameters and per-step FLOPs, which matters most when the recurrent stack dominates the model.
(4) Expressivity Gap: at finite precision, the LSTM’s additive, unsquashed cell state can implement a genuine counter, whereas the GRU’s convex-combination update keeps the state inside [-1,1] and can only approximate counting (Weiss et al. 2018).
(5) How to Choose: prefer the GRU for small or medium datasets, short-to-medium sequences, and tight latency or memory budgets; prefer the LSTM for long sequences, large corpora, and tasks that need precise long-horizon bookkeeping such as language modeling.

Two side-by-side cell diagrams: the LSTM panel shows a cell-state track with multiply and add operators fed by forget and input gates plus an output gate producing h_t; the GRU panel shows a single hidden-state track with an update gate feeding both branches and a reset gate feeding the candidate

Figure 1: The LSTM keeps a separate cell-state track written by forget and input gates and read out through an output gate; the GRU folds everything onto one hidden-state track, where the update gate supplies both mixing weights and the reset gate only conditions the candidate.

Mathematical Formulation:
c_t = f_t \odot c_{t-1} + i_t \odot \tilde{c}_t
h_t = o_t \odot \tanh(c_t)
\tilde{h}_t = \tanh(W_h x_t + r_t \odot U_h h_{t-1} + b_h)
h_t = (1 - z_t) \odot \tilde{h}_t + z_t \odot h_{t-1}
P_{\mathrm{LSTM}} = 4(HD + H^2 + H)
P_{\mathrm{GRU}} = 3(HD + H^2 + H)

Where:

  • h_t is the hidden state emitted at step t and c_t the LSTM’s internal cell state; both start from zero at t = 0.
  • x_t is the input at step t, with D its width and H the hidden width.
  • f_t, i_t, o_t are the LSTM forget, input, and output gates and \tilde{c}_t its candidate, each of the form \sigma(Wx_t + Uh_{t-1} + b) (with \tanh for the candidate).
  • z_t and r_t are the GRU update and reset gates, both sigmoid, and \tilde{h}_t is its candidate state.
  • \odot is the elementwise product, \sigma the logistic sigmoid mapping to (0,1), and W, U, b the input, recurrent, and bias parameters of one gate block.
  • P counts recurrent-cell parameters only, so the ratio P_{\mathrm{GRU}}/P_{\mathrm{LSTM}} = 3/4 holds for any D and H.
Grouped bar chart on a log scale of recurrent parameter counts for hidden widths 128, 256, 512 and 1024 with input width equal to hidden width: LSTM bars are 0.13M, 0.53M, 2.10M and 8.39M while GRU bars are 0.10M, 0.39M, 1.57M and 6.29M

Figure 2: Recurrent parameters per layer with D = H: three gate blocks instead of four give the GRU exactly 0.75x the LSTM count at every width, so at H = 512 one layer holds 1.57M against 2.10M.

PropertyGRULSTM
Gates2: update, reset3: forget, input, output
State carriedHidden state onlyHidden state plus cell state
Weight blocks34
Params at D = H = 5121.57M2.10M
Memory exposureWhole state is exposed downstreamOutput gate filters what leaves the cell
Unbounded countingNo: state stays bounded by the convex updateYes: additive, unsquashed cell state
Where it tends to winSmall data, short sequences, tight latencyLong sequences, large corpora, language modeling

Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *