Project 04 · Language models · From scratch

Understanding language models by building the pieces.

nanoLLM is a set of experiments that makes language-model behavior concrete by comparing increasingly capable sequence models on the same task.

The learning path

The project moves from simple recurrent models to Transformers, making it easier to see what changes when memory, context, and attention improve.

Sequence models RNN → GRU → LSTM Learn how recurrent memory evolves
→
Attention Transformer Compare context and attention heads
→
Evaluation Metrics, sweeps, and figures Turn model behavior into evidence

What I investigated

Model behavior

How do RNN, GRU, LSTM, and Transformer architectures compare when trained under a consistent experimental setup?

Context and attention

How do context length and the number of attention heads affect language-model performance?

4 model families compared
from scratch training and analysis
Tiny Shakespeare experimental dataset

Measured result

On Tiny Shakespeare, the modern Transformer achieved the lowest validation bits per byte at 2.1052, compared with 2.4384 for the vanilla RNN. GRU and LSTM narrowed most of the gap, while the larger LSTM underperformed the smaller one despite using roughly four times as many parameters.

2.1052modern Transformer bpb
2.4384vanilla RNN bpb
−13.7%Transformer bpb vs RNN
256 charsbest Transformer context

Technical focus

Tokenization, sequence modeling, recurrent networks, self-attention, Transformer architecture, validation metrics, experiment sweeps, and reproducible analysis.