3.5.1 · D1Sequence Models

Foundations — Recurrent Neural Networks (RNN) architecture

3,729 words17 min readBack to topic

Before you can read a single line of the parent note, you must be fluent with the pieces it silently assumes: what a vector is, what a weight matrix does to a vector, what the superscript means, why we bother with , and what a gradient is. This page builds each one from absolutely nothing, in an order where each idea leans only on the ones before it.


1. A number, a list of numbers, a vector

Start with the smallest thing: a single number, like or . We call a lone number a scalar — "scalar" just means "one number, no direction." Ordinary numbers like these (including fractions and decimals, positive or negative) are called real numbers, and mathematicians give the whole collection of them a name: . So is just shorthand for "all the ordinary numbers on the number line."

Now stack several numbers into an ordered list:

That ordered list is a vector. "Ordered" matters: the first slot and the second slot mean different things and you may not swap them.

Figure — Recurrent Neural Networks (RNN) architecture

Why does the RNN need this? Because every single thing an RNN handles — the input word , the memory , the output — is a vector. A word like "movie" is turned into a list of 300 numbers (that's what Word Embeddings do). The memory is a list of, say, 128 numbers. The whole topic is about vectors flowing and changing.

So when the parent note writes , translate it to: "the input at time is a list of ordinary numbers." Nothing scarier than that.


2. The superscript — a clock, not a power

This trips up everyone, so read carefully. When you see , the in round brackets is not an exponent. It is a time stamp.

So the sequence is: the piece we read at tick 1, the piece at tick 2, and so on, up to the last tick . Here (capital) is just the length of the sequence — how many pieces there are in total.

Why the topic needs it: an RNN's whole purpose is to process things in order over time, so it needs a notation that says "this thing, at this tick." That is exactly .


3. A weight matrix — a machine that reshapes a vector

Next assumed piece: the capital- symbols like , , . Each is a matrix — a rectangular grid of numbers.

Here is the only fact about matrices you truly need:

Concretely, each output number is a weighted sum of all input numbers. For example:

Figure — Recurrent Neural Networks (RNN) architecture

Why the topic needs three different 's, and what the subscripts mean:

The dimensions in the parent, e.g. , now read plainly: "a machine that eats a -slot input and outputs a -slot vector" — exactly the shape needed to feed the memory.


4. Adding vectors and the bias

Inside there are plus signs between vectors. Vector addition is the easy one: line them up and add slot by slot.

The last term is the bias — just a fixed vector that gets added on every time. Why do we need it? Because without a bias, when the input is all zeros the result is forced to be zero; the bias lets the network shift its output to any baseline it wants. It is the "+ c" of the linear world. (There is a second bias, , for the output step — same idea, we meet it in §7.)

So the whole expression means: reshape the old memory, reshape the new input, add both together, then nudge by a fixed offset. We give this pre-squash result its own name, (a "pre-activation"):


5. Why ? The squasher

The parent wraps that in : . Before asking why , know what it is.

Figure — Recurrent Neural Networks (RNN) architecture

Why the topic needs it: without , the memory update would be purely linear and the RNN could not model anything interesting. The squash also keeps the memory numbers bounded in so they don't blow up as they cycle around the loop tick after tick.


6. The recurrence — the loop that makes it "recurrent"

Now assemble the two pieces the parent's core equation is made of:

Read it left to right as a story: "The new memory is built from (a reshaped copy of the old memory ) plus (a reshaped copy of the new input ), all squashed by ."

The single crucial thing: the old memory appears on the right, and the new memory comes out on the left — then next tick, that becomes the "old" one. The output feeds back into the input. This feed-back loop is the entire meaning of the word recurrent.

Figure — Recurrent Neural Networks (RNN) architecture

The starting point : at the very first tick there is no "previous memory," so we set (a vector of all zeros — the boldface means "the zero vector, every slot 0," matching our bold-is-a-vector rule from the top of the page). This is the "blank mind before reading anything" case, and you must always handle it explicitly.


7. From memory to output: , softmax, and sigmoid

The memory is internal bookkeeping. To actually say something, the RNN turns it into an output vector with one more reshape-plus-bias:

Here is the hidden-to-output matrix from §3 and is the output bias (the second bias promised in §4). The raw numbers in are called scores or "logits" — they can be any size, positive or negative, and don't yet mean anything friendly. We convert them depending on the task.

Why the topic needs both: softmax answers "which of many?", sigmoid answers "how likely is this one thing?". Both convert raw scores into honest probabilities.


8. Loss, gradient, and how the RNN learns — from zero

The training section of the parent talks about a total loss and its gradient . Here is the from-zero version, and we start by clearing up the two loss symbols.

Now the piece the parent leans on but never builds from zero: the gradient, and why it points where it does.


How these foundations feed the topic

Scalar and real number R

Dimension R^d

Vector addition and bias b

Matrix reshapes a vector W x

Time index superscript t

Sequence x1 to xT

Recurrence h_t from h_t-1 and x_t

tanh squasher

Output y = W_hy h + b_y

Softmax and sigmoid probabilities

Cross-entropy loss L

Total loss and gradient

Vanishing exploding gradients

RNN architecture parent topic

This whole map feeds the parent: RNN architecture. Downstream, the same foundations power Sequence-to-Sequence Models, the Attention Mechanism, and Transformers.


Equipment checklist

What is a vector, in one sentence?
An ordered list of numbers — pictured as an arrow/point in a space with as many axes as slots.
What does the symbol mean, and ?
= all ordinary real numbers on the number line; = the space of lists of such numbers.
What does the bracketed superscript in mean?
A time stamp ("the value at tick "), NOT an exponent.
What does a matrix do to a vector?
Eats an -slot vector and outputs an -slot vector by stretching/rotating/mixing its numbers.
What do the subscripts in tell you?
"From to " — the source space and the destination space of the reshaping.
How do you add two vectors?
Slot by slot; pictorially, do one journey then the next arrow's journey.
What is the bias for, and how many biases are there?
A fixed added offset so the output isn't forced to zero; there are two — for the hidden update and for the output.
Why apply instead of nothing?
Its bend (non-linearity) lets the network learn curvy patterns; stacking only linear maps collapses to one straight-line map.
Why rather than sigmoid for the hidden state?
It is zero-centered ( to ) and has a steeper middle slope, keeping memory balanced and gradients healthier.
What makes an RNN "recurrent"?
The memory output loops back to become the input of the next tick.
What is set to and why?
The zero vector — the blank memory before any input is read.
How is the output computed from the memory?
— one reshape by plus the output bias .
What is the exponential ?
Raise the constant to the power ; always positive and fast-growing.
What does softmax produce and when do you use it?
A list of positive numbers summing to 1 (probabilities); use it to pick one option out of many.
What does the sigmoid produce?
A single number in — the probability of a yes/no answer.
What is the difference between and ?
is the wrongness at one tick; is the sum of all the per-tick 's over the whole sequence.
What form does the target take for a pick-one task?
A one-hot vector — in the correct option's slot , everywhere else.
What is the per-step loss , typically?
Cross-entropy for the correct class — "how surprised were we by the truth?"
What is a gradient, and why does training need it?
The grid of slopes of per weight; it points uphill so we step opposite (gradient descent) to reduce loss.
What is the gradient-descent update rule?
— step against the gradient by learning rate .
Why do RNN gradients vanish or explode?
Reaching back over many ticks multiplies a similar factor once per step — under 1 shrinks to 0, over 1 blows up.