Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:LaurentMazare Tch rs Recurrent Neural Network

From Leeroopedia
Revision as of 17:21, 16 February 2026 by Admin (talk | contribs) (Auto-imported from principles/LaurentMazare_Tch_rs_Recurrent_Neural_Network.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Deep Learning, Sequence Modeling, Natural Language Processing
Last Updated 2026-02-08 00:00 GMT

Overview

Recurrent neural networks process sequential data by maintaining a hidden state that is updated at each time step, with gated variants (LSTM, GRU) designed to capture long-range dependencies.

Description

Recurrent neural networks (RNNs) are a class of neural architectures designed for sequential data where the order of elements matters. At each time step, an RNN takes the current input and its previous hidden state, producing an updated hidden state and optionally an output. This hidden state serves as the network's memory, accumulating information from all previously seen elements in the sequence.

The basic (vanilla) RNN suffers from the vanishing gradient problem: gradients diminish exponentially as they are backpropagated through many time steps, making it difficult to learn dependencies between distant elements. Two gated architectures address this limitation:

Long Short-Term Memory (LSTM) introduces a separate cell state that flows through the network with minimal transformation, acting as a "conveyor belt" for information. Three gates control information flow:

  • Forget gate -- Decides what information to discard from the cell state
  • Input gate -- Decides what new information to store in the cell state
  • Output gate -- Decides what information from the cell state to output as the hidden state

Gated Recurrent Unit (GRU) simplifies the LSTM architecture by merging the cell state and hidden state into a single state vector. It uses two gates:

  • Reset gate -- Controls how much of the previous hidden state to forget when computing the candidate new state
  • Update gate -- Controls the interpolation between the previous hidden state and the candidate new state

Both LSTM and GRU can be stacked into multiple layers, where the output sequence from one layer becomes the input to the next. Bidirectional variants process the sequence in both forward and reverse directions, concatenating the resulting hidden states.

Usage

Apply recurrent architectures when:

  • Processing time series, audio, or text data where temporal order is significant
  • The input and/or output are variable-length sequences
  • Long-range dependencies must be captured (prefer LSTM or GRU over vanilla RNN)
  • Building seq2seq models, language models, or sequence classifiers

Theoretical Basis

Vanilla RNN

At each time step t, given input xt and previous hidden state ht1:

ht=tanh(Wihxt+bih+Whhht1+bhh)

The vanishing gradient arises because hTh1=t=2Ththt1, which tends toward zero when the spectral radius of the Jacobian is less than 1.

LSTM

The LSTM introduces cell state ct alongside hidden state ht:

Forget gate: ft=σ(Wfxt+Ufht1+bf)

Input gate: it=σ(Wixt+Uiht1+bi)

Cell candidate: c~t=tanh(Wcxt+Ucht1+bc)

Cell state update: ct=ftct1+itc~t

Output gate: ot=σ(Woxt+Uoht1+bo)

Hidden state: ht=ottanh(ct)

The cell state update ct=ftct1+ creates an additive gradient path, preventing vanishing gradients.

GRU

The GRU uses fewer parameters than LSTM:

Reset gate: rt=σ(Wrxt+Urht1+br)

Update gate: zt=σ(Wzxt+Uzht1+bz)

Candidate state: h~t=tanh(Whxt+Uh(rtht1)+bh)

Hidden state: ht=(1zt)ht1+zth~t

The update gate zt controls interpolation between the old and new states, allowing the GRU to either retain previous information or incorporate new information.

Bidirectional Processing

A bidirectional RNN runs two separate recurrent networks -- one processing the sequence forward and one backward. The outputs are concatenated:

htbi=[ht;ht]

This provides each position with context from both past and future elements.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment