Next-token prediction is self-supervised: the label at each position is the token that actually follows in the text, so raw text supplies both input and target.
Cross-entropy loss
For a single position where the correct next token is \(y\) and the model assigns it probability \(p_y\), the loss is \[-\log p_y.\] Averaged over all positions in a batch, this is the cross-entropy loss. It is small when the model puts high probability on the correct token and large when it does not. Minimizing it is the same as maximizing the probability the model assigns to the observed text.
Every position in a document is a training example, so a corpus of length \(n\) provides roughly \(n\) prediction problems with labels already present. The supervision signal grows with the data, which is what makes training on very large text collections feasible.