Skip to content
StackDecode
LLM Library
TrainingAnimated

Pretraining: Predicting the Next Token

The first and most expensive training stage.

The idea

The model reads trillions of tokens and is trained to predict each next token. The error (cross-entropy loss) is used to update the weights by gradient descent.

Watch it work

Press play, pause, or step through. Some animations have settings you can change.

Prompt: "The cat sat on the ___"mat4.2sofa3.4floor3.0roof1.6moon0.8table0.5dog-0.3idea-1.4
  • candidates kept
  • chosen

The model produces a raw score (logit) for every word in its vocabulary. Only eight are shown here.

1/3

Temperature reshapes the probabilities; top-k and top-p cut the tail.

Step by step

  1. 1Collect and clean a huge text dataset
  2. 2Cut it into sequences
  3. 3Predict each next token
  4. 4Update the weights to reduce the loss

Where it is used

Creating a base model.

Watch out for

A base model completes text; it does not follow instructions well until post-training.