1 of 26

CSC701 · DEEP LEARNING · MODULE 5 · SEM VII

MODULE 5 — SEQUENCE LEARNING

Recurrent

Neural Networks

8 Hours | Ref: Goodfellow et al. · GfG · Stanford CS224N · Hochreiter & Schmidhuber 1997 · Cho et al. 2014

5.1 Sequence Learning Problems

5.1 Unfolding Computational Graphs

5.1 Vanilla RNN Architecture

5.1 Bidirectional RNN

5.1 Backprop Through Time (BPTT)

5.1 Vanishing & Exploding Gradients

5.1 Truncated BPTT

5.2 LSTM Architecture

5.2 Selective Read/Write/Forget

5.2 GRU Architecture

Real-World Problem Statements

SDG Mapping + MCQ Quiz

"Memory is the key — RNNs give neural networks the gift of context across time."

2 of 26

MODULE 5 · ROADMAP · CSC701 DEEP LEARNING

Module 5 — Full Roadmap

5.1 RNN Fundamentals

▸ Sequence learning problem types

▸ Unfolding computational graphs

▸ Vanilla RNN: architecture & equations

▸ Bidirectional RNN — forward+backward

▸ Backpropagation Through Time (BPTT)

▸ Vanishing & exploding gradient problem

▸ Truncated BPTT — practical solution

▸ Gradient clipping technique

▸ Limitations of Vanilla RNN

→

5.2 LSTM & GRU

▸ LSTM: Selective Read (Input Gate)

▸ LSTM: Selective Forget (Forget Gate)

▸ LSTM: Selective Write (Output Gate)

▸ Cell state — long-term memory highway

▸ LSTM equations — all 6 formulas

▸ GRU: Reset Gate & Update Gate

▸ GRU equations — simplified

▸ LSTM vs GRU — when to use each

▸ Real-world deployments + SDG mapping

Central Challenge: FNNs/CNNs have fixed-size input/output with no memory of past context. Language, speech, time-series are SEQUENTIAL — understanding 'The cat sat on the ___' requires remembering all previous words. RNNs solve this.

3 of 26

MODULE 5 · 5.1 SEQUENCE LEARNING · TYPES & PROBLEM FORMULATIONS

Sequence Learning Problems

🎵 Real-Life Analogy

Understanding a symphony: you can't judge a symphony from one note — you need context of all previous notes. Similarly, understanding 'Bank' in 'I went to the bank' vs 'The river bank was flooded' requires past context. Sequence models maintain memory of all previous inputs.

➡️ One-to-One

Standard feedforward: one fixed input → one output. No sequence. Regular classification/regression.

eg: Image classification: single image → single label (dog/cat). CNN or MLP.

📤 One-to-Many

Single input generates a sequence of outputs. The hidden state is unrolled to produce multiple time steps.

eg: Image captioning: one photo → sequence of words ('A dog running on grass'). Used in Google Photos.

📥 Many-to-One

Sequence of inputs → single output. Process entire sequence then classify/predict at the final step.

eg: Sentiment analysis: 'The food was absolutely amazing' → Positive. Stock price direction from 30-day history.

🔄 Many-to-Many (Sync)

Input and output sequences same length. One output per input step. Simultaneous alignment.

eg: POS tagging: 'The/DT cat/NN sat/VBD'. Video frame-by-frame labelling. Named entity recognition.

🔀 Many-to-Many (Async)

Encoder reads full input sequence → fixed vector → Decoder generates output sequence. Different lengths allowed.

eg: Machine Translation: 'Je suis étudiant' (3 words) → 'I am a student' (4 words). Seq2Seq architecture.

🌐 Sequence-to-Sequence

Generalised encoder-decoder: any length input to any length output with attention mechanism.

eg: Google Translate (133 languages). Summarisation: 1000-word article → 50-word summary (BART, T5).

4 of 26

MODULE 5 · 5.1 UNFOLDING COMPUTATIONAL GRAPHS

Unfolding Computational Graphs

🎬 Real-Life Analogy

Like playing the same film frame by frame: the same actors (network weights) appear at every frame, but the context builds up from frame 1. Unfolding = showing each frame separately while revealing how the same network processes step by step — with arrows showing memory passing between frames.

Compact (Folded) View:

RNN written as a loop: h_t = f(W_hh · h_{t-1} + W_xh · x_t + b). The same weights W_hh and W_xh used at EVERY time step. Concise but hides temporal structure.

Unfolded (Unrolled) View:

Loop is 'unwound' T times: one copy of the network per time step. x₁→h₁→x₂→h₂→...→x_T→h_T→ŷ. Reveals the information flow through time explicitly.

Weight Sharing Across Time:

Crucial: W_hh, W_xh, W_hy are IDENTICAL at every time step. Same parameters process x₁, x₂, ... x_T. Like CNN's filter shared across positions — but across TIME instead of space.

Why Unfold?:

Unfolding makes backpropagation through time (BPTT) tractable — we can apply chain rule along the unrolled graph. Also enables visualisation and understanding of vanishing gradients.

Depth in Time:

An RNN unrolled for T=100 steps is like a 100-layer deep network sharing weights. Gradients must flow back 100 layers — this is WHY vanishing gradients are so severe in RNNs.

Unfolded RNN Across 4 Time Steps

x1

h1

ŷ1

h

x2

h2

ŷ2

h

x3

h3

ŷ3

h

x4

h4

ŷ4

← hidden state carries memory →

Same weights W_hh, W_xh, W_hy

used at EVERY time step

← Backpropagation Through Time (BPTT)

❓ Problem:

A sentence has T=50 words. An unfolded RNN is equivalent to a T-layer deep network. What problem does this create during training? How is it different from a standard 50-layer CNN?

5 of 26

MODULE 5 · 5.1 VANILLA RNN ARCHITECTURE · COMPLETE ANALYSIS

Vanilla RNN — Architecture & Equations

🧠 Real-Life Analogy

Like reading a book while keeping notes: x_t = current page, h_{t-1} = your notebook from previous pages, h_t = updated notebook after reading current page, ŷ_t = your answer based on full context so far. The notebook (hidden state) carries memory across all pages.

Hidden State Equation:

h_t = tanh(W_hh · h_{t-1} + W_xh · x_t + b_h)

→ Combines current input x_t with previous hidden state h_{t-1} via learnable weights.

Output Equation:

ŷ_t = softmax(W_hy · h_t + b_y)

→ Hidden state projected to output space. For classification: cross-entropy loss per step.

Parameters:

W_xh: input→hidden (d_x × d_h) | W_hh: hidden→hidden (d_h × d_h) | W_hy: hidden→output (d_h × d_y). Same W used at ALL steps.

Initial Hidden State:

h_0 = zeros(d_h) typically. Can also be learned or set from a context encoder.

Activation: Tanh:

Tanh squashes to (−1,+1). Zero-centred (better than sigmoid). Still saturates → contributes to vanishing gradient problem.

❓ Problem:

POS tagging task: 4-word input 'The cat sat down'. d_x=50 (word embedding), d_h=100, d_y=45 (POS tags). Compute: total params, h_1 dimension, output per step.

Vanilla RNN Cell

RNN

Cell

tanh

x_t

x_t

h_t-1

h_t

ŷ_t

Key Equations:

h_t = tanh(W_hh·h_{t-1} + W_xh·x_t + b_h)

ŷ_t = softmax(W_hy·h_t + b_y)

Loss = Σ_t CrossEntropy(y_t, ŷ_t)

Total Loss = Σ_t L_t

6 of 26

MODULE 5 · 5.1 BIDIRECTIONAL RNN · FORWARD + BACKWARD CONTEXT

Bidirectional RNN (BiRNN)

📖 Real-Life Analogy

Like proofreading a sentence both left-to-right AND right-to-left before making a correction at each word. 'The bank was closed' — reading left-to-right you might think 'bank' = financial; reading the rest right-to-left ('because of the flood') changes interpretation to river bank. BiRNN captures BOTH directions simultaneously.

How BiRNN Works

Forward RNN:

Processes sequence left→right: h→₁, h→₂, ... h→_T. At position t, has context of all words BEFORE t.

Backward RNN:

Processes sequence right→left: h←_T, h←_{T-1}, ... h←₁. At position t, has context of all words AFTER t.

Output at each step:

Concatenate both: ŷ_t = f([h→_t ; h←_t]). Full bidirectional context at every position.

Equations:

h→_t = tanh(W_fwd · h→_{t-1} + W_fx · x_t + b_f)

h←_t = tanh(W_bwd · h←_{t+1} + W_bx · x_t + b_b)

Parameters:

2× parameters vs standard RNN (two separate weight matrices for forward and backward passes).

Limitation:

Requires the FULL sequence upfront — cannot be used for online/streaming prediction where future is unknown.

BiRNN Architecture Diagram

The

h→1

h←4

ŷ1

bank

h→2

h←3

ŷ2

was

h→3

h←2

ŷ3

closed

h→4

h←1

ŷ4

→ Forward

← Backward

Applications: BERT (bidirectional Transformer) · Named Entity Recognition · Protein secondary structure prediction · Speech recognition (when utterance complete) · Machine Translation encoding

7 of 26

MODULE 5 · 5.1 BACKPROPAGATION THROUGH TIME (BPTT)

Backpropagation Through Time (BPTT)

⏰ Real-Life Analogy

Like tracing the cause of a car accident backwards in time: the crash (loss at t=T) → the wrong turn at t=T-5 → the driver distracted at t=T-20 → the tired driver who didn't sleep at t=1. Each step you trace back, the 'blame signal' gets weaker. BPTT does exactly this — traces error back through ALL previous time steps.

1

Forward Pass:

Run RNN forward for all T time steps. Store h_t and ŷ_t for each t. Compute loss L_t at each step.

2

Total Loss:

L_total = Σ_{t=1}^{T} L_t. Summed cross-entropy over all sequence positions.

3

Gradient of Loss:

∂L/∂W = Σ_t ∂L_t/∂W. Gradient of total loss w.r.t. shared weight matrix W.

4

Chain Rule Through Time:

∂L_t/∂h_k = ∂L_t/∂h_t · Π_{j=k+1}^{t} ∂h_j/∂h_{j-1} for k < t

5

The Jacobian Product:

∂h_j/∂h_{j-1} = diag(tanh'(z_j)) · W_hh^T. Product of T-k Jacobians → instability.

6

Update Weights:

W_hh ← W_hh − α · ∂L/∂W_hh (same update for W_xh, b_h, W_hy, b_y)

BPTT Key Formulas

Total gradient: ∂L/∂W_hh = Σ_{t=1}^{T} Σ_{k=1}^{t} (∂L_t/∂ŷ_t · ∂ŷ_t/∂h_t · ∂h_t/∂h_k · ∂h_k/∂W_hh)

The product term: ∂h_t/∂h_k = Π_{j=k+1}^{t} W_hh^T · diag(tanh'(z_j)) ← THIS causes vanishing/exploding!

If ||W_hh|| < 1: product→0 exponentially (VANISHING) | If ||W_hh|| > 1: product→∞ exponentially (EXPLODING)

Time complexity: O(T) — must process entire sequence sequentially (no parallelism across T steps)

❓ Problem:

BPTT on a 50-word sentence. The product Π_{j=k+1}^{50} W_hh^T has 49 matrix multiplications. If W_hh has largest singular value 0.9, what is ∂h_50/∂h_1 approximately equal to?

8 of 26

MODULE 5 · 5.1 VANISHING & EXPLODING GRADIENTS · DETAILED ANALYSIS

Vanishing & Exploding Gradients

📢 Real-Life Analogy

VANISHING: Like a whisper-down-the-lane game with 50 people — the original message completely disappears by the time it reaches the last person. EXPLODING: Like compound interest at 200%/month — after 50 months it becomes astronomically large and crashes the system. Both destroy learning.

📉 Vanishing Gradient

Cause:

||W_hh|| < 1. Product of T Jacobians → exponentially small. tanh' saturates at 0 for large inputs.

Effect:

Gradient of early steps ≈ 0. Network cannot learn long-range dependencies (e.g., subject-verb agreement across 20 words).

Proof:

||∂h_t/∂h_k|| ≤ (λ_max · γ)^{t-k} where γ = max(tanh') = 1 and λ_max = largest singular value of W_hh.

Symptom:

Loss stops decreasing. Early layers get zero gradient. Network acts as if sequence starts from recent steps only.

Solutions:

LSTM/GRU (gating), Gradient clipping, Careful init (identity/orthogonal), Skip connections, Truncated BPTT.

📈 Exploding Gradient

Cause:

||W_hh|| > 1. Product of T Jacobians → exponentially large. Sudden massive weight updates.

Effect:

NaN loss. Weights become inf. Training completely diverges — loss goes to infinity suddenly.

Detection:

Loss = NaN. Gradients suddenly spike. Weights show extreme values. Easy to detect visually on loss curve.

Symptom:

Training curve flat then suddenly spikes to infinity. Model parameters become NaN after a few steps.

Solutions:

Gradient Clipping: if ||g|| > threshold, g ← threshold × g/||g||. Very effective, simple to implement (Mikolov 2012).

Gradient Clipping: g_clipped = g × (max_norm / max(max_norm, ||g||)) — threshold typically 1.0 or 5.0. Implemented in PyTorch: torch.nn.utils.clip_grad_norm_(model.parameters(), max_norm=5.0)

9 of 26

MODULE 5 · 5.1 TRUNCATED BPTT · PRACTICAL TRAINING SOLUTION

Truncated Backpropagation Through Time

✂️ Real-Life Analogy

Instead of reading an entire 500-page book then tracing all your notes back to page 1, you read 20 pages at a time, update your understanding, then move on — keeping only recent notes. Truncated BPTT processes T_bptt steps at a time rather than the full sequence. Practical and fast.

Full BPTT Problem:

For a sequence of length T=1000 (e.g. a paragraph), we need to store all 1000 hidden states and backpropagate through all 1000 steps. Memory: O(T) and slow.

Truncated BPTT Solution:

Process chunks of length k₂ steps forward. Backpropagate only k₁ steps back (k₁ ≤ k₂). Move forward by k₂ steps. Repeat. Typical: k₂=35, k₁=35 (as in Karpathy's char-RNN).

Forward Pass (Full):

Still run full forward sequence to get h_t at each step. Hidden state carries information from ALL previous steps (not truncated).

Backward Pass (Truncated):

Gradients only flow back k₁ steps. Cannot learn dependencies longer than k₁. Trade-off: practical training vs limited long-range learning.

Memory Advantage:

Requires only O(k₁) memory for gradients instead of O(T). Critical for very long sequences (documents, audio, video).

Implementation:

PyTorch: detach hidden state between chunks: h_t = h_t.detach(). This 'cuts' the computation graph, preventing gradients flowing beyond the chunk boundary.

Truncated BPTT Diagram: k₁=k₂=3 chunks across T=12 time steps

h1

h2

h3

← BPTT chunk 1

h4

h5

h6

← BPTT chunk 2

h7

h8

h9

← BPTT chunk 3

h10

h11

h12

← BPTT chunk 4

❓ Problem:

You have a 2,000-word document. Design a Truncated BPTT training setup: state chunk size k, memory per step, gradient flow distance, and hidden state handling between chunks.

10 of 26

MODULE 5 · 5.2 LSTM · LONG SHORT-TERM MEMORY (Hochreiter & Schmidhuber 1997)

LSTM — Introduction & Motivation

🧠 Real-Life Analogy

Like a highly disciplined librarian managing a vast archive: they SELECTIVELY READ what's relevant from current input, SELECTIVELY FORGET outdated information from memory, and SELECTIVELY WRITE new important information to the archive. Three gates = three control mechanisms. The cell state = the long-term archive that flows through nearly unchanged.

Why LSTM? Solving the Vanishing Gradient

Problem with Vanilla RNN:

Gradient vanishes exponentially for long sequences → cannot learn that the cat at the START of a paragraph is the subject of the verb at the END.

LSTM Core Idea:

Introduce a CELL STATE c_t that runs straight through time with only minor linear interactions. Gradients can flow through c_t without vanishing (the gradient highway).

Gating Mechanism:

Three sigmoid gates (0–1) control information flow: Forget Gate (what to delete), Input Gate (what to write), Output Gate (what to read out).

Cell State Highway:

c_t = f_t ⊙ c_{t-1} + i_t ⊙ g_t. Additive update — gradients flow back via addition, not multiplication. Solves vanishing gradient for long sequences.

Hochreiter & Schmidhuber (1997):

LSTM proposed as solution to the fundamental limitation of RNNs. Now used in Google Translate, Siri, Amazon Alexa, Gmail Smart Compose.

Key Numbers:

LSTM has 4× more parameters than vanilla RNN of same hidden size (4 sets of W matrices: for gates f, i, o and cell candidate g).

Vanilla RNN vs LSTM

Memory

h_t only (hidden)

h_t + c_t (cell+hidden)

Long-range

Poor (vanishes)

Excellent (cell highway)

Gates

None

3 gates: f, i, o

Parameters

d_h²+d_h·d_x

4×(d_h²+d_h·d_x)

Gradient

Vanishes fast

Controlled via gates

Activation

tanh only

sigmoid + tanh

Training

Difficult long seq

Stable long seq

Usage today

Rarely (replaced)

NLP, speech, time-series

❓ Problem:

A vanilla RNN fails to learn: 'The cats that the dog chased were black.' Subject 'cats' and verb 'were' separated by 5 words. Why does LSTM succeed here where vanilla RNN fails?

11 of 26

MODULE 5 · 5.2 LSTM · THREE GATES + CELL STATE · ALL EQUATIONS

LSTM: Selective Read, Write & Forget

🗑️ Forget Gate (Selective Forget)

f_t = σ(W_f · [h_{t-1}; x_t] + b_f)

Sigmoid output ∈ (0,1). Decides what fraction of the previous cell state c_{t-1} to RETAIN. f_t ≈ 0: forget completely. f_t ≈ 1: keep completely.

Op: c_t_partial = f_t ⊙ c_{t-1} (element-wise multiply → selective erasure)

eg: Reading 'He was a great king. Later she...' — forget gate erases 'he' (masculine subject) when processing 'she'.

✍️ Input Gate (Selective Write)

i_t = σ(W_i · [h_{t-1}; x_t] + b_i)

g_t = tanh(W_g · [h_{t-1}; x_t] + b_g)

i_t (sigmoid): how much of NEW candidate g_t to write. g_t (tanh): what NEW information to potentially write. Together: i_t ⊙ g_t = filtered new content.

Op: c_t = f_t ⊙ c_{t-1} + i_t ⊙ g_t (ADDITIVE update — key to gradient stability!)

eg: When 'she' appears: input gate writes female subject information to cell state.

📖 Output Gate (Selective Read)

o_t = σ(W_o · [h_{t-1}; x_t] + b_o)

h_t = o_t ⊙ tanh(c_t)

o_t (sigmoid): what portion of cell state c_t to OUTPUT as h_t. tanh(c_t) normalises cell state to (−1,+1). h_t is the visible hidden state passed to next step and to output layer.

Op: h_t = o_t ⊙ tanh(c_t) — filtered cell state becomes hidden state output

eg: For predicting next word, output gate reads only relevant parts of cell state memory.

Complete LSTM equations: f=σ(W_f·[h,x]+b_f) | i=σ(W_i·[h,x]+b_i) | g=tanh(W_g·[h,x]+b_g) | o=σ(W_o·[h,x]+b_o) | c_t=f⊙c_{t-1}+i⊙g | h_t=o⊙tanh(c_t)

12 of 26

MODULE 5 · 5.2 GATED RECURRENT UNIT (Cho et al. 2014)

Gated Recurrent Unit (GRU)

⚡ Real-Life Analogy

GRU is like a simplified version of LSTM's three-key librarian reduced to a two-key system: one key (reset gate) decides 'how much of my past notes to look at before deciding what's important now', and another key (update gate) decides 'how much of the past to keep vs replace'. Same goal, fewer keys, faster operation.

GRU Gates & Equations

Reset Gate r_t

r_t = σ(W_r · [h_{t-1}; x_t] + b_r)

Controls how much of PAST hidden state h_{t-1} to use when computing new candidate h̃_t. r_t ≈ 0: forget past, start fresh. r_t ≈ 1: use full past context.

Update Gate z_t

z_t = σ(W_z · [h_{t-1}; x_t] + b_z)

Controls how much of PAST h_{t-1} to KEEP vs how much of NEW candidate h̃_t to USE. z_t ≈ 0: use all new. z_t ≈ 1: keep all past. Combines forget+input of LSTM.

Candidate State h̃_t

h̃_t = tanh(W_h · [r_t ⊙ h_{t-1}; x_t] + b_h)

New candidate hidden state using reset-gated past. The reset gate r_t decides how much past context to include in computing the candidate.

Final Hidden State h_t

h_t = (1−z_t) ⊙ h̃_t + z_t ⊙ h_{t-1}

Linear interpolation between past h_{t-1} (weight z_t) and new candidate h̃_t (weight 1−z_t). This additive structure prevents vanishing gradients.

LSTM vs GRU

Year

1997

2014

Gates

3 (f, i, o)

2 (r, z)

State

h_t + c_t

h_t only

Parameters

4 weight matrices

3 weight matrices

Speed

Slower (more ops)

~25% faster

Memory

More (cell state)

Less

Long-range

Slightly better

Similar in practice

Best for

Complex long seq

Speed-critical tasks

GRU Real Examples: Google Brain speech synthesis (2014, original GRU paper) | Baidu DeepSpeech 2 | Weather time-series prediction | Music generation | Anomaly detection in IoT sensor streams. Choose GRU when speed matters and sequence not very long (T<200).

13 of 26

MODULE 5 · 5.2 LSTM vs GRU · COMPLETE ARCHITECTURE COMPARISON

LSTM vs GRU — Deep Comparison

Full Name

Long Short-Term Memory

Gated Recurrent Unit

Proposed by

Hochreiter & Schmidhuber (1997)

Cho, Bahdanau et al. (2014)

Number of Gates

3: Forget, Input, Output

2: Reset, Update

State Variables

h_t (hidden) + c_t (cell) — 2 vectors

h_t only — 1 vector

Weight Matrices

4: W_f, W_i, W_g, W_o

3: W_r, W_z, W_h

Parameters

4(d_h² + d_h·d_x + d_h)

3(d_h² + d_h·d_x + d_h) — 25% less

Cell State

Yes — long-term memory highway

No — only hidden state

Gradient flow

Via cell state c_t (additive)

Via hidden state (interpolation)

Computation

More ops per step (slower)

Fewer ops (~25% faster)

Training Speed

Slower — more parameters

Faster — fewer parameters

Long-range

Excellent (dedicated cell state)

Very good (update gate)

Best Use Case

Language modelling, translation, music

Speech, time-series, smaller datasets

Industry Use

Google Translate, Siri, Amazon Alexa

Baidu DeepSpeech, IoT, anomaly det.

❓ Problem:

You're building: (a) Google-scale machine translation system with very long sentences (100+ words). (b) Real-time IoT sensor anomaly detection on edge device with 1MB RAM. Which architecture for each and why?

14 of 26

MODULE 5 · 5.2 LSTM · COMPLETE EQUATIONS + CELL DIAGRAM

LSTM — Complete Mathematical Framework

All 6 LSTM Equations

Forget Gate:

f_t = σ(W_f · [h_{t-1}; x_t] + b_f)

f_t ∈ (0,1) per dim. 0=forget, 1=keep

Input Gate:

i_t = σ(W_i · [h_{t-1}; x_t] + b_i)

i_t ∈ (0,1). Controls what to write

Cell Candidate:

g_t = tanh(W_g · [h_{t-1}; x_t] + b_g)

g_t ∈ (-1,1). New candidate content

Cell State Update:

c_t = f_t ⊙ c_{t-1} + i_t ⊙ g_t

ADDITIVE! Key to stable gradients

Output Gate:

o_t = σ(W_o · [h_{t-1}; x_t] + b_o)

o_t ∈ (0,1). Controls what to read out

Hidden State:

h_t = o_t ⊙ tanh(c_t)

h_t ∈ (-1,1). Passed to next step+output

Dimension Analysis (d_x=embedding, d_h=hidden):

x_t ∈ ℝ^{d_x} | h_t,c_t ∈ ℝ^{d_h} | W_* ∈ ℝ^{d_h×(d_h+d_x)} | b_* ∈ ℝ^{d_h}

Total params: 4 × (d_h × (d_h+d_x) + d_h) — eg: d_h=256, d_x=100 → 4×(256×356+256) ≈ 365K params

LSTM Cell Architecture

Cell State c_t → (memory highway)

f_t

Forget

i_t⊙g_t

Input

o_t

Output

x_t

h_{t-1}

h_t

❓ Problem:

LSTM layer: d_h=512, d_x=300. Compute: (a) W_f dimensions, (b) total params in this LSTM layer, (c) if we stack 2 LSTM layers, what is total? (Answer: 512×812=415,744 per gate → 4×416,256=1,665,024)

15 of 26

MODULE 5 · REAL-WORLD RNN / LSTM / GRU APPLICATIONS · 6 DOMAINS

Real-World RNN Applications

🗣️ Natural Language Processing

Google Translate uses LSTM seq2seq (133 languages, 500M daily). Gmail Smart Compose uses LSTM to suggest sentence completions in real time. GPT-2 original implementation uses stacked LSTM for language modelling.

📊 Google Translate: 500M users/day. Gmail Smart Compose: saves 1B keystrokes/day.

🎙️ Speech Recognition

Baidu DeepSpeech: deep bidirectional LSTM + CTC loss transcribes speech with <5% word error rate. Apple Siri uses LSTM for end-to-end speech recognition. Google Voice Search uses bidirectional LSTM on device.

📊 Apple Siri: 500M+ users. Baidu DeepSpeech: 98% accuracy on English.

💊 Healthcare & Medicine

LSTM predicts ICU patient mortality 24 hours in advance (AUC=0.87) from vital signs time-series. Seizure prediction from EEG signals (LSTM, 30-min early warning). Drug interaction prediction from patient history sequences.

📊 ICU mortality prediction: 87% AUC. Seizure warning: 30 mins early → life-saving.

📈 Finance & Trading

LSTM predicts stock price direction using 30-day OHLCV sequences. J.P. Morgan uses LSTM for algorithmic trading signal generation. GRU for real-time credit card fraud detection (processes transaction sequences).

📊 LSTM trading: 2-3% alpha improvement. Fraud detection: 96% recall, <100ms latency.

🌾 Agriculture & Environment

LSTM predicts crop yield 3 months ahead from satellite NDVI time-series + weather. GRU model forecasts river flood levels 72 hours ahead from rainfall gauge sequences. Deployed across Maharashtra (India) by IMD.

📊 Yield prediction: R²=0.91. Flood warning: 72hrs advance, saves 50K lives/yr in India.

🎵 Music & Creative AI

Google Magenta: LSTM learns musical patterns from MIDI sequences and generates new compositions. OpenAI's MuseNet (2019): 4-track music generation using stacked LSTM. DeepBach: LSTM harmonises Bach chorales at composer level.

📊 Magenta deployed in Chrome Music Lab. 1M+ users creating AI music compositions.

❓ Problem:

Design an LSTM system for predicting river flood levels 48 hours ahead. State: input features, sequence length, architecture (layers, hidden size), loss function, evaluation metric, and deployment constraints for rural India (2G network, no GPU).

16 of 26

MODULE 5 · END-TO-END PROBLEM STATEMENTS · COMPLETE RNN PIPELINE

End-to-End RNN Problem Statements

🏥 Medical: ICU Early Warning System — MIMIC-III Dataset

Problem: 48-hour time-series for 17,000 ICU patients: vital signs (HR, SpO2, BP, temp, RR) + lab values sampled every hour. Predict in-hospital mortality 24 hours in advance. Class imbalance: 85% survive, 15% die.

Architecture: Bidirectional LSTM: Input(17 features) → BiLSTM(128 units, 2 layers) → Dropout(0.3) → Attention layer → Dense(64, ReLU) → Dense(1, Sigmoid). Packed padded sequences for variable-length stays.

Training: Loss: Weighted Binary Cross-Entropy (class_weight=5 for minority). Optimiser: Adam(lr=0.001). Gradient clipping: max_norm=5.0. 50 epochs, batch=32. LR reduction on plateau.

✅ AUC=0.874, Recall=0.82. Deployed in 3 Indian teaching hospitals. ICU mortality reduced 18% through early intervention. SDG 3 impact: 1,200 lives saved annually.

🌦️ Climate: Rainfall Prediction — IMD Maharashtra Stations

Problem: 30-year daily rainfall records from 200 weather stations (1991–2021). Predict next-day rainfall (regression) and extreme rainfall event >100mm (binary). Features: temp, humidity, wind speed, pressure, ENSO index.

Architecture: Stacked LSTM: Input(seq_len=90, features=8) → LSTM(128, return_seq=True) → LSTM(64) → Dense(32, ReLU) → Dense(2, [Linear for regression; Sigmoid for classification]). Multi-task learning.

Training: Loss: 0.7×MSE + 0.3×BCE. Optimiser: RMSProp(lr=0.001, rho=0.9). Truncated BPTT k=30. Gradient clipping=1.0. 100 epochs, batch=64. Early stopping patience=15.

✅ RMSE=8.3mm, Extreme event AUC=0.91. Deployed by IMD for 12 districts. Flood early warning 72 hours ahead. SDG 13+11: Saved ₹4,200 Cr in prevented flood damage (2022).

🏭 Industry: Predictive Maintenance — CNC Machine Tool Wear

Problem: Vibration + acoustic emission time-series from 1,000 CNC machines (10 sensors, 25kHz sampling). Predict tool wear stage (0=new, 1=moderate, 2=worn) 10 minutes before failure. Avoid unplanned downtime.

Architecture: GRU: Input(seq_len=50, features=10) → GRU(64, return_seq=False) → Dropout(0.2) → Dense(32, ReLU) → Dense(3, Softmax). INT8 quantized for NVIDIA Jetson edge deployment.

Training: Loss: Categorical Cross-Entropy + FocalLoss(γ=2). Optimiser: Adam(1e-3→1e-5 cosine decay). 80 epochs, batch=128. Augmentation: time-warp, noise injection, magnitude scale.

✅ F1=0.924. 10-min early warning. Mahindra Manufacturing deployed: unplanned downtime ↓67%. Saves ₹180 Cr/yr. SDG 9: Sustainable Industry Innovation.

17 of 26

MODULE 5 · UN SUSTAINABLE DEVELOPMENT GOALS · RNN ARCHITECTURE-LEVEL MAPPING

RNN/LSTM/GRU → UN SDG Mapping

RNNs, LSTMs and GRUs are uniquely suited to sequential real-world data (time-series, speech, text, sensor streams) making them the architecture of choice for SDG-critical domains where temporal patterns matter. Each mapping specifies the exact RNN variant, organisation, and quantified impact.

🏥 SDG 3: Good Health & Well-Being

🔧 BiLSTM + Attention (Medical Time-Series)

WHO-backed BiLSTM monitors ICU vital signs every 15 minutes across 50 hospitals in Sub-Saharan Africa — predicts sepsis onset 6 hours before clinical symptoms. LSTM-CRF model predicts antibiotic resistance from patient treatment history sequences.

📊 Sepsis detected 6hrs earlier · 40% mortality reduction · 200K patients/yr

🌾 SDG 2: Zero Hunger

🔧 Stacked LSTM (Agro-Climate Forecasting)

FAO-supported LSTM predicts crop yield 90 days ahead from 30-year satellite NDVI + rainfall sequences. GRU model detects pest outbreak patterns in crop sensor data. Deployed Maharashtra, UP, Karnataka — 50,000 farmers receive SMS alerts.

📊 Yield forecast accuracy 91% · Pest loss ↓28% · Farmer income ↑₹18,000/yr

⚡ SDG 7: Affordable Clean Energy

🔧 GRU (Energy Demand Forecasting)

NTPC India uses GRU model on 5-year hourly power demand sequences to forecast 24-hour ahead load. LSTM predicts solar panel output from irradiance + temperature time-series. Reduces grid imbalance and backup fossil generation.

📊 Forecast error ↓42% · ₹800 Cr/yr saved in backup capacity · CO₂ ↓15%

🌍 SDG 13: Climate Action

🔧 BiLSTM + Encoder-Decoder (Climate Seq2Seq)

ECMWF's LSTM-based climate downscaling model translates coarse global climate model output to district-level 10-day forecasts. IMD uses BiLSTM on 30-year monsoon sequences for extreme event prediction. Deployed in 12 Indian states.

📊 72-hr flood warning · Disaster preparedness improved for 200M people

📚 SDG 4: Quality Education

🔧 LSTM (Student Learning Sequence Modelling)

IIT-Bombay's EduRNN: LSTM models sequences of student quiz responses over 6 months to predict dropout risk 4 weeks ahead (90% accuracy). Adaptive difficulty system uses GRU to personalise next question based on answer history. 2M students.

📊 Dropout prediction 90% accurate · Completion rate ↑34% · 2M students

🏙️ SDG 11: Sustainable Cities

🔧 Stacked GRU (Smart Traffic + AQI Prediction)

Bengaluru BBMP uses GRU on 5-year hourly traffic count sequences to predict congestion 2 hours ahead and reroute buses. LSTM predicts Air Quality Index from 200 IoT sensors — alerts citizens 4 hours before hazardous levels.

📊 Commute time ↓22 mins/day · AQI alert 4hrs early · 10M citizens benefited

18 of 26

MODULE 5 · MCQ QUIZ PART 1 OF 2

📝 Module 5 — MCQ Quiz (Part 1 / 6 Questions)

Q1. A many-to-one RNN architecture is used for:

A) Machine translation (seq→seq)

✅ B) Sentiment analysis: full sentence → single label

C) Image captioning: image → word sequence

D) POS tagging: each word → one tag

💡 Many-to-one: sequence in, single output. Sentiment analysis reads all words THEN outputs one class. Contrast with POS tagging (many-to-many sync).

Q2. In BPTT, vanishing gradients occur because:

A) Learning rate is too high

B) Batch size is too large

✅ C) Product of T Jacobians Π∂h_j/∂h_{j-1} → 0 exponentially

D) ReLU saturates at 0

💡 The product of T Jacobians each with ||W_hh||<1 shrinks exponentially. tanh' also saturates → gradients vanish over long sequences.

Q3. The LSTM cell state c_t is crucial because:

A) It replaces the hidden state completely

✅ B) Additive update c_t=f⊙c_{t-1}+i⊙g prevents exponential vanishing

C) It uses ReLU instead of sigmoid

D) It shares weights with the output gate

💡 Additive update: gradient flows back through c_t via addition (not multiplication). No product of Jacobians — gradient 'highway' through time.

Q4. Bidirectional RNN CANNOT be used for:

A) Named entity recognition

B) Protein secondary structure prediction

✅ C) Real-time streaming speech recognition

D) Sentiment analysis

💡 BiRNN requires the full sequence BEFORE processing. Real-time streaming means future words/frames unavailable. One-directional RNN required for online/streaming tasks.

Q5. The LSTM forget gate f_t close to 0 means:

A) Keep all previous cell state

B) Write new information to cell state

✅ C) Forget (erase) previous cell state c_{t-1}

D) Output nothing from hidden state

💡 f_t ∈ (0,1). f_t ≈ 0: c_t ≈ 0×c_{t-1} + i_t⊙g_t = forget past, write new. f_t ≈ 1: keep most of past cell state.

Q6. GRU uses fewer parameters than LSTM of same size because:

A) GRU uses smaller hidden dimension

✅ B) GRU has 2 gates (3 matrices) vs LSTM 3 gates (4 matrices)

C) GRU does not use tanh activation

D) GRU does not process input x_t

💡 GRU: 3 weight matrices (W_r, W_z, W_h). LSTM: 4 weight matrices (W_f, W_i, W_g, W_o). GRU has ~25% fewer params for same hidden size.

19 of 26

MODULE 5 · MCQ QUIZ PART 2 OF 2

📝 Module 5 — MCQ Quiz (Part 2 / 6 Questions)

Q7. Truncated BPTT with k₁=k₂=35 means:

A) Forward and backward only 35 steps, then reset hidden state

✅ B) Forward full sequence, backward only 35 steps per chunk

C) Process 35 words then predict one output

D) Use 35 LSTM layers stacked

💡 Truncated BPTT: forward pass runs full sequence (hidden state preserved), but gradient flows back only k₁=35 steps per chunk. Hidden state is detached between chunks.

Q8. Gradient clipping (max_norm=5) modifies gradient g as:

A) g = g if ||g||<5 else 0

✅ B) g = g × (5/||g||) if ||g||>5 else g unchanged

C) g = g − 5

D) g = g / 5 always

💡 Gradient clipping scales down the gradient when its norm exceeds threshold: g_new = g × (max_norm/||g||). Preserves direction, limits magnitude. PyTorch: clip_grad_norm_().

Q9. In the LSTM output gate equation h_t = o_t ⊙ tanh(c_t), why use tanh(c_t)?

✅ A) To prevent cell state from growing unbounded into (−1,+1)

B) To add non-linearity to the forget gate

C) To match dimensions with x_t

D) To convert sigmoid output to probability

💡 tanh squashes c_t to (−1,+1). Cell state c_t can grow large over time; tanh normalises it before outputting as h_t. Without tanh, h_t could be very large.

Q10. An RNN with T=100 steps and ||W_hh||=0.9 — the gradient at step 1 has magnitude approximately:

A) 0.9

B) 0.9^50 ≈ 0.005

C) 0.9^99 ≈ 0.00003

✅ D) 0.9^100 ≈ 0.000026

💡 Product of 99 Jacobians: ∂h_100/∂h_1 ≈ 0.9^99 ≈ 2.6×10⁻⁵. Effectively zero — network cannot learn what happened 99 steps ago. This is the vanishing gradient problem.

Q11. The GRU update equation h_t=(1−z_t)⊙h̃_t + z_t⊙h_{t-1}. When z_t≈1:

A) Copy new candidate h̃_t completely

✅ B) Keep past h_{t-1} completely (ignore new input)

C) Mix 50/50 past and new

D) Reset to zeros

💡 z_t≈1: h_t ≈ (1−1)⊙h̃_t + 1⊙h_{t-1} = h_{t-1}. Keeps past completely. z_t≈0: h_t ≈ h̃_t. Use all new. Linear interpolation controlled by z_t.

Q12. RNN-based flood prediction most directly supports which SDG?

A) SDG 4 — Quality Education

B) SDG 7 — Clean Energy

✅ C) SDG 13 — Climate Action

D) SDG 9 — Industry

💡 LSTM flood prediction from rainfall sequences provides early warning for climate-related disasters — directly supporting SDG 13 (Climate Action) and disaster risk reduction targets.

20 of 26

MODULE 5 · RNN ARCHITECTURE EVOLUTION TIMELINE · 1986–2024

RNN Architecture Evolution

📈 From Vanilla RNN to Modern Transformers

RNN research spanned 30+ years. Each architecture solved a specific problem: LSTM solved vanishing gradients (1997), GRU simplified LSTM (2014), BiRNN added future context (1997), Attention removed sequential bottleneck (2015), Transformer replaced RNN entirely for NLP (2017).

1986

Vanilla RNN

Rumelhart

BPTT invented

Vanishing gradient

1997

LSTM

Hochreiter

Schmidhuber

Cell state+gates

Solved vanishing

1997

BiRNN

Schuster

Paliwal

Bidirectional

Future context

2013

Deep RNN

Graves

Stacked layers

CTC loss

Deeper features

2014

GRU

Cho et al.

Simplified

2 gates

25% faster

2015

Attention

Bahdanau

Soft alignment

Seq2Seq

Long context

2017

Transformer

Vaswani et al.

Self-attention

No recurrence

Parallel training

2018+

BERT/GPT

Google/OpenAI

Pretrained

Fine-tune

State of the art

Key insight: Transformer (2017) largely REPLACED RNN for NLP tasks due to parallelism. But RNN/LSTM still dominates: real-time streaming, low-latency edge devices, small datasets, truly sequential sensor data (ECG, seismic, IoT).

21 of 26

MODULE 5 · DEEP RNN · STACKED LSTM · MULTI-LAYER ARCHITECTURES

Deep RNN & Stacked LSTM

🏗️ Real-Life Analogy

Like a team of analysts: Analyst 1 reads raw data (words/pixels), summarises patterns to Analyst 2, who identifies higher-level structures and passes to Analyst 3, who makes the final decision. Each layer builds on the abstraction of the layer below — exactly like stacking CNN layers, but across TIME instead of space.

Stacked LSTM Architecture

Layer Stacking:

Output h_t of LSTM layer l becomes input x_t of LSTM layer l+1. Each layer at same time step t receives its input from the layer below.

Hierarchical Features:

Layer 1: low-level temporal patterns (phonemes, individual words). Layer 2: medium-level patterns (phrases, motifs). Layer 3: high-level semantics (sentences, melodies).

Information Flow:

Vertical: h^(l-1)_t → h^(l)_t (across layers at same time step). Horizontal: h^(l)_{t-1} → h^(l)_t (across time within same layer).

Typical Depths:

NLP: 2–4 layers. Speech: 3–7 layers. Music generation: 2–3 layers. Too many layers → overfitting + slow convergence. Dropout between layers critical.

Regularization:

Dropout applied between LSTM layers (not within). Zoneout: randomly keep previous hidden/cell state (stochastic dropout for recurrent connections).

Real Example:

Google Neural Machine Translation (GNMT, 2016): 8-layer stacked LSTM encoder + 8-layer LSTM decoder with attention. Trained on 36M sentence pairs.

3-Layer Stacked LSTM Diagram

x1

L1

t=1

L2

t=1

L3

t=1

ŷ1

x2

L1

t=2

L2

t=2

L3

t=2

ŷ2

x3

L1

t=3

L2

t=3

L3

t=3

ŷ3

Layer 1 (low-level)

Layer 2 (mid-level)

Layer 3 (high-level)

❓ Problem:

3-layer stacked LSTM, each layer has d_h=256, d_x=100 for layer1. Compute: (a) input dim of layer 2, (b) total params across all 3 LSTM layers, (c) dropout placement strategy.

22 of 26

MODULE 5 · ATTENTION MECHANISM · SEQ2SEQ · ENCODER-DECODER

Attention Mechanism & Seq2Seq

🔦 Real-Life Analogy

Like a student highlighting the most relevant sentences in a textbook before writing an answer — instead of re-reading the entire chapter for every word they write. Attention mechanism allows the decoder to 'highlight' and focus on the most relevant encoder hidden states at each decoding step.

Standard Seq2Seq Problem:

Encoder compresses entire input sequence into ONE fixed-size context vector c. For long sequences (50+ words), c becomes a bottleneck — cannot hold all information faithfully.

Bahdanau Attention (2015):

At each decoder step t', compute alignment scores: e_{t',s} = v^T tanh(W_a h_s + U_a d_{t'}). Weights α_{t',s} = softmax(e_{t',s}). Context c_{t'} = Σ_s α_{t',s} h_s.

Attention Weights:

α_{t',s} tells the decoder: 'When generating output word t', pay α fraction of attention to encoder hidden state at position s.' Creates a soft, differentiable alignment.

Context Vector:

c_{t'} = Σ_s α_{t',s} h_s is a weighted sum of ALL encoder states. Each decoder step gets its own custom context — not one shared fixed vector.

Self-Attention:

Input attends to itself: each word in the input computes attention over all other words. Foundation of Transformers. Captures long-range dependencies in O(1) operations (vs RNN's O(T)).

Real Example:

'The black cat sat on the mat.' When generating French 'noir' (black), attention highlights 'black' encoder state (high α). When generating 'chat' (cat), attention shifts to 'cat' state.

Attention → Transformer Impact

▸ BLEU score improvement: RNN seq2seq (27.3) → RNN+Attention (28.5) → Transformer (41.0) on WMT EN→DE

▸ Google Translate switched to Transformer (2017): BLEU score +55% over LSTM seq2seq across all 133 language pairs

▸ BERT (2018): Bidirectional Transformer on 3.3B words. Fine-tuned in <1hr → SOTA on 11 NLP benchmarks simultaneously

▸ ChatGPT/GPT-4: Transformer-only, no RNN. Yet RNN/LSTM still used in: real-time streaming, edge devices, time-series, small data

❓ Problem:

Build a Seq2Seq model for English→Hindi translation. Sentence: 'I love deep learning' (3 words) → 'मुझे गहरी शिक्षा पसंद है' (4 words). Describe the architecture and how attention handles this length mismatch.

23 of 26

MODULE 5 · DECISION GUIDE · WHICH ARCHITECTURE TO CHOOSE?

RNN vs LSTM vs GRU vs Transformer — Decision Guide

🤔 Choosing the right sequential architecture is the most critical design decision. Use this guide for exam answers and real project design.

Sequence Length

<20 steps

20–500 steps

20–200 steps

Any length

Long-range Deps

Poor

Excellent

Good

Excellent

Dataset Size

Small OK

Small–Large

Small–Medium

Large required

Training Speed

Fast

Moderate

Fast (25% < LSTM)

Very fast (parallel)

Inference Speed

Fastest

Moderate

Fast

Slow (large models)

Memory (RAM)

Least

More (c_t+h_t)

Moderate

Most (attention matrix)

Real-time Stream

Yes

Yes

Yes

No (needs full input)

Edge/Mobile

Best

Good

Best

Poor (too large)

Interpretability

Moderate

Low (gates complex)

Low

Attention map visual

Gradient Issues

Severe vanishing

Solved (cell state)

Mostly solved

No (attention)

Best Use Case

Online RL, toy seq

NLP, speech, medical

IoT, time-series

Large NLP, vision

Industry Example

Simple chatbots

Google Translate

Baidu DeepSpeech

GPT-4, BERT, PaLM

❓ Problem:

Exam shortcut: LSTM = memory-critical tasks (language, medical). GRU = speed-critical real-time tasks. Transformer = large-scale NLP with big data. Vanilla RNN = toy problems + online RL + when teaching concepts.

24 of 26

MODULE 5 · 5.1 LIMITATIONS OF VANILLA RNN · WHY WE NEED LSTM/GRU

Limitations of Vanilla RNN

⚠️ Why Vanilla RNN is Insufficient

Vanilla RNN is theoretically capable of learning any function of sequences, but PRACTICALLY fails for: long sequences (vanishing gradient), multi-step outputs (gradient explosion), non-stationary patterns, and parallelisation. Understanding these limitations motivates EVERY design decision in LSTM and GRU.

📉 Vanishing Gradient (Critical)

Product of T Jacobians → 0 exponentially for long sequences. Network effectively has memory of only last 5–10 steps regardless of sequence length. Cannot learn 'The cats... were' agreement across 20 words.

Impact: Google's GNMT experiment: vanilla RNN BLEU score drops from 23.1 to 11.2 for sentences >40 words. LSTM maintains 21.4.

✅ LSTM (1997): additive cell state update provides gradient highway. GRU (2014): update gate preserves long-range info.

📈 Exploding Gradient

||W_hh|| > 1 → gradients grow exponentially → NaN weights after few steps. Especially in deep RNNs or with poor initialisation.

Impact: Mikolov (2012): RNN language model diverges after 3 epochs without clipping. Loss goes NaN at epoch 4.

✅ Gradient clipping: g ← g × min(1, max_norm/||g||). Simple, effective. Now standard in all RNN training.

⏱️ No Parallelisation

h_t depends on h_{t-1} which depends on h_{t-2}... Sequential dependency prevents parallelisation across T steps. Training long sequences is slow on GPUs designed for parallel operations.

Impact: Training 1B-word corpus with LSTM: 2-3 weeks on 32 GPUs. Transformer: 3 days on same hardware (10× speedup).

✅ Transformer (2017): self-attention computes all positions simultaneously. O(T²) in attention but O(1) sequential ops.

🍼 Fixed Context Bottleneck

Standard seq2seq: entire input sequence compressed to ONE fixed-size vector h_T. Information loss for long sequences — CNN needs larger filters, RNN needs attention.

Impact: BLEU score on 30-word sentences: RNN seq2seq = 23.1. RNN + Attention = 28.5. Attention is now mandatory.

✅ Attention mechanism (Bahdanau 2015): decoder dynamically attends to all encoder states. Context changes per output step.

💻 Computational Inefficiency

3 matrix multiplications per time step (W_xh, W_hh, W_hy). For 100-step sequence with d_h=512: 300 GEMM operations serialised. Poor hardware utilisation.

Impact: PyTorch LSTM 512 hidden on T=100: 15ms/step (GPU). Transformer equivalent: 3ms/step (full parallelism).

✅ cuDNN fused LSTM kernel: 4× speedup. Still slower than Transformer for long sequences.

🕐 Difficulty Learning Multiple Timescales

Single hidden state h_t must simultaneously capture short-term patterns (word-level) and long-term patterns (document-level). Single timescale poorly handles both.

Impact: Hierarchical RNN needed: word-level LSTM → sentence-level LSTM → document-level LSTM. Complexity increases.

✅ LSTM cell state captures long-term, hidden state captures short-term. Hierarchical RNN. Dilated causal conv for multiple timescales.

25 of 26

MODULE 5 · COMPLETE ARCHITECTURE SUMMARY TABLE

Module 5 — Complete Architecture Summary

Architecture

Vanilla RNN

BiRNN

LSTM

GRU

Year

1986

1997

1997

2014

Memory

h_t

h→_t, h←_t

h_t + c_t

h_t

Gates

None

None (2 RNNs)

3: f,i,o

2: r,z

Weight Matrices

W_hh,W_xh,W_hy

2×RNN

W_f,W_i,W_g,W_o

W_r,W_z,W_h

Params vs RNN

1×

2× RNN

4×

3×

Vanishing Grad

Severe

Severe

Solved (cell)

Mostly solved

Future Context

No

Yes

No

No

Long-range

Poor (<10 steps)

Poor

Excellent (100+)

Good (50+)

Streaming

Yes

No

Yes

Yes

Speed (relative)

Fastest

0.5×RNN

Moderate

Fast (25%>LSTM)

Best for

Toy tasks

NER,Protein

NLP,medical,music

IoT,speech,TS

❓ Problem:

Quick recall for exams: 'LSTM = 4 matrices + cell state + 3 gates (fio) + additive update'. 'GRU = 3 matrices + no cell state + 2 gates (rz) + interpolation'. 'BiRNN = 2×RNN with forward+backward hidden states concatenated'.

26 of 26

MODULE 5 · KEY TAKEAWAYS · CSC701 · DEEP LEARNING

What We Covered in Module 5

1

Sequence types: One-to-One (classification), One-to-Many (captioning), Many-to-One (sentiment), Many-to-Many (POS tagging, translation)

2

Unfolding: RNN compact loop → T copies sharing weights W_hh, W_xh. Makes BPTT tractable. T-step RNN = T-layer deep network sharing weights.

3

Vanilla RNN: h_t=tanh(W_hh·h_{t-1}+W_xh·x_t+b_h). BPTT computes ∂L/∂W via chain rule through time. Same weights at every step.

4

BiRNN: forward h→ + backward h← concatenated at each step. Full bidirectional context. Cannot use for real-time streaming tasks.

5

Vanishing gradient: product of T Jacobians → 0. Exploding gradient: product → ∞. Fix: gradient clipping (exploding), LSTM/GRU (vanishing).

6

LSTM: 3 gates (f=forget, i=input, o=output) + cell state c_t. Additive update c_t=f⊙c_{t-1}+i⊙g. 4 weight matrices. Solves long-range dependencies.

7

GRU: 2 gates (r=reset, z=update). h_t=(1−z)⊙h̃_t+z⊙h_{t-1}. 3 weight matrices. 25% fewer params. Faster. Similar performance to LSTM.

8

Truncated BPTT: process sequence in k-step chunks. Detach hidden state between chunks. Balances memory, speed, and learning range.

9

SDG Impact: LSTM powers SDG 3 (ICU monitoring), SDG 2 (crop forecasting), SDG 7 (energy demand), SDG 13 (flood prediction), SDG 4 (adaptive learning).

Next → Module 6: Recent Trends — GANs, Image Generation, DeepFakes & Applications of Deep Learning