TorchedUp
ProblemsPremium
TorchedUp
Triplet Margin LossEasy
ProblemsPremium

Triplet Loss

Implement the triplet margin loss with squared L2 distances.

Signature: def triplet_loss(anchor: np.ndarray, positive: np.ndarray, negative: np.ndarray, margin: float = 1.0) -> float

Formula: max(0, ||a - p||^2 - ||a - n||^2 + margin)

Math

Asked at

Python (numpy)0/3 runs today

Test Results

○easy triplet (loss = 0)
○violating triplet
○within margin (positive)🔒 Premium
Advertisement