Triplet loss trains embeddings by comparing three points at once: an anchor, a positive (same class as the anchor), and a negative (a different class). It wants the anchor closer to its positive than to its negative, by at least a margin.
Let d(a, b) be squared Euclidean distance between two embeddings:
Task: write triplet_loss(anchors, positives, negatives, margin) returning the mean loss over all triplets, rounded to 4 decimal places.
anchors, positives, negatives is a list of embedding vectors (lists of floats), one triplet per index.