3.5.1 · D3Sequence Models

Worked examples — Recurrent Neural Networks (RNN) architecture

3,383 words15 min readBack to topic

This page is the "get your hands dirty" companion to Recurrent Neural Networks (RNN) architecture. We take the two equations of an RNN cell and run them by hand through every kind of situation they can meet: the very first step with no memory, a middle step, the sign behaviour of , saturation toward both and , the tiny-weight and huge-weight limits, negative recurrence, a nonzero hidden bias, a nonzero output bias, a real word problem, and an exam-style twist.

Before anything else, let us make sure every symbol is earned.

Figure — Recurrent Neural Networks (RNN) architecture

Read the figure like this: the horizontal axis is (the pre-activation), the vertical axis is . The pale-yellow curve is ; the two blue dashed lines are the hard ceilings at and ; the pink dotted line is , showing that near the origin barely bends. Every worked example is really just "find where your lands on this curve."

To keep the arithmetic honest and checkable, all worked examples use 1-dimensional state (one number for , one for ). The logic is identical for vectors — you just replace numbers with matrix–vector products.

Our fixed toy cell (unless a problem overrides it):


The scenario matrix

Every situation the two equations can throw at you falls into one of these cells. The examples below are labelled with the cell they cover.

Cell Situation Why it's a distinct case
A First step, No memory term — tests the "cold start"
B Middle step, memory feeds in now non-zero
C Positive vs. negative input (sign of ) is odd: flips sign with input
D Saturating input, both tails ( and ) flattens → memory "maxed out" at
E Limiting weight (memoryless) RNN collapses to feedforward
F Limiting weight large (gradient blow-up) Foreshadows exploding gradients
G Real-world word problem (sentiment, many-to-one) Only final state used
H Exam twist: identical inputs, does settle? Fixed-point / convergence reasoning
I Negative recurrent weight Sign flips each step → oscillation
J Nonzero hidden bias and output bias Bias shifts the whole -axis / the output line

Cell A + B — cold start, then a middle step

About the next figure: it draws Example 1 unrolled — two yellow boxes side by side (one per time step), blue arrows feeding inputs up from below, and a pink arrow carrying the memory rightward from the first box into the second. That pink arrow is the recurrence.

Figure — Recurrent Neural Networks (RNN) architecture

Cell C — the sign of the input


Cell D — saturation, BOTH tails


Cell E & F — the two weight limits


Cell I — negative recurrent weight (oscillation)


Cell G — real-world word problem (many-to-one)


Cell J — nonzero biases shift the dynamics


Cell H — exam twist: does the state settle?

About the last figure: it plots (yellow dots, joined) against the time step, with the blue dashed line marking the fixed point . Watch the dots take smaller and smaller vertical jumps as they hug the dashed line — that shrinking gap is the contraction in action.

Figure — Recurrent Neural Networks (RNN) architecture

Tying it back together

Every one of the ten cells is just the same two equations — read under a different lighting:

  • Cell A/B showed the raw mechanics: cold start () then memory feeding in.
  • Cell C/D were about where lands on the S-curve: sign (odd symmetry) and both saturating tails ().
  • Cell E/F/I were about what does: zero → feedforward, large → blow-up, negative → oscillation. Sign chooses direction, magnitude chooses decay vs. growth.
  • Cell J separated the two biases: moves the memory's resting point (inside ), moves the output line (outside).
  • Cell G/H were the payoff: a real many-to-one classifier, and the fixed-point reasoning that explains why memory fades when .

The single thread through all of them: because squashes and contracts, a vanilla RNN is stable but forgetful — great for short dependencies, weak for long ones. That tension is exactly what Long Short-Term Memory (LSTM), Gated Recurrent Unit (GRU), and later the Attention Mechanism and Transformers were built to resolve.

Cold start h0 equals 0

Middle step memory feeds in

Sign of input flips h

Huge input saturates to plus or minus 1

Large W leads to blow up

Zero W becomes feedforward

Negative W oscillates

Bias bh shifts memory and by shifts output

Real world final state only

Same input converges to fixed point

Exploding gradients

Vanishing gradients

Recall Quick self-check

First step uses which memory value? ::: , so the term drops out. What is ? ::: The pre-activation — the sum before squashes it. Why is chosen over sigmoid for the hidden state? ::: It is zero-centred, range , keeping positive/negative signals balanced and gradients healthier. What does turn the RNN into? ::: A memoryless feedforward network applied per step. What does a negative do? ::: Flips the memory's sign every step, causing oscillation; magnitude makes it decay. What is the difference between and ? ::: is added inside and shifts the memory's resting point; is added outside on the output line and shifts every by a constant. Why does memory settle when ? ::: The update map is a contraction (slope ), so iterates converge to a unique fixed point — but old signals also decay. Which cell foreshadows exploding gradients? ::: Cell F, large : forward caps values, but backward each step multiplies by .