← Speech and Language Processing
NLP›Popular Textbooks› SLP · Chapter 7

Chapter 7

Transformers and Pretraining: From Attention Weights to the Next Token

Chapter: Transformers and Pretraining, in Daniel Jurafsky and James H. Martin, Speech and Language Processing, 3rd edition draft, August 19, 2026.

Topics to learn

Page numbers refer to the linked chapter PDF.

FAQ

Why is replacing a future attention score with zero not a mask?

Softmax turns a score of zero into a positive weight. A forbidden position needs probability zero after normalization, usually from a score of negative infinity before the softmax.

Does masking only the last layer prevent future leakage?

No. An earlier layer can already have copied a future token into an allowed position. Every attention layer that could move that information has to respect the same boundary.

Do temperature, top-k, or top-p change the trained model?

No. They change which tokens the sampler can draw from the current distribution. The weights stay fixed.

What is the pretraining target in this chapter?

The next token. The current token is input. The following token is the label. Predicting the unshifted token while also attending to it would be a different, easier task.