Lensa ML
Lensa ML

How RNNs Read Sequences

Explained through sentiment analysis

Step 1 of 6

The Task: Read & Judge

Given a movie review, decide — positive or negative?

Rearrange the same words
Themoviewasnotgood
WORD ORDER
OriginalSwappedShuffled
Sentiment
Negative
Score
-0.81
Words → Embeddings → RNN
The[0.1, 0.0, 0.0, 0.0]
movie[0.1, 0.3, 0.1, 0.1]
was[0.0, 0.0, 0.0, 0.0]
Each word is mapped to a numeric vector (embedding) before the RNN can process it
Word order matters
"not good" ≠ "good not"
Words → vectors
Embeddings encode meaning
Sequence needed
Can't judge one word alone

Drag the slider to rearrange words. Word order matters — "not good" is negative, but "good not" is confusing. Before an RNN can read text, each word must first be converted to a numeric embedding vector. The RNN then reads these embeddings one at a time, left to right, building up meaning sequentially.

Step 1 of 6: The Task: Read & Judge

Given a movie review, decide — positive or negative?

Rearrange the same words
Themoviewasnotgood
WORD ORDER
OriginalSwappedShuffled
Sentiment
Negative
Score
-0.81
Words → Embeddings → RNN
The[0.1, 0.0, 0.0, 0.0]
movie[0.1, 0.3, 0.1, 0.1]
was[0.0, 0.0, 0.0, 0.0]
Each word is mapped to a numeric vector (embedding) before the RNN can process it
Word order matters
"not good" ≠ "good not"
Words → vectors
Embeddings encode meaning
Sequence needed
Can't judge one word alone

Drag the slider to rearrange words. Word order matters — "not good" is negative, but "good not" is confusing. Before an RNN can read text, each word must first be converted to a numeric embedding vector. The RNN then reads these embeddings one at a time, left to right, building up meaning sequentially.

Step 2 of 6: Reading Word by Word

An RNN reads left to right, updating its understanding at each step

Reading:(start)
ht-1(4d)× W_hxt(4d)× W_x+tanhht(4d)feeds back next step
TIME STEP: 0 / 7
Initial Hidden State
h₀=[+0.000,+0.000,+0.000,+0.000]
All zeros — the RNN has read nothing yet. Step forward to see the math.
h0[0]
0.000
h0[1]
0.000
h0[2]
0.000
h0[3]
0.000
Sentiment
0.000
Step
0/7

Step through to see the full RNN calculation with real numbers. At each step: multiply the previous hidden state by Wh, the word embedding by Wx, add them, and apply tanh. Click the element buttons to expand each dot product. Watch how "not" flips the hidden state negative.

Step 3 of 6: The Hidden State Evolves

Watch the network's "mood" shift as it reads each word

Themoviewasnotreallythatgood
0+-Themoviewasnotreallythatgood
STEP THROUGH: 0 / 7
Weight Sharing
Every time step uses the same W_h and W_x — the RNN cell is reused, not copied.

When "unrolled," we see the same RNN cell repeated at each step. All copies share identical weights — this is what makes RNNs parameter-efficient. The sentiment bar shows how the internal state evolves as each word is read.

Step 4 of 6: Long Reviews, Short Memory

Vanilla RNNs forget earlier words — a critical flaw

SEQUENCE DEPTH: 6 steps
2 (short)8 (long)
GRADIENT MAGNITUDE AT EACH TIME STEP0.050t1lost!0.092t20.166t30.303t40.550t51.000t6gradients flow backward ← earlier steps lose signal
First Step Grad
0.0503
Last Step Grad
1.0000
Ratio
5.0%

Increase the depth to see gradients vanish exponentially. At each step, gradients are multiplied by ~0.55 — after 6 steps the first word's gradient is 0.0503. Early words can't learn. This is the vanishing gradient problem.

Step 5 of 6: LSTM: Selective Memory

Gates let the network choose what to remember and forget

CELL STATE — long-term memory highway×F0.50Forget+I0.50Input×O0.50Output
Forget Gate: 0.50
Input Gate: 0.50
Output Gate: 0.50
Prev Cell
0.80
New Cell
0.700
Hidden Out
0.302
f × c_prev
0.400
i × cand
0.300
o × tanh(c)
0.302

Drag each gate slider to see its effect. Forget gate at 0 erases old memory; at 1 it keeps everything. Input gate controls how much new info is written. Output gate filters what gets passed to the next step. Formula: c_t = f·c_(t-1) + i·candidate, h_t = o·tanh(c_t).

Step 6 of 6: The Final Verdict

The last hidden state holds enough context to classify the whole review

RNN reads word by word:Themoviewasnotreallythatgood
TIME STEP: 0 / 7
h[0]
0.000
h[1]
0.000
h[2]
0.000
h[3]
0.000
Sentiment
0.000
Prediction
Positive
Confidence
0%
NegativePositive

Step through each word to watch the RNN build its verdict. After reading the entire sequence, the final hidden state is converted to a prediction via softmax. Watch how "not" before "good" makes the RNN output Negative.