In the realm of Recurrent Neural Networks (RNNs), gates play a important role in determining what information from the previous time step should be retained or discarded. These gates serve as adaptive mechanisms that enable RNNs to selectively update their hidden states, allowing them to capture long-term dependencies in sequential data. In this answer, we will consider the inner workings of these gates, namely the update gate, reset gate, and output gate, and provide a comprehensive explanation of their functionality.
The first gate we will explore is the update gate. This gate determines how much of the previous hidden state should be retained and how much of the new candidate state should be incorporated. It takes as input the previous hidden state, denoted as h(t-1), and the current input, denoted as x(t). These inputs are then passed through a sigmoid activation function, which squashes the values between 0 and 1, representing the update gate's ability to retain or discard information. Mathematically, the update gate can be represented as follows:
z(t) = sigmoid(W_z * x(t) + U_z * h(t-1) + b_z)
Here, W_z, U_z, and b_z are the weight matrix, recurrent weight matrix, and bias vector associated with the update gate, respectively. The resulting value, z(t), is an element-wise multiplication between the previous hidden state and the update gate's output. This multiplication allows the RNN to control the flow of information, enabling it to selectively retain or discard information from the previous time step.
Next, we move on to the reset gate. The purpose of the reset gate is to determine how much of the previous hidden state should be forgotten. Similar to the update gate, the reset gate takes the previous hidden state, h(t-1), and the current input, x(t), as inputs. These inputs are then passed through a sigmoid activation function, yielding the reset gate's output. Mathematically, the reset gate can be represented as follows:
r(t) = sigmoid(W_r * x(t) + U_r * h(t-1) + b_r)
Here, W_r, U_r, and b_r are the weight matrix, recurrent weight matrix, and bias vector associated with the reset gate, respectively. The reset gate's output, r(t), is then used to compute the candidate state, which represents the new information that will be incorporated into the hidden state. The candidate state is calculated by taking the element-wise multiplication between the reset gate's output and the previous hidden state, and passing it through a non-linear activation function, such as the hyperbolic tangent function. Mathematically, the candidate state can be represented as follows:
h'(t) = tanh(W_h * x(t) + U_h * (r(t) * h(t-1)) + b_h)
Here, W_h, U_h, and b_h are the weight matrix, recurrent weight matrix, and bias vector associated with the candidate state, respectively. The candidate state, h'(t), represents the new information that will be incorporated into the hidden state.
Finally, we come to the output gate. The output gate determines how much of the candidate state should be exposed as the output of the current time step. It takes the current input, x(t), and the previous hidden state, h(t-1), as inputs, which are then passed through a sigmoid activation function. Mathematically, the output gate can be represented as follows:
o(t) = sigmoid(W_o * x(t) + U_o * h(t-1) + b_o)
Here, W_o, U_o, and b_o are the weight matrix, recurrent weight matrix, and bias vector associated with the output gate, respectively. The output gate's output, o(t), is then used to compute the hidden state, which is the output of the current time step. The hidden state is calculated by taking the element-wise multiplication between the output gate's output and the candidate state, and passing it through a non-linear activation function. Mathematically, the hidden state can be represented as follows:
h(t) = o(t) * tanh(h'(t))
By using these gates, RNNs are able to selectively retain or discard information from the previous time step, incorporating new information as needed. This adaptability allows RNNs to capture long-term dependencies in sequential data, making them particularly effective in tasks such as natural language processing, speech recognition, and time series analysis.
Gates in RNNs determine what information from the previous time step should be retained or discarded through the use of update gates, reset gates, and output gates. The update gate controls how much of the previous hidden state should be retained or discarded, the reset gate determines how much of the previous hidden state should be forgotten, and the output gate regulates how much of the candidate state should be exposed as the output of the current time step. These gates enable RNNs to selectively update their hidden states, allowing them to capture long-term dependencies in sequential data.
Other recent questions and answers regarding Examination review:
- How is the output of an RNN determined based on the recurrent information, the input, and the decision made by the gates?
- How does the input in an RNN represent the new information being fed into the network at each time step?
- How do Long Short-Term Memory (LSTM) cells address the issue of long sequences of data in RNNs?
- What is the main advantage of using recurrent neural networks (RNNs) for handling sequential or temporal data?

