Loss Functions¶
Loss functions (also called cost functions or objective functions) are used to measure how well a neural network's predictions match the target values. The goal of training is to minimize this value.
Sorix provides several common loss functions for different types of tasks.
Available Loss Functions¶
| Loss Function | Use Case | Description |
|---|---|---|
MSELoss |
Regression | Mean Squared Error between prediction and target. |
BCEWithLogitsLoss |
Binary Classification | Binary Cross Entropy with integrated Sigmoid for stability. |
CrossEntropyLoss |
Multiclass Classification | Measures the difference between two probability distributions. |
Which loss function should I use?¶
- Regression: Use
MSELosswhen predicting continuous values (e.g., house prices). - Binary Classification: Use
BCEWithLogitsLosswhen you have two classes (0 or 1). - Multiclass Classification: Use
CrossEntropyLossfor multiple mutually exclusive classes (e.g., MNIST digit recognition).
Basic Usage¶
In Sorix, loss functions are objects that you call with two tensors: the predictions (y_pred) and the ground truth (y_true).