Abstract
Multilabel classification is the task of attributing multiple labels to examples via predictions. Current models formulate a reduction of the multilabel setting into either multiple binary classifications or multiclass classification, allowing for the use of existing loss functions (sigmoid, cross-entropy, logistic, etc.). These multilabel classification reductions do not accommodate for the prediction of varying numbers of labels per example. Moreover, the loss functions are distant estimates of the performance metrics. We propose sigmoidF1, a loss function that is an approximation of the F1 score that (i) is smooth and tractable for stochastic gradient descent, (ii) naturally approximates a multilabel metric, and (iii) estimates both label suitability and label counts. We show that any confusion matrix metric can be formulated with a smooth surrogate. We evaluate the proposed loss function on text and image datasets, and with a variety of metrics, to account for the complexity of multilabel classification evaluation. sigmoidF1 outperforms other loss functions on one text and two image datasets over several metrics. These results show the effectiveness of using inference-time metrics as loss functions for non-trivial classification problems like multilabel classification.
Introduction
In machine learning, a persistent "metric gap" exists between training objectives and evaluation metrics. While models are typically trained using standard losses like Cross-Entropy or Binary Cross-Entropy (BCE), they are often evaluated using the F1 score. This discrepancy is particularly acute in multi-label classification, where an instance (e.g., a movie poster) may belong to multiple categories simultaneously.
Standard approaches treat multi-label tasks as independent binary decisions. However, this fails to account for the inherent trade-off between precision and recall and struggles with predicting varying label counts per example. Because the F1 score relies on discrete counts of True Positives and False Positives—requiring a non-differentiable hard threshold—it cannot be optimized directly via gradient descent.
Methodology
The proposed sigmoidF1 loss bridges this gap by creating a smooth, differentiable surrogate for the F1 score. The core innovation involves replacing the non-differentiable step function used for thresholding with a tunable sigmoid curve.
As shown in Figure 1, the pipeline transforms logits $\hat{\mathbf{y}}$ into smoothly bounded predictions $S(\hat{\mathbf{y}})$ using a sigmoid function. These "soft" predictions are then used to calculate differentiable approximations of the confusion matrix components (True Positives, False Positives, and False Negatives), which in turn define the sigmoidF1 loss ($\mathcal{L}_{\widetilde{F1}}$).
The specific mapping function used is: $$S(u; \beta, \eta) = \frac{1}{1 + \exp(-\beta(u + \eta))}$$ where $\beta$ (slope) controls the "hardness" of the threshold and $\eta$ (offset) controls its location.
Figure 2 illustrates how varying these parameters allows the surrogate to approximate the step function while remaining differentiable, enabling backpropagation to directly optimize for the F1 metric.
Experiments and Results
The authors evaluated sigmoidF1 across diverse datasets spanning text and image modalities:
- Image: moviePosters (genres), Pascal-VOC (20 object classes), and MS-COCO (80 categories).
- Text: arXiv2020 (155 scientific subjects) and medical datasets (cancerHallmarks, chemicalExposure).
Key Results
sigmoidF1 consistently outperformed or matched state-of-the-art losses like Focal Loss and Asymmetric Loss (ASL):
- Superior F1 Performance: On the Pascal-VOC dataset,
sigmoidF1achieved a weighted F1 of 88.20%, significantly beating standard BCE (87.52%) and Focal Loss (72.54%). - Robustness in Text: On the arXiv2020 dataset, it reached a weighted F1 of 20.60%, outperforming all other tested loss functions.
- Small Dataset Advantage: On smaller, sparser medical datasets,
sigmoidF1was often the only loss that produced non-zero results, whereas BCE failed to reach the required confidence thresholds.
Discussion and Conclusion
A key insight is that sigmoidF1 is calculated over a batch, forcing the model to learn label "suitability" relative to other labels. This naturally assists in estimating the correct number of labels per instance. The authors identify three critical properties for such surrogate losses: they must be bounded, saturate (pushing decisions toward 0 or 1), and maintain dynamic gradients.
While sigmoidF1 requires hyperparameter tuning for $\beta$ and $\eta$, it demonstrates that fitting the algorithm to the data—by optimizing the evaluation metric directly—is a powerful alternative to standard reductions. Future work includes extending this smooth surrogate approach to other non-differentiable metrics like the Jaccard index.
Summary updated