Skip to content
class

MultiLabelMarginLoss

extendsMultilabelMarginLoss
MultiLabelMarginLoss(size_average: bool | None = None, reduce: bool | None = None, reduction: Reduction = 'mean')

CamelCase alias for MultilabelMarginLoss.

Provided so that nn.MultiLabelMarginLoss (the capitalisation used by the reference framework) resolves to the same implementation. There is no behavioural difference — all parameters, attributes, and shapes are identical to MultilabelMarginLoss.

Parameters

reductionstr= 'mean'
'none' | 'mean' (default) | 'sum'.

Notes

Identical loss formula to MultilabelMarginLoss:

loss(x,y)=∑ijmax⁡ ⁣(0,  1−(x[y[j]]−x[i]))∣x∣\text{loss}(x, y) = \sum_{ij} \frac{\max\!\bigl(0,\; 1 - (x[y[j]] - x[i])\bigr)}{|x|}

where the sum is taken over all pairs (i,j)(i, j) such that i∉{y[0],y[1],…}i \notin \{y[0], y[1], \ldots\}. Targets are padded with −1-1 to mark end-of-list; entries at or beyond the first −1-1 are ignored.

Examples

Interchangeable with MultilabelMarginLoss:
>>> import lucid
>>> import lucid.nn as nn
>>> criterion = nn.MultiLabelMarginLoss()
>>> scores = lucid.tensor([[0.5, 0.2, 0.9, 0.1]])
>>> target = lucid.tensor([[2, 0, -1, -1]])
>>> loss = criterion(scores, target)
Verifying alias equivalence:
>>> import lucid.nn as nn
>>> assert nn.MultiLabelMarginLoss is nn.MultiLabelMarginLoss
>>> c1 = nn.MultilabelMarginLoss()
>>> c2 = nn.MultiLabelMarginLoss()
>>> # Both produce identical results for the same inputs.

Used by 1