Soft-margin binary hinge loss.
Computes the element-wise two-class logistic loss between the input
x and the binary label y \in \{-1, +1\}:
This is the logistic (log-sigmoid) surrogate for the binary hinge. It is smooth and differentiable everywhere, unlike the hard hinge.
Parameters
reductionstr= 'mean''none' | 'mean' (default) | 'sum'.Attributes
reductionstrThe reduction mode.
Notes
- Input
x: — real-valued scores. - Target
y: — binary labels in . - Output : scalar for
'mean'/'sum'; for'none'.
- As with the loss approaches zero; as it grows linearly, which provides outlier robustness compared to cross-entropy.
- This loss is essentially
BCEWithLogitsLossre-labelled for targets.
Examples
Positive and negative labels:
>>> import lucid
>>> import lucid.nn as nn
>>> criterion = nn.SoftMarginLoss()
>>> x = lucid.tensor([ 1.5, -1.0, 0.5, -2.0])
>>> y = lucid.tensor([ 1.0, 1.0, -1.0, -1.0])
>>> loss = criterion(x, y)
Element-wise output:
>>> import lucid
>>> import lucid.nn as nn
>>> criterion = nn.SoftMarginLoss(reduction="none")
>>> x = lucid.tensor([0.0, 2.0])
>>> y = lucid.tensor([1.0, -1.0])
>>> loss = criterion(x, y) # shape (2,)Used by 1
Constructors
1Instance methods
2Return a string representation of the layer's configuration.