DL Basics — PyTorch MLPs, CNNs, Sequences, Fine-Tuning Discipline
Back to M3 — Sequences + NLP Baselines

RNN/Sequence Concepts (LSTM/GRU, Masking, Embeddings)

Outcome: explain padding/masking on 2 examples. Curated video (16:37, verified 2026-09-24 via yt-dlp): Recurrent Neural Networks (RNNs), Clearly Explained!!! (StatQuest with Josh Starmer) Watch: https://www.youtube.com/watch?v=AsNTP8Kwu80 Notes: RNN anatomy, running sequences through the net, shared weights, vanishing/exploding gradients (motivation for LSTM/GRU). Lesson pairs this with padding/masking + embedding examples in the drill. NOTE: 16:37 runs just over the 15-min target but inside the 30-min cap; kept for breadth. Key moments: 0:00 Intro; 4:13 RNN anatomy; 5:59 Running data; 10:31 Shared weights; 11:23 Vanishing/exploding gradients.

17 minutesVideo LessonPDF notes
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.
Loading progress...

Key moments

  1. Sequence Modeling Overview — Introduction to sequence structures and challenges with variable-length temporal data.
  2. Token Embeddings — Explanation of vector representations and PyTorch nn.Embedding lookup tables.
  3. LSTM and GRU Gating — Analysis of recurrent cell equations, memory highways, and gating mechanisms.
  4. Padding and Packing Utilities — Walkthrough of padding batches and using pack_padded_sequence to skip invalid tokens.
  5. Masking and Loss Computation — Techniques for masking attention and ignoring pad indices in objective functions.
PDF notes

Frequently asked questions

Why use an Embedding layer instead of a Linear layer with one-hot inputs?

An embedding layer performs direct indexing O(1) in memory rather than allocating huge sparse matrices and running O(V * D) matrix multiplications.

What is the key functional difference between LSTM and GRU?

LSTMs maintain separate cell and hidden states using three gates, whereas GRUs combine cell and hidden states using only two gates, reducing computation.

How does enforce_sorted=False affect pack_padded_sequence?

It allows passing batches where sequence lengths are not pre-sorted in descending order, at the expense of a minor internal sort-and-restore overhead.

How was this lesson?

Your feedback helps us refine explanations and catch bugs.