3.5.6 · D1Sequence Models

Foundations — Bidirectional RNNs

2,813 words13 min readBack to topic

Before you can trust that one idea, you must own every symbol the parent note throws at you. This page builds each one from nothing: plain words → the picture → why the topic needs it, in an order where each brick rests on the last.


1. A sequence and its index

Picture a row of boxes on a shelf, numbered left to right. Box holds the first word, box holds the last.

Figure — Bidirectional RNNs

Why the topic needs it. "Bidirectional" only means anything because there is a direction — a first box and a last box. Without an ordered sequence, "forward" and "backward" would be meaningless. The whole page is built on walking this row of boxes in two opposite ways.


2. A vector: turning a word into numbers ( as an arrow of numbers)

A neural network cannot chew on the letters "Apple". It needs numbers. So each word in the box gets replaced by a short list of numbers called a vector.

Picture each number as a coordinate. Two numbers = a dot on a flat map; three numbers = a dot floating in a room. More than three we can't draw, but the idea is identical: a vector is a point / arrow in a space of dimensions.

Figure — Bidirectional RNNs

Why the topic needs it. Every arrow in the network is a vector; every "encode Apple + released" is really "move to a new point in this space". You cannot read the worked example without knowing that is a location, and that its length is what must match up when matrices multiply it.

Recall Why can't we just use the word itself?

Networks multiply and add; they need numbers, not letters. ::: A word is first mapped (embedded) to a numeric vector so arithmetic becomes possible.


3. The embedding: the map from word to vector

Picture a dictionary where the definition of each word is not text but a point on the map from §2. Similar words (king / queen) land near each other.

Why the topic needs it. Step 1 of the worked example is literally "embed the words". The vectors the parent lists come out of this table. This foundation feeds directly into everything downstream. (Depth on this is deferred; here we only need "word → fixed vector".)


4. Weights , bias , and matrix–vector multiply

The network's job is to transform one vector into another. The tool for a linear transform is a matrix.

Picture as stretching, rotating and squishing the arrow into a new arrow; then slides that arrow to a new spot.

Figure — Bidirectional RNNs

Why the topic needs it. Every line of the RNN update is a matrix–vector multiply plus a bias. The parent uses separate matrices for memory () and for the new word () precisely because a matrix is how you turn one meaning-vector into another, and each job needs its own grid of numbers — and its own shape.


5. : the squashing function

After stirring and shifting we get raw numbers that could be huge. We tame them with .

Picture an S-shaped curve lying flat at on the far left, passing through the origin, and flattening at on the far right.

Figure — Bidirectional RNNs

Why THIS tool and not just ? Two reasons. (1) Bounding: if we only ever multiplied and added, values could explode across many timesteps; caps every hidden number in , keeping the memory stable — that is exactly the parent's remark "tanh squashes to to prevent exploding values." (2) Nonlinearity: stacking pure matrices collapses to one matrix (still just a line); bends the space so the network can learn curved patterns.

Recall Why is a nonlinearity needed at all?

Because a chain of linear maps is itself linear — no extra expressive power. ::: bends the transformation so the network can represent complex, non-straight relationships.


6. The hidden state : the memory vector

Now the star of the show.

Picture a notepad you update after each box: read box , glance at your last note , scribble a new note that blends old memory with the new word.

Why the topic needs it. The entire bidirectional idea is "keep two separate notepads". Understanding as memory that flows in a direction is what lets §7's arrows make sense.


7. The direction arrows and

The parent writes little arrows over the letter . These are not vectors-vs-scalars; they mark which way we walked the shelf.

Picture two friends: one starts at box 1 and shuffles right, another starts at box and shuffles left. They meet at every box and each hands over a note.

Why the topic needs it. This is bidirectionality. answers "given all words before me, what am I?"; answers "given all words after me, what am I?". The whole point of the parent — distinguishing "Apple" the company from "apple" the fruit — needs to know "released iOS" comes next.


8. Concatenation

Picture gluing two short trains of boxes into one longer train — nothing is added or averaged; both lists survive intact, just side by side.

Why the topic needs it. The parent combines past and future by concatenation, not summation, "to preserve both". Knowing = stacking (so and give ) is required to read in the example (two length-3 notes glued).


9. : numbers into a probability decision

Finally we must decide a label for each word (is it an organization? a location?).

Picture a bar chart of raw scores; softmax reshapes the bars so their total height is exactly 1, letting you read each bar as "chance this is the answer".

Why THIS tool? We are classifying — choosing one of several tags. A classification needs a probability per class, and softmax is the standard way to get one from raw scores. That is exactly the parent's line "we're making a classification decision at each timestep." The output is a softmax result: all four numbers sum to .


How the foundations feed the topic

Sequence and index t

Word to vector via embedding

Vectors live in R to the n

Weight matrix times vector plus bias

tanh squashes the result

Hidden state h - the memory

Forward h and backward h

Concatenate the two notes

softmax gives the label

Bidirectional RNN

Each foundation is a prerequisite of the next; the last three (direction arrows, concatenation, softmax) are the parts unique to going bidirectional. These same bricks reappear when you meet LSTM and GRU Cells, the Encoder-Decoder Architecture, the Attention Mechanism, and Transformers — so time spent here pays forward.


Equipment checklist

Test yourself — you should be able to answer each before reading the parent's derivation.

What does stand for in ?
The total number of slots (words) in the sequence.
What does mean in one phrase?
The set of all lists of real numbers — an -dimensional space of points/arrows.
What is the difference between and ?
is the length of an input word-vector; is the length of a hidden-state (memory) vector.
Where does the vector come from?
From the embedding table that maps each word to a fixed numeric vector.
What single operation does perform on a vector?
A linear transform ("stir": stretch/rotate/squish) followed by a shift (add bias).
What shape must have, and why?
— it maps a length- word into a length- hidden vector, so it has rows and columns.
In , what job does each subscripted matrix do?
(shape ) stirs the old memory ; (shape ) stirs the new word ; shifts the sum — all landing in before .
Give the two reasons is applied.
(1) It bounds values into to prevent explosion; (2) it adds nonlinearity so the network can learn curved patterns.
In words, what is the hidden state ?
A running-summary memory vector of everything read up to slot .
What does the arrow in tell you?
The RNN walked left→right, so this note encodes the past (boxes to ).
What does encode and where does it start blank?
The future (boxes to ); it starts blank at the right, .
What does do, and what length results?
Stacks the two vectors end to end; if each is length the result is length .
What produces the raw scores that softmax turns into probabilities?
The output transform (with ), then softmax normalizes them over the label classes.