liveBook · Manning

Cross entropy loss

As explained in Deep Learning with Python, Third Edition

A classification loss that measures the mismatch between predicted probability distributions and true token labels.

Cross-entropy measures the distance between probability distributions. In classification, it compares the model’s predicted probabilities with the ground-truth distribution and provides a loss for training. section 4.1.3

Choose the cross-entropy variant to match the classification task:

  • Use binary cross-entropy for two-class classification, typically with one sigmoid output representing a probability. section 3.6.5 section 4.1.7
  • Use categorical cross-entropy for multiclass classification. section 4.4

Binary classification in Keras

For a binary classifier with a sigmoid output, configure training with `loss="binary_crossentropy"`; the same choice is used for a dogs-versus-cats ConvNet. section 4.1.3 section 8.2.3

Listing 4.5 Compiling the model
model.compile(
    optimizer="adam",
    loss="binary_crossentropy",
    metrics=["accuracy"],
)

Shows binary cross-entropy configured as the model’s loss in a Keras compile call. section 4.1.3

How Deep Learning with Python, Third Edition covers it

How deep it goes
Defines cross-entropy as a distance between distributions and gives task-based loss choices without deriving the calculation.
Examples
Uses binary classifiers for sentiment and dogs-versus-cats classification, alongside a categorical-classification rule.
What it assumes
Assumes familiarity with classification tasks and, for binary models, a sigmoid output encoding a probability.
What you can do after
Apply it via Keras by selecting binary or categorical cross-entropy to match the classification task.
How it connects
Connects classification, probability distributions, sigmoid activation, and model training.

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 Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.