3.5.5 · D1Sequence Models

Foundations — Gated Recurrent Units (GRU)

2,661 words12 min readBack to topic

Before you can read a single GRU equation, you need to recognise the pieces it is built from. This page defines every symbol and every tool the parent note uses — from what a vector even is, up to the mixing formula — with a picture attached to each. Read top to bottom; each block earns the next.


1. What a sequence is, and why we index by

A GRU reads a sequence: an ordered list of things, one after another. In text, that list is the words of a sentence, left to right.

We label positions with a counter called the timestep, written . The first item is at , the next at , and so on. "" is just "which step are we on right now".

Figure — Gated Recurrent Units (GRU)

Look at the figure: reading the sentence is like walking a row of stepping stones. On each stone we do the same computation, but with new input. That "same computation, new input, memory carried across" pattern is exactly what a basic RNN does, and GRU is a smarter version of that stone.


2. Vectors — the shape of everything here

A word cannot be fed to math as letters. We turn it into a vector: a fixed-length list of numbers.

The symbol just means "the real numbers" (any decimal, positive or negative). means "a point in -dimensional space". You never have to picture 200 dimensions — picture an arrow of numbers whose length is .


3. The hidden state — the memory carried forward

This is the star symbol of the whole topic.

Because GRU (unlike LSTM, which also carries a separate cell state ) keeps only , this single vector is the machine's complete memory. That simplicity is the whole selling point.


4. Concatenation — stacking two vectors

The equations always feed the network both the old memory and the new word together. To do that we glue the two vectors into one taller vector.

Figure — Gated Recurrent Units (GRU)

Why concatenate? So a single matrix (next section) can look at old memory and new input simultaneously and decide based on their combination — e.g. "this word is 'but' and the memory so far is positive → prepare to flip".


5. The linear layer — the learnable "mixing board"

Inside every gate you see the pattern . This is the one operation neural nets are built from.

The parent note has three of these boards: (with biases ) — one for the reset gate, one for the update gate, one for the candidate.


6. Sigmoid — squashing into so a number becomes a "dial"

A gate must output a fraction between 0 (fully closed) and 1 (fully open). Raw can be any number, huge or negative. We need to squash it.

Why this tool and not another? We want a smooth, always-increasing knob that can never leave , so its output can be read directly as "keep this fraction". Sigmoid is the classic function with exactly those properties, and being smooth means we can train through it. This is why gates (, ) use .

Figure — Gated Recurrent Units (GRU)

Here is Euler's number (); shrinks fast as grows, which is what drags the output toward 1.


7. The two gates built from sigmoid — and

Now that we have , a concatenation, and a mixing board, we can build the two dials the whole topic is named for. Each gate is one linear layer followed by a sigmoid, so its output is a vector of dials in .

Notice both gates read the same input but have their own weights ( vs ), so they can learn to answer two different questions from the same evidence.


8. Tanh and the candidate memory

The candidate new memory uses tanh, not sigmoid. Different job, different squasher.

Why tanh here and sigmoid there? A gate answers "what fraction, 0 to 1?" → sigmoid. A memory value wants to represent features that can be positive or negative (e.g. "very positive sentiment" = , "very negative" = ), so it needs the range centred at 0 → tanh. Centring at 0 also keeps values from drifting, which helps training.

Figure — Gated Recurrent Units (GRU)

Now we can write the candidate hidden state — the "proposed new memory":


9. Hadamard product — element-wise multiply (the "gating" action)

This symbol is how a dial actually controls a memory vector.


10. The "1" in — a vector of ones

The final formula uses . But is a vector and looks like a single number — how do you subtract?


11. Putting the pieces into the mixing formula

Once all the above exist, the final GRU update reads cleanly:

Every symbol is now defined: is a sigmoid dial-vector, a tanh candidate (built using the reset gate ), the old memory (with ), the per-slot scaling, and the leftover fraction.


12. Why gates fix vanishing gradients (the motive)

The parent topic exists to beat the vanishing gradient problem. The key symbol there is : "how much does a tiny change in old memory change new memory?" Multiplied across many steps, if this is the effect shrinks toward zero and long-range learning dies. Because contains the term , this derivative gets a contribution — and when , information (and gradient) travels across many steps almost undamped. That is the whole payoff of building the update gate.


Prerequisite map

Sequence and timestep t

Vector and dimension

Hidden state h_t and seed h_0

Concatenation of two vectors

Linear layer W times v plus b

Sigmoid dial 0 to 1

Update gate z and reset gate r

Tanh candidate minus1 to 1

Candidate memory h-tilde uses r

Hadamard product element-wise

Gated mixing formula

Ones vector for 1 minus z

GRU cell

Each foundation on the left feeds the GRU cell on the right. Miss any node and an equation will contain a symbol you cannot read.


Equipment checklist

Test yourself — cover the right side and answer aloud.

What does the subscript in mean?
The position (timestep) in the sequence — which step we are on.
What does say about ?
It is a list of real numbers — a vector of dimension .
What is and why do we need it?
The seed memory before any input; set to the zero vector so is defined at .
What is and how long is it?
The two vectors stacked into one; length .
In , what is learned and what does do?
and are learned; mixes all inputs into weighted sums (a "mixing board"), shifts them.
Write the reset gate equation.
.
Write the update gate equation.
.
Write the candidate memory equation and say where enters.
; gates the old memory before it feeds the candidate.
Why do gates use sigmoid and the candidate use tanh?
Sigmoid gives a fraction in (a dial); tanh gives values in so memory can be positive or negative.
What does compute?
Element-wise product — multiply matching slots, no cross-slot sums.
In , what is the "1"?
The ones vector ; subtract each dial from 1 slot by slot.
In , what happens if ?
— the old memory is kept exactly, new candidate ignored.
Why does keeping help long-range memory?
The term passes memory (and gradient) forward almost undamped, avoiding vanishing gradients.

Related: Hinglish version · builds toward 3.5.06-Bidirectional-RNNs and 3.6.01-Attention-Mechanism.