TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
←

173. Triplet Margin Loss

Easy

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

L=max(0,∥a−p∥22​−∥a−n∥22​+m)

Related problems

  • Triplet Margin Loss (PyTorch)easyPyTorch

Asked at

NumPy

import numpy as np

 

def triplet_loss(...):

    pass

🔒

Premium problem

Free accounts include problems #1–20. Upgrade to unlock the editor, hidden test cases, and reference solutions for every problem.

Upgrade to PremiumBack to problems

Already premium?