CS5720 - Week 6
Slide 107 of 120

RNN Forward Pass - Step by Step

How RNNs Process Sequences

An RNN forward pass processes sequences one element at a time, maintaining a hidden state that carries information from previous time steps.
Key Components:

Input sequence - x₁, x₂, x₃, ... xₜ
Hidden states - h₀, h₁, h₂, ... hₜ
Weight matrices - Wₓₕ, Wₕₕ, Wₕᵧ
Output sequence - y₁, y₂, y₃, ... yₜ
🔄 Recurrent Connection:
The hidden state from time t-1 is fed back as input at time t, creating the "memory" of past information.

Forward Pass Steps

  • 1️⃣
    Initialize Hidden State
    Start with h₀ = 0 (usually zeros)
  • 2️⃣
    Process First Input
    Combine x₁ and h₀ to compute h₁
  • 3️⃣
    Generate Output
    Compute y₁ from hidden state h₁
  • 4️⃣
    Repeat for Sequence
    Continue for x₂, x₃, ... until sequence end
  • 5️⃣
    Final Output
    Collect outputs y₁, y₂, ... yₜ

RNN Forward Pass Visualization

Time t=1
x₁ = "Hello"
+
h₀ = [0,0,0]
h₁ = [0.2,0.8,0.1]
y₁ = 0.3
Time t=2
x₂ = "world"
+
h₁ = [0.2,0.8,0.1]
h₂ = [0.5,0.3,0.9]
y₂ = 0.7
Time t=3
x₃ = "!"
+
h₂ = [0.5,0.3,0.9]
h₃ = [0.1,0.6,0.4]
y₃ = 0.9
Each time step: hₜ = tanh(Wₓₕ × xₜ + Wₕₕ × hₜ₋₁ + bₕ)
Prepared by Dr. Gorkem Kar