liveBook · Manning

Cross entropy loss

As explained in Build a Text-to-Image Generator (from Scratch)

Categorical cross-entropy loss measures the discrepancy between predicted class probabilities and the ground-truth class in multicategory classification.

Cross-entropy loss measures the discrepancy between predicted class probabilities and the ground-truth class. It supports multicategory image classification and sequence prediction by penalizing incorrect predictions and minimizing the loss during training. section 3.4.1 section 4.5

Apply cross-entropy loss through a supervised prediction loop:

loss_fn = nn.CrossEntropyLoss()

Instantiate categorical cross-entropy directly with PyTorch’s CrossEntropyLoss implementation. section 3.4.1

Caption and image-token prediction

For the caption “a dog runs,” the decoder receives “<start> a dog runs” and learns to predict “a dog runs <end>.” In text-to-image generation, the same objective compares predicted image-token sequences with actual sequences. section 4.5 section 12.1.1

How Build a Text-to-Image Generator (from Scratch) covers it

How deep it goes
Explains target alignment and parameter minimization, then implements the loss with PyTorch without deriving its mathematical formula.
Examples
Uses image classes, the caption “a dog runs,” German–English translation batches, and discrete image-token sequences.
What it assumes
Assumes model outputs, ground-truth labels or sequences, and parameter optimization; teaches target shifting for next-token prediction.
What you can do after
Apply it via PyTorch to train classifiers and autoregressive models against categorical or token-level targets.
How it connects
Connects image classification, autoregressive decoding, sequence-to-sequence learning, tokenization, and teacher-forced target sequences.

Also explained in

Compare how 19 books explain cross entropy loss →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Text-to-Image Generator (from Scratch). The section links point to the parts of the book it draws on.