liveBook · Manning

Cross entropy loss

As explained in Graph Neural Networks in Action

CrossEntropyLoss is a PyTorch loss module that measures classification error from logits and target class labels.

For a multiclass node-classification model, loss gives a way to track prediction error: lower is better. Log loss is used alongside F1 score to compare GCN and GraphSAGE models. The reported scores are evaluation results; they do not show how to configure PyTorch’s CrossEntropyLoss module or what inputs to pass to it. section 3.1.4

Use loss at two points in the workflow:

  • Plot training and validation loss after each epoch. If training loss keeps falling while validation loss rises, the model is overfitting; retain the model instance with the lowest validation loss. section 3.1.4
  • Compare validation-set log loss with F1 score. A single score need not settle model choice: prediction requirements and the consequences of errors matter. section 3.1.4 section 3.2.1

Choosing a neighborhood aggregation

With mean, sum, and max aggregation in GraphSAGE, max has both the highest F1 score (0.7449) and lowest log loss (2.1039). A later list-aggregation comparison is less straightforward: the standard list raises F1 to 0.7484 but also raises log loss to 2.622. Check both measures rather than treating an F1 improvement as an across-the-board gain. section 3.2.1 section 3.2.2

Figure 3.1 Training and validation loss curves for the GCN model (left) and GraphSAGE model (right) trained in this section. The divergence of the validation from the training curve signals over-fitting, where the model learns the training data too well and at the expense of generalizing to new data.
figure

The training and validation curves make the point where falling training loss stops indicating better generalization visible. section 3.1.4

How Graph Neural Networks in Action covers it

How deep it goes
Works through loss curves and metric comparisons, but does not specify CrossEntropyLoss inputs, implementation, or a mathematical derivation.
Examples
Compares GCN and GraphSAGE validation scores, then contrasts mean, sum, max, and list aggregation results.
What it assumes
Introduces loss as a measure of prediction quality while assuming a trained classification model with training and validation results.
What you can do after
Evaluate/understand model trade-offs by reading validation-loss curves and comparing log loss with F1 score.
How it connects
Connects log loss to F1 score, validation loss, overfitting, GCN, GraphSAGE, and neighborhood aggregation.

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 Graph Neural Networks in Action. The section links point to the parts of the book it draws on.