Back Propagation through time in RNN (original) (raw)

Last Updated : 18 May, 2026

Recurrent Neural Networks (RNNs) are designed for sequential data such as text, speech and time series. Unlike traditional neural networks, RNNs use an internal memory (hidden state) so the output depends on both current and previous inputs.

RNN Architecture

At each timestep t , the RNN maintains a hidden state S_t​, that stores information from previous inputs. The hidden state S_t​ updates by combining the current input X_t​ and the previous hidden state S_{t-1} , applying an activation function to introduce non-linearity. Then the output Y_t ​is generated by transforming this hidden state.

S_t = g_1(W_x X_t + W_s S_{t-1})

Y_t = g_2(W_y S_t)

where g_1​ and g_2​ are activation functions.

frame_3331

RNN Architecture

Error Function at Time t=3

To train the network, we measure how far the predicted output Y_t ​ is from the desired output d_t​ using an error function. We use the squared error to measure the difference between the desired output d_t and actual output Y_t:

E_t = (d_t - Y_t)^2

At t=3:

E_3 = (d_3 - Y_3)^2

This error quantifies the difference between the predicted output and the actual output at time 3.

Updating Weights Using BPTT

Backpropagation Through Time (BPTT) updates the weights W_y, W_s, W_x by computing gradients across multiple time steps to minimize error.

1. Adjusting Output Weight W_y

The output weight W_y​ directly affects the current output Y_3​, so its update depends only on the current time step.

Using the chain rule:

\frac{\partial E_3}{\partial W_y} = \frac{\partial E_3}{\partial Y_3} \times \frac{\partial Y_3}{\partial W_y}

frame_3334

Adjusting Wy

2. Adjusting Hidden State Weight W_s

The hidden state weight W_s​ affects both the current and previous hidden states because each hidden state depends on the one before it. Therefore, updating W_s​, requires considering how all hidden states S_1, S_2, S_3 influence the output at time step 3.

\frac{\partial E_3}{\partial W_s} = \sum_{i=1}^3 \frac{\partial E_3}{\partial Y_3} \times \frac{\partial Y_3}{\partial S_i} \times \frac{\partial S_i}{\partial W_s}

**Gradient Flow Through Hidden States

frame_3332

Adjusting Ws

3. Adjusting Input Weight W_x​

Similar to W_s​, the input weight W_x​ affects all hidden states because the input at each timestep shapes the hidden state. The process considers how every input in the sequence impacts the hidden states leading to the output at time 3.

\frac{\partial E_3}{\partial W_x} = \sum_{i=1}^3 \frac{\partial E_3}{\partial Y_3} \times \frac{\partial Y_3}{\partial S_i} \times \frac{\partial S_i}{\partial W_x}

The process is similar to W_s​, accounting for all previous hidden states because inputs at each timestep affect the hidden states.

frame_3333

Adjusting Wx

Advantages

Limitations

Related Article: