Topic

RNNs and sequence modeling

He shows that RNNs learn stateful programs from raw characters. He uses visualization and error analysis to see what they learn and where long-range dependencies fail.

Based on Andrej Karpathy's public content. Not affiliated with or endorsed by Andrej Karpathy.

Covered in

GitHub · char-rnn: Multi-layer Recurrent Neural Networks (LSTM, GRU, RNN) for character-level language models in Torch

This README describes char-rnn, Karpathy's Torch code for training multi-layer RNN/LSTM/GRU character-level language models and sampling text from them. Beyond usage, he teaches practical training wisdom: match parameter count to dataset size, monitor training vs. validation loss to diagnose over/underfitting, and pick the checkpoint with the lowest validation loss.

The Unreasonable Effectiveness of Recurrent Neural Networks

Karpathy teaches that recurrent neural networks are powerful because they maintain state and can apply the same learned transformation across sequences of arbitrary length, effectively learning stateful programs. Through character-level language modeling experiments, he shows that RNNs can learn spelling, syntax, formatting, and some longer-range structure directly from raw text, while still struggling with long-term dependencies and semantic consistency.

Paper · Visualizing and Understanding Recurrent Networks

This paper, co-authored by Karpathy with Justin Johnson and Li Fei-Fei, uses character-level language models as an interpretable testbed to study what LSTMs actually learn. It shows interpretable cells that track long-range structure (line length, quotes, brackets), traces LSTM gains over n-gram baselines to long-range dependencies, and breaks down remaining errors with a sequence of oracles, finding that scaling up mostly fixes short-range n-gram errors.