Proposition 3I.10.P0335 of 100 in the corpus
A GRU keeps one state and interpolates between keeping it and rewriting it.
The update gate weighs the old state against a candidate, so the direct derivative is a diagonal of gate values, as in the LSTM, with fewer parts. Papers and libraries write it two ways: which side the update gate multiplies is a relabelling, but where the reset gate acts changes the function.
One state, two gates
The gated recurrent unit, or GRU, was introduced by Cho and colleagues in 2014 for an encoder–decoder translation model. It drops the separate cell state and the output gate. In the form PyTorch documents,
PyTorch's convention: z near one keeps the old state, and the reset gate acts after the recurrent matrix.
The candidate plays the part of the LSTM’s . The update gate splits each coordinate between the old state and the candidate. The reset gate decides how much of the old state the candidate may read: with near zero, the candidate is computed almost as if the sequence had just begun.
Hold the gates and candidate fixed. The direct derivative is , the GRU’s carry line. It is the LSTM’s carry line with two constraints. The amount written is tied to the amount kept: plays the input gate and the forget gate. Greff and colleagues tested this coupling as one of their LSTM variants. And there is no output gate, so the carried state is the visible state.
That second constraint bounds the state. Each coordinate of is a convex combination of the old value and a candidate in , so . A state that starts in stays there. That is the GRU half of I.10.T3, proved in I.10.X07. The bound concerns values; the full derivative has other paths, through , and , exactly as in (I.10.4).
Read the equation, not the letter
Cho and colleagues wrote , which is PyTorch’s convention. Chung and colleagues, comparing gated units later the same year, wrote . In one, near one keeps; in the other, it overwrites.
The two describe the same family of functions. Since , negating the update gate’s weights and bias turns one convention into the other exactly. Weights trained under one convention and loaded under the other, without that conversion, do something else: with for ten steps, one reading keeps of the old state and the other (I.10.X06). A diagram labelled “update gate” does not say which. The equation does.
Where the reset gate acts
The original paper applies the reset gate before the recurrent matrix:
.
PyTorch applies it after, as in (I.10.7). Keras offers both through
reset_after, whose default is the after form, described as cuDNN compatible.
The two candidates are and . They agree for every exactly when commutes with . Entry by entry, that means : every weight connecting two coordinates with different reset values must be zero. A uniform reset satisfies the condition for any , and a diagonal satisfies it for any reset. Otherwise the functions differ. I.10.B04 gives a two-unit case where the same weights, state and gates produce mirror-image candidates.
The after form has a practical reason. The product no longer waits for , so all three recurrent products can be computed as one by matrix multiplication. It also has a cost in the count: the recurrent bias sits inside the reset and cannot be merged with , which adds parameters.
What the parts cost
Count with one bias per gate, the convention of (I.9.1) and (I.10.1):
Each gated block repeats the cost of a plain recurrent layer.
For and these are , or , and . PyTorch keeps two bias vectors per block, giving , and . The multiply–accumulate count per step scales the same way, for the LSTM against for the plain cell.
Equal width is therefore not an equal comparison. At a GRU of width six has parameters, exactly the LSTM’s at width five. Backpropagation through time also stores more per step: every gate value is needed again in (I.10.6). I.10.B05 audits shapes, counts and storage, and I.10.X10 scales the storage to a realistic batch.
Which one to use
The evidence does not crown either. Chung and colleagues found both gated units better than a tanh RNN on their polyphonic music and speech-signal tasks, and the GRU comparable to the LSTM. Jozefowicz, Zaremba and Sutskever evaluated over ten thousand architectures. They found one that beat both on some tasks but not all, and found that a forget bias of one closed the LSTM’s gap to the GRU. Greff and colleagues compared eight LSTM variants and found none significantly better than the standard cell; the forget gate and the output activation were its most critical parts.
The defensible procedure is a measured one. Compare at matched parameters or matched compute, with the forget bias set deliberately, over several seeds, on a validation split the comparison did not tune. Choose the GRU when its smaller cost matters and it holds its own; choose neither by reputation.
The same idea across depth
The GRU update is an interpolation between keeping a vector and replacing it. Nothing in that idea needs time. Srivastava, Greff and Schmidhuber applied it across layers:
where is a layer and a learned gate. With the gate near zero, a highway layer passes its input through, and its Jacobian is close to the identity. A residual connection, , drops the gate and keeps the identity path unconditionally: its Jacobian is .
The question this chapter answered for time is the general one. When a deep computation trains badly, look for a path from the loss back to the early parameters along which the derivative is near the identity. Gating, highway layers and residual connections are three answers. The transformer takes the third.
Reproduce the reset counterexample
from math import tanh
W = [[0.0, 1.0], [1.0, 0.0]]
h, r, z = [0.5, -0.5], [0.75, 0.25], 0.5
def matvec(m, v):
return [sum(a*b for a, b in zip(row, v)) for row in m]
before = [tanh(a) for a in matvec(W, [ri*hi for ri, hi in zip(r, h)])]
after = [tanh(ri*a) for ri, a in zip(r, matvec(W, h))]
for n in (before, after):
new = [(1 - z)*nj + z*hj for nj, hj in zip(n, h)]
print(" ".join(f"{v:.6f}" for v in n), "|",
" ".join(f"{v:.6f}" for v in new))
The first line is the reset-before candidate and new state, and . The second is the reset-after pair, and .
Sources
Depends on
Used by
Nothing yet.
Problems using this
- I.10.B04 — The same weights, two GRUscounterexample▲▲△
- I.10.B05 — What four gates costshape▲▲△
- I.10.X06 — Which side does z multiply?numeric▲△△
- I.10.X07 — The GRU state stays in the boxproof▲▲△
- I.10.X10 — What backpropagation through time keepscomplexity▲▲△