17 GRU, LSTM

1 GRU (Gated Recurrent Unit)

Recall formula for RNN. The basic problem is that rt depends on rt−1 through Wrrt−1. If Wr is a matrix with spectral radius less than 1, Wrrt−1 can be thought of as "reducing" rt−1 by a factor of Wr. Applied repeatedly, rt,ru 's dependence will be very small. So rt should connect to rt−1 not only through Wrrt−1.

We first construct a potential version r~t of rt: (1.1)r~t=σ(Wrrt−1+Wxt+b). Two natural options:

The idea behind GRU is to combine them rt=ztrt−1+(1−zt)r~t. This would exactly be a convex combination if zt were a scalar in [0,1], but zt is allowed to be a vector, so we'd better write rt=zt⊙rt−1+(1−zt)⊙r~t.
For zt, we take (1.2)zt=σsigmoid(Wrzrt−1+Wzxt+bz),, where σsigmoid(u)=11+e−u. We sometimes refer to zt as a gate. It controls the closeness of rt to rt−1 and r~t.

rt−1 appears in both zt⊙rt−1 and r~t. It might be redundant. So GRU modifies (1.1) by using one more gate: r~t=σ(Wr(rt−1⊙gt)+Wxt+b), where gt controls the extent to which rt−1 is used in the formula for r~t. Similar to (1.2), gt=σsigmoid(Wrgrt−1+Wgxt+bg).
Putting all the formulae together: r0=0,gt=σsigmoid(Wrgrt−1+Wgxt+bg),zt=σsigmoid(Wrzrt−1+Wzxt+bz),(1.3)r~t=σtanh(Wr(rt−1⊙gt)+Wxt+b),rt=zt⊙rt−1+(1−zt)⊙r~t,μt=β0+βTrt.
zt is called the update gate while gt is called the reset gate. Unknown parameters are Wrg,Wg,bg,Wrz,Wz,bz,Wr,W,b,β0,β.

LSTM (Long Short Term Memory)

This is another modification to the basic RNN for enabling long memory. It has one more gate compared with GRU. Instead of a recursion directly between rt−1 and rt, LSTM recursions are between (st−1,rt−1)→(st,rt).

We again construct a potential version: (2.1)r~t=σ(Wrrt−1+Wxt+b).
In LSTM, st is taken to be a linear combination of st−1 and r~t with gates controlling both coefficients of the linear combination: st=ft⊙st−1+it⊙r~t, where ft,it denote gates. rt is defined usually as σtanh(st). In LSTM, we add a gate to rt: rt=ot⊙σtanh(st).
Putting everything together, we obtain the full LSTM model: r0=0,ft=σsigmoid(Wrfrt−1+Wfxt+bf),it=σsigmoid(Wrirt−1+Wixt+bi),ot=σsigmoid(Wrort−1+Woxt+bo),(2.2)r~t=σtanh(Wrrt−1+Wxt+b),st=ft⊙st−1+it⊙r~t,rt=ot⊙σtanh(st),μt=β0+βTrt.
ft is called the forget gate, it is called the input gate and ot is called the output gate. Unknown parameters are Wrf,Wf,bf,Wri,Wi,bi,Wro,Wo,bo,Wr,W,b,β0,β.