Update auc.py
* Update auc.py
To allow, in some case, there is no positive or negative sample in a batch.
* Update auc.py
* Update auc.py
Not sure should it be more efficient leaving `torch.unique` at line there or not.
@@ -52,7 +52,7 @@ class Auc(Metric):
raise ConfigurationError("AUC can be used for binary tasks only. gold_labels has {} unique labels, "
"expected at maximum 2.".format(unique_gold_labels.numel()))
- gold_labels_is_binary = list(torch.sort(unique_gold_labels)[0].numpy()) == [0, 1]
+ gold_labels_is_binary = set(unique_gold_labels.tolist()) <= {0, 1}
if not gold_labels_is_binary and self._positive_label not in unique_gold_labels:
raise ConfigurationError("gold_labels should be binary with 0 and 1 or initialized positive_label "
"{} should be present in gold_labels".format(self._positive_label))
