Machine Learning

Recurrent Neural Network

Recurrent Neural Network.

Recurrent Neural Network (RNN)

Concept Overview

A Recurrent Neural Network (RNN) is a class of artificial neural networks designed to recognize patterns in sequences of data, such as text, genomes, handwriting, or the spoken word. Unlike feedforward neural networks that process inputs independently, RNNs maintain an internal state (or memory) to capture information about what has been calculated so far. This memory allows them to exhibit dynamic temporal behavior and process sequences of variable length.

Mathematical Definition

The defining feature of an RNN is its hidden state, which is updated at each time step based on the current input and the previous hidden state. The basic update rule for a simple RNN (often called an Elman network) is:

ht = σ( Whhht-1 + Wxhxt + bh )

Where:

  • ht is the hidden state vector at time step t.
  • xt is the input vector at time step t.
  • Whh is the recurrent weight matrix connecting the previous hidden state to the current one.
  • Wxh is the input weight matrix connecting the current input to the hidden state.
  • bh is the bias vector for the hidden state.
  • σ is a non-linear activation function, typically tanh or ReLU.

The output (if required) at time step t is typically computed as:

yt = f( Whyht + by )

Key Concepts

  • Hidden State (Memory): The vector ht acts as the network's memory. It encodes information about all previous inputs in the sequence up to time t, enabling context-dependent processing.
  • Weight Sharing: Unlike feedforward networks where each layer has distinct weights, an RNN applies the exact same weights (Whh, Wxh, Why) across all time steps. This parameter sharing drastically reduces the model size and allows it to generalize across positions in the sequence.
  • Backpropagation Through Time (BPTT): To train an RNN, the network is conceptually "unrolled" across time, transforming it into a deep feedforward network where each layer represents a time step. Standard backpropagation is then applied to calculate gradients.
  • Vanishing and Exploding Gradients: A major challenge in training simple RNNs. Because the recurrent weight matrix Whh is multiplied repeatedly during BPTT, gradients can shrink to zero (vanishing) or grow uncontrollably (exploding) for long sequences. This makes it difficult for standard RNNs to learn long-range dependencies.

Historical Context

The foundations of recurrent networks were laid in the 1980s. John Hopfield introduced the Hopfield network in 1982, an early form of RNN serving as a content-addressable memory system. In 1990, Jeffrey Elman introduced the "Simple Recurrent Network" (SRN), which popularized the concept of maintaining a context unit to process sequential inputs like sentences.

However, the difficulty of training RNNs on long sequences (due to vanishing gradients) severely limited their practical application. This led to the development of more advanced recurrent architectures, most notably the Long Short-Term Memory (LSTM) network introduced by Sepp Hochreiter and Jürgen Schmidhuber in 1997, which introduced a gating mechanism to regulate the flow of information and preserve gradients over long durations.

Real-world Applications

  • Natural Language Processing (NLP): Used historically in machine translation, text generation, and sentiment analysis (though largely superseded by Transformers in modern LLMs).
  • Speech Recognition: Converting spoken audio sequences into text transcriptions.
  • Time Series Forecasting: Predicting future values based on historical sequential data, such as stock prices, weather patterns, or energy demand.
  • Music Generation: Learning the sequential patterns of notes and chords to compose new melodies.
  • Video Analysis: Processing frames of a video sequentially for action recognition or captioning.

Related Concepts

  • Gradient Descent — The optimization algorithm used to train RNNs via BPTT.
  • Attention Mechanism — A modern technique that addresses the long-range dependency limitations of RNNs, eventually leading to the Transformer architecture.

Experience it interactively

Adjust parameters, observe in real time, and build deep intuition with Riano’s interactive Recurrent Neural Network module.

Try Recurrent Neural Network on Riano →

More in Machine Learning