def reduce_labels(self, y: np.ndarray | "torch.Tensor") -> np.ndarray | "torch.Tensor":
        """
        Reduce labels from one-hot encoded to index labels.
        """

        import torch

        # Check if the loss function supports probability labels and probability labels are provided
        if self._probability_labels and len(y.shape) == 2:
            if isinstance(y, torch.Tensor):
                is_one_hot = torch.equal(y.float().floor(), y.float().ceil())
            else:
                is_one_hot = np.array_equal(np.floor(y), np.ceil(y))
            if not is_one_hot:  # probability labels
                return y

        # Check if the loss function requires as input index labels instead of one-hot-encoded labels
        # Checking for exactly 2 classes to support binary classification
        if self.nb_classes > 2 or (self.nb_classes == 2 and len(y.shape) == 2 and y.shape[1] == 2):
            if self._reduce_labels and self._int_labels:
                if isinstance(y, torch.Tensor):
                    return torch.argmax(y, dim=1)
                return np.argmax(y, axis=1)
            if self._reduce_labels:  # float labels
                if isinstance(y, torch.Tensor):
                    return torch.argmax(y, dim=1).float()
                y_index = np.argmax(y, axis=1).astype(np.float32)
                y_index = np.expand_dims(y_index, axis=1)
                return y_index
            return y

        if isinstance(y, torch.Tensor):
            return y.float()
        return y.astype(np.float32)

        Reduce labels from one-hot encoded to index labels.
        
art/estimators/classification/pytorch.py