Sequences, RNNs, LSTM and GRU

2 min

Objective: model an ordered sequence and understand recurrent memory.

A recurrent network reads a sequence element by element. Its hidden state summarizes the past:

text
h_t = φ(W_x x_t + W_h h_{t-1} + b)

The same weights are reused at each step. This recurrence accepts variable lengths but makes temporal computation sequential and exposes it to vanishing gradients.

LSTM and GRU

The LSTM adds a memory state and input, forget and output gates. The GRU combines some gates and has fewer parameters. These gates learn what information to keep, modify or forget.

python
from torch import nn

rnn = nn.GRU(input_size=64, hidden_size=128, num_layers=2,
             batch_first=True, dropout=0.2, bidirectional=True)

Preview — the rest of the lesson is for enrolled readers.

Already enrolled with a code?

Your access is tied to your account, not to this link. Sign in with the same email you used in class: your course is waiting, no need to enter the code again.

Sign inNo account yet? Create one
This lesson is part of the “Specialized Architectures” module

The first modules of the course are open to everyone. For the rest you have three options: buy this course once and for all, subscribe, or enter the code handed out in class.

Are you a student on this course?

The code is tied to your account: sign in or create an account and it will be applied automatically when you come back.

No account yet? Create one