Home / Deep Learning

What is RNN?

Take a microscopic look inside a single Recurrent Neural Network block. Visualize how it simply merges past memory with new input data to generate a new context state.

Waiting for Data...

Internal Flow

$H_{t-1} \to H_t$ (Hidden State)
$X_t$ (New Input Data)
Neural Network Layer (W)
Mathematical Operations
$+$
Vector Concatenation / Add

Inside the RNN: Unpacking the Cell

The internal architecture of a standard Recurrent Neural Network block is wonderfully simple. It takes its past memory, merges it with the present, and squashes it through a single neural layer to create the future state.

The Core Idea: The Hidden State

Unlike standard feed-forward networks, RNNs pass a single vector of context forward through time. This is the Hidden State ($H_t$).

Inside the cell, there is no complex long-term conveyor belt (like in an LSTM). There is only this singular hidden state, serving as both the short-term working memory and the network's output representation for that specific step.

Step-by-Step Flow

When the simulation runs, watch the data flow through these sequential steps inside the cell:

  1. 1. Receiving Inputs: The block takes in two pieces of information: the brand new input vector from the current step ($X_t$) coming from the bottom, and the context vector from the previous step ($H_{t-1}$) coming from the left.
  2. 2. Concatenation: These two inputs are merged (concatenated) together. By combining them, the network can look at "what just happened" and "what happened before" simultaneously.
  3. 3. The Neural Layer ($\tanh$): The merged vector is multiplied by a set of shared weights ($W$) and passed through an activation function, typically tanh (hyperbolic tangent). This function squashes the numbers so they stay smoothly between -1 and 1, preventing the values from exploding to infinity as the loop repeats.
    Math: $H_t = \tanh(W_{hx} \cdot X_t + W_{hh} \cdot H_{t-1} + b_h)$
  4. 4. Outputting the New State: The result of this calculation is the brand new Hidden State ($H_t$). This vector is split: a copy is sent upwards to be used for a prediction ($Y_t$), and a copy is sent rightwards to be passed into the next RNN block as memory.

The Vanishing Gradient Problem

Because the standard RNN only has this simple $tanh$ calculation repeated over and over, it suffers heavily from Vanishing Gradients. When it tries to learn connections across long sequences (e.g., matching a word at the end of a long paragraph to one at the beginning), the learning signal multiplied repeatedly through the layers shrinks to almost zero. This is why more complex architectures like LSTMs were invented!

Cheat sheet

RNN Architecture

Take a microscopic look inside a single Recurrent Neural Network block. Visualize how it simply merges past memory with new input data to generate a new context state.

NLP · vizlearn.in/natural_language_processing/rnn_architecture.html