# Gated recurrent unit

Gated recurrent units (GRUs) are a gating mechanism in recurrent neural networks, introduced in 2014 by Kyunghyun Cho et al. The GRU is like a long short-term memory (LSTM) with a forget gate, but has fewer parameters than LSTM, as it lacks an output gate. GRU's performance on certain tasks of polyphonic music modeling, speech signal modeling and natural language processing was found to be similar to that of LSTM. GRUs have been shown to exhibit better performance on certain smaller and less frequent datasets.

## Architecture

There are several variations on the full gated unit, with gating done using the previous hidden state and the bias in various combinations, and a simplified form called minimal gated unit.

The operator $\odot$ denotes the Hadamard product in the following.

### Fully gated unit

Initially, for $t=0$ , the output vector is $h_{0}=0$ .

{\begin{aligned}z_{t}&=\sigma _{g}(W_{z}x_{t}+U_{z}h_{t-1}+b_{z})\\r_{t}&=\sigma _{g}(W_{r}x_{t}+U_{r}h_{t-1}+b_{r})\\{\hat {h}}_{t}&=\phi _{h}(W_{h}x_{t}+U_{h}(r_{t}\odot h_{t-1})+b_{h})\\h_{t}&=(1-z_{t})\odot h_{t-1}+z_{t}\odot {\hat {h}}_{t}\end{aligned}} Variables

• $x_{t}$ : input vector
• $h_{t}$ : output vector
• ${\hat {h}}_{t}$ : candidate activation vector
• $z_{t}$ : update gate vector
• $r_{t}$ : reset gate vector
• $W$ , $U$ and $b$ : parameter matrices and vector
• $\sigma _{g}$ : The original is a sigmoid function.
• $\phi _{h}$ : The original is a hyperbolic tangent.

Alternative activation functions are possible, provided that $\sigma _{g}(x)\in [0,1]$ .

Alternate forms can be created by changing $z_{t}$ and $r_{t}$ • Type 1, each gate depends only on the previous hidden state and the bias.
{\begin{aligned}z_{t}&=\sigma _{g}(U_{z}h_{t-1}+b_{z})\\r_{t}&=\sigma _{g}(U_{r}h_{t-1}+b_{r})\\\end{aligned}} • Type 2, each gate depends only on the previous hidden state.
{\begin{aligned}z_{t}&=\sigma _{g}(U_{z}h_{t-1})\\r_{t}&=\sigma _{g}(U_{r}h_{t-1})\\\end{aligned}} • Type 3, each gate is computed using only the bias.
{\begin{aligned}z_{t}&=\sigma _{g}(b_{z})\\r_{t}&=\sigma _{g}(b_{r})\\\end{aligned}} ### Minimal gated unit

The minimal gated unit is similar to the fully gated unit, except the update and reset gate vector is merged into a forget gate. This also implies that the equation for the output vector must be changed:

{\begin{aligned}f_{t}&=\sigma _{g}(W_{f}x_{t}+U_{f}h_{t-1}+b_{f})\\{\hat {h}}_{t}&=\phi _{h}(W_{h}x_{t}+U_{h}(f_{t}\odot h_{t-1})+b_{h})\\h_{t}&=(1-f_{t})\odot h_{t-1}+f_{t}\odot {\hat {h}}_{t}\end{aligned}} Variables

• $x_{t}$ : input vector
• $h_{t}$ : output vector
• ${\hat {h}}_{t}$ : candidate activation vector
• $f_{t}$ : forget vector
• $W$ , $U$ and $b$ : parameter matrices and vector