Gradient descent is the iterative optimization algorithm that adjusts model parameters to reduce a loss function. Fine-tuning starts with pretrained weights and adapts them to a specific task rather than learning from random parameters. section 3.0 section 3.1.2
A model’s parameters determine how inputs become outputs. The loss function converts the model’s current error into one number: lower loss is better. Gradient descent uses the slope of that loss to choose parameter changes that should make the next prediction less wrong. section 3.1.2
A basic training loop follows these steps:
- Read input and target batches from a data loader. section 3.1.2
- Run the model to produce outputs. section 3.1.2
- Calculate loss by comparing outputs with targets. section 3.1.2
- Clear previous gradients, backpropagate the loss, and let the optimizer update parameters. section 3.1.2
- Monitor loss periodically to track training progress. section 3.1.2
Sentiment fine-tuning
Suppose a model predicts “positive” with 30% probability when the correct label is “positive.” Cross-entropy loss penalizes this uncertainty, and gradient descent adjusts parameters so future predictions can become more confident and accurate. section 3.1.2
Figure 3.5 Gradient descent principle illustrated with a single weight variable. For LLMs, the same principle applies to billions of parameters.

Shows gradient descent as movement toward a lower-loss valley using a single weight, while the same principle applies across billions of language-model parameters. section 3.1.2























