Cross-entropy loss trains classifiers by penalizing incorrect probability assignments. It increases loss when a true relationship or class receives low probability, aligning optimization with label matching. section 11.4.1 section 12.1.4
In graph learning, the loss supports two complementary classification settings:
- Link prediction uses negative sampling: positive graph edges receive high scores, while sampled false edges receive low scores; a balancing parameter controls negative-sample importance. section 11.4.1
- Node classification applies CrossEntropyLoss to encoder outputs and actual labels, such as licit versus illicit transaction categories. section 12.1.4
- A sigmoid converts relationship scores into probabilities, while log_softmax provides numerically stable class probabilities for the decoder. section 11.4.1 section 12.1.4
Listing 12.10 Encoder–decoder implementation for node classification
import torch
import torch.nn.functional as F
class NodeClassifier(torch.nn.Module):
def __init__(self, gnn_model):
super().__init__()
self.gnn = gnn_model
def forward(self, x, edge_index):
x = self.gnn(x, edge_index)
return F.log_softmax(x, dim=1)
A PyTorch node-classification decoder returns log_softmax outputs from a GNN encoder before CrossEntropyLoss evaluates the predictions. section 12.1.4


















