Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The Pipeline

Here is the path from raw text to a model that generates new sentences:

training data  ->  tokenizer  ->  model  ->  training  ->  saved weights
                                                               |
                   tokenizer  ->  model  ->  generation  <-  load weights

We build each piece from scratch, in order. Each chapter introduces one component and ends with a Complete Code page containing the finished source for that stage.

What You Will Build

ChapterYou will createPipeline stage
The Tokenizertokenizer.tsTurns words into numbers and back
The Autograd Engineautograd.tsAutomatic differentiation (makes training possible)
Neural Network Primitivesnn.tsLinear layers, softmax, normalization
The Modelmodel.ts, rng.tsThe GPT architecture: config, weights, forward pass
Trainingtrain.tsThe training loop and optimizer
Saving the ModelsaveModel, loadModelSerialize trained weights to disk and load them back
Generationgenerate.tsInference: turning a trained model into sentences
Smoke Testphrases-train.ts, phrases-generate.tsEntry points to train and generate
Fine-Tuningphrases-fine-tune.tsAdapt a trained model to new data