In the lab notebook C3_W4_lecture_nb_2_Modified_Triplet_Loss.ipynb
the closest_neg
part of the triplet loss is defined as:
mask_1 = np.identity(b) == 1 # mask to exclude the diagonal
mask_2 = sim_an > sim_ap.reshape(b, 1) # mask to exclude sim_an > sim_ap
mask = mask_1 | mask_2
...
sim_an_masked[mask] = -2
closest_neg = np.max(sim_an_masked, axis=1, keepdims=True)
In other words, you do not consider negative values that are greater than the positive value.
However, in the graded assignment, if you follow this, your tests will not pass. You must consider all negative values in the calculation.
The lectures and readings don’t seem to take a definitive stance on which is correct. It seems like this should be called out more explicitly, and if both are fine, the graded assignment should make it clear which method to use.