Module 17

Recurrent Networks, Sequences and Classical NLP

How do we design networks that represent ordered information, maintain context and process variable-length sequences?

lessons
24
duration
41 h
concepts
121
available in English
24 / 24
completed by you
0 of 24

Where it fits

Leads to

Overview

Follow sequence modeling from statistical language models (n-grams and Kneser-Ney smoothing) and distributional semantics (PPMI, LSA, Word2Vec and GloVe) to recurrent networks: RNNs, backpropagation through time, temporal gradient analysis, LSTMs, GRUs, deep and bidirectional variants, and training on a local GPU. The second half builds encoder–decoder and seq2seq systems, introduces attention at its origin (additive and multiplicative, implemented from scratch with manual backward passes), studies exposure bias, CRF and CTC labeling, and a complete translator. It closes with limits of sequential processing and the frontier: RNN dynamics and computational power, and the return of parallelizable recurrence (xLSTM, minGRU, DEER).

Why it matters

Attention in m18 and LLMs in m20 arose from problems experienced here: the fixed-context bottleneck, a sequential chain that cannot be parallelized, and exposure bias. Implementing RNNs, LSTMs and attention-based seq2seq with manual backward passes builds intuition about gradient flow and memory needed to read and extend modern recurrent architectures, including xLSTM, state-space models and hybrids. N-grams, embeddings and recurrent models also remain fast, inexpensive local tools for logs, code and time series, useful for application security, code language modeling, anomaly detection and quantitative sequence work.

Lessons 24

  1. 01Review: sequences as data and the autoregressive factorizationStudy sequences, tokenization, word frequencies, autoregressive probabilities and sequence task shapes.Review60 min
  2. 02N-gram language modelsBuild and evaluate n-gram language models, including maximum-likelihood estimation, sampling and sparse contexts. GPUCore100 min
  3. 03Smoothing: from Laplace to Kneser-NeyStudy probability smoothing, Good-Turing, interpolation, backoff and Kneser-Ney, with controlled evaluations. GPUCore110 min
  4. 04Distributional semantics: co-occurrence, PMI and LSAStudy distributional semantics, co-occurrence, TF-IDF, PPMI and latent semantic analysis with reproducible corpora.Core95 min
  5. 05The neural probabilistic language model: end-to-end learned embeddingsBuild a fixed-window neural language model, derive embedding gradients and analyze full-vocabulary output cost. GPUCore90 min
  6. 06Word2Vec: skip-gram, CBOW and negative samplingStudy Word2Vec skip-gram and CBOW, hierarchical softmax, negative sampling and their evaluation protocols. GPUCore115 min
  7. 07GloVe and implicit factorization: why word embeddings workStudy GloVe, co-occurrence ratios and the assumptions connecting SGNS to shifted PMI. GPUAdvanced100 min
  8. 08Using and evaluating word embeddings: analogies, subwords, bias and limitsEvaluate embeddings through analogies, task performance, subword composition, association tests and polysemy. GPUCore85 min
  9. 09Recurrent neural networks: hidden state, shared parameters and language modelsStudy recurrent neural networks, shared state transitions, task losses and character generation. GPUCore100 min
  10. 10Backpropagation through time: derivation, implementation and truncationDerive backpropagation through time, truncated gradients, contiguous stream batching and RTRL costs. GPUCore110 min
  11. 11Vanishing and exploding gradients through timeAnalyze temporal Jacobians, vanishing and exploding gradients, clipping and recurrent memory benchmarks. GPUAdvanced105 min
  12. 12LSTM: the memory cell and the constant error carouselStudy LSTM memory cells, multiplicative gates, backward propagation and implementation parity. GPUCore115 min
  13. 13GRU and the family of gated recurrencesDerive GRU variants and gradients, interpret gates as leaky integrators, examine chrono initialization, and compare gated architectures under reproducible protocols. GPUCore90 min
  14. 14Deep and bidirectional RNNs and contextual embeddingsExplore stacked and bidirectional recurrent networks, causal context, ELMo-style contextual representations, and language-model pretraining and transfer. GPUCore90 min
  15. 15Training RNNs for real: batching, regularization and GPU speedTrain recurrent language models using variable-length batching, recurrent regularization, adaptive softmax, and careful diagnostics and benchmarking. GPUCore110 min
  16. 16Sequence labeling and alignments: BiLSTM-CRF and CTCModel structured sequence labels with BiLSTM-CRF and marginalize monotonic alignments with CTC, including dynamic programs, gradients, and evaluation. GPUAdvanced115 min
  17. 17Encoder-decoder and sequence-to-sequence learningBuild recurrent encoder-decoder models for sequence transduction, examine teacher forcing and greedy decoding, and interpret BLEU, chrF, source reversal, and context bottlenecks. GPUCore110 min
  18. 18Additive attention: jointly learning to align and translateDerive additive attention and its gradient, interpret soft and hard alignment, and examine recurrent sequence-to-sequence experiments with careful empirical limits. GPUCore120 min
  19. 19Multiplicative attention and variants: Luong, local, monotonic and pointersCompare multiplicative attention scores, global and local windows, monotonic variants, pointer networks, and copy mechanisms under explicit protocols. GPUCore100 min
  20. 20Exposure bias: training the way you generateStudy the mismatch between reference and generated prefixes, measure conditional behavior in a known HMM, and evaluate scheduled sampling and sequence-level alternatives. GPUAdvanced95 min
  21. 21Guided project: an attention-based neural translator on your GPUBuild and assess a small Spanish-English neural translator using attention, coverage, copying, length-stratified metrics, paired bootstrap and controlled attention interventions. GPUCore120 min
  22. 22The limits of sequential processing and convolutional alternativesExamine sequential dependencies, fixed-size recurrent memory, effective context, parallelizable recurrences, and causal convolutional alternatives. GPUAdvanced100 min
  23. 23Dynamics and computational power of RNNsAnalyze recurrent dynamics through fixed points, slow states and reservoirs, then examine computational power and length generalization under explicit assumptions. GPUResearch115 min
  24. 24The return of RNNs: xLSTM, minimal RNNs and parallel recurrencesStudy minimal gated recurrences, stable exponential gating, matrix memory, and Newton-based parallelization, with measured implementation tradeoffs. GPUResearch110 min

Module capstone

Code naturalness: language models and attention-based seq2seq repair

Using the installed Python standard-library source, tokenized with tokenize and split by file, build a language-model ladder on the same partition: a custom order-3 to order-6 Kneser-Ney model, a neural window model, an AWD-LSTM-style regularized LSTM and minGRU. Compare token cross-entropy, throughput and memory, and test whether code is more predictable than natural language, as Hindle and colleagues observed. Then train a seq2seq model with bidirectional encoder, attention and copy mechanism to repair injected synthetic errors (missing parentheses or colons, swapped operators and changed variable names), in the style of DeepFix. Measure repair rate verified with ast.parse and use the best language model’s token surprise to locate anomalous lines. Deliver a reproducible three-seed report with quality-versus-length curves, attention maps for successes and failures, and a limitations discussion preparing the m18 transformer comparison.

Check what you already know

  • Estimate an n-gram model and evaluate held-out perplexity and bits per character using a comparable protocol.
  • Derive interpolated Kneser-Ney from absolute discounting and explain continuation probability.
  • Build embeddings with PPMI and truncated SVD and explain PMI’s bias toward rare events.
  • Derive word2vec negative-sampling gradients by hand for both vector tables.
  • Show that optimal SGNS factorizes PMI shifted by log k.
  • Implement forward and backward passes (BPTT) of an Elman RNN and verify them with gradient checking.
  • Bound ‖∂h_T/∂h_t‖ using singular values of W_hh and explain the robust-memory versus gradient dilemma.
  • Derive an LSTM cell backward pass and explain the forget gate’s role in gradient flow.
  • Process variable-length batches using masks or PackedSequence and apply variational dropout in an RNN.
  • Implement CTC loss using forward-backward in log space.
  • Build a seq2seq model with teacher forcing and greedy decoding and calculate BLEU with its brevity penalty.
  • Implement Bahdanau additive attention with a manual backward pass and padding mask.
  • Compare dot, general and concat scores and explain input feeding and the copy mechanism.
  • Explain exposure bias, implement scheduled sampling and discuss its criticism.
  • Calculate a dilated TCN’s receptive field and explain why an LSTM is not parallelizable over time.
  • Evaluate linear recurrence h_t = a_t h_{t−1} + b_t in parallel in log space.

References