Feedforward networks, like the MLPs we've discussed, process inputs independently. If you feed an MLP the same input twice, it produces the same output, unaware of any previous interactions. This works well for many tasks, but what about data where order matters? Consider predicting the next word in a sentence, analyzing stock market trends, or transcribing speech. The meaning or prediction often depends heavily on what came before. Feedforward networks lack an inherent mechanism to remember past information in the sequence.
Recurrent Neural Networks (RNNs) are designed specifically to handle this kind of sequential information. The core idea is recurrence: processing sequence elements one by one while maintaining an internal memory, often called the hidden state.
Imagine reading a sentence. You don't process each word in isolation. Your understanding of the current word is influenced by the words you've already read. RNNs mimic this process. At each step (e.g., for each word in a sentence or each point in a time series), the RNN performs a calculation based on two things:
This calculation produces a new hidden state (ht) which captures information from the current input and relevant context from the past. This hidden state ht is then passed forward to the next time step (t+1), acting as the network's memory of what it has seen so far.
This "looping" mechanism, where the output of a step feeds back into the input of the next step (via the hidden state), is what makes the network recurrent. Crucially, the same set of weights and biases are used for the calculation at every time step. This parameter sharing makes RNNs efficient and allows them to generalize patterns across different positions in sequences of varying lengths.
We can represent the update of the hidden state at time step t mathematically. A common formulation uses an activation function (like tanh
or ReLU
) applied to a combination of the current input and the previous hidden state:
Here:
tanh
).The network might also produce an output yt at each time step, often calculated based on the current hidden state:
yt=g(Whyht+by)Where:
softmax
for classification).Visually, we can think of "unrolling" the recurrence over time. The diagram below shows a simple RNN unrolled for three time steps. Notice how the hidden state h is passed from one step to the next, carrying information along the sequence.
An RNN cell unrolled over time. The hidden state
h
acts as memory, carrying information from one time step to the next. The same weights (W_hh
,W_xh
,W_hy
) are applied at each step.
This recurrent structure, centered around the evolving hidden state, allows RNNs to capture dependencies between elements in a sequence, making them suitable for tasks involving natural language, time series data, and other ordered inputs where context is significant.
© 2025 ApX Machine Learning