The loss function measures the gap between predictions and expected values; it is the quantity that training seeks to minimize. Squared error (MSELoss) is used for regression, cross-entropy (CrossEntropyLoss) for classification. It must be differentiable so a gradient can be computed.
Example
perte = nn.CrossEntropyLoss()(logits, cibles)