Computes the triplet loss with semi-hard negative mining.
tfa.types.FloatTensorLike = 1.0,
distance_metric: Union[str, Callable] = 'L2',
name: Optional[str] = None,
Used in the notebooks
The loss encourages the positive distances (between a pair of embeddings
with the same labels) to be smaller than the minimum negative distance
among which are at least greater than the positive distance plus the
margin constant (called semi-hard negative) in the mini-batch.
If no such negative exists, uses the largest negative distance instead.
We expect labels
y_true to be provided as 1-D integer
Tensor with shape
[batch_size] of multi-class integer labels. And embeddings
y_pred must be
Tensor of l2 normalized embedding vectors.
Float, margin term in the loss definition. Default value is 1.0.
Optional name for the op.
Loss from its config (output of
Returns the config dictionary for a
y_true, y_pred, sample_weight=None
Ground truth values. shape =
[batch_size, d0, .. dN], except
sparse loss functions such as sparse categorical crossentropy where
[batch_size, d0, .. dN-1]
The predicted values. shape =
[batch_size, d0, .. dN]
sample_weight acts as a coefficient for the
loss. If a scalar is provided, then the loss is simply scaled by the
given value. If
sample_weight is a tensor of size
the total loss for each sample of the batch is rescaled by the
corresponding element in the
sample_weight vector. If the shape of
[batch_size, d0, .. dN-1] (or can be broadcasted to
this shape), then each loss element of
y_pred is scaled
by the corresponding value of
sample_weight. (Note on
dN-1: all loss
functions reduce by 1 dimension, usually axis=-1.)
Weighted loss float
NONE, this has
[batch_size, d0, .. dN-1]; otherwise, it is scalar. (Note
because all loss functions reduce by 1 dimension, usually axis=-1.)
If the shape of
sample_weight is invalid.