Question on hard triplet loss

Hello guys in week 3, course 3 of natural language processing specialization, the video lecture titled,‘Triplets’ at 5:12 minute said, hard triplets are those where the similarity between anchor and negative is very close with the similarity between anchor and positive but are smaller than the similarity between anchor and positive. and also the practice code masks those values where sim_an > sim_ap by the following lines of code, 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 = np.copy(sim_an) # create a copy to preserve sim_an
sim_an_masked[mask] = -2

closest_neg = np.max(sim_an_masked, axis=1, keepdims=True). but the lecture note which exists next to the lecture video, “triplets” , says * Hard negative triplet: cos(A,P) < cos(A,N) isn’t this statement incorrect?

Simplifying this: sim(A, P) < sim(A, N)

Based on this assumption the lecture note looks correct to me. Am I missing something?

your response is not clear

Sorry, I’m not able to identify the difference you’re trying to highlight. I’m seeing two equations that look like A<B and B>A in your question. It may be just my misunderstanding.

Hi @mahder

as far as I see with both statement, you are missing one mentions hard triplet and the latter mention hard negative triplet,

the first condition where cos(A,P) > cos(A,N) or another way is cos (A,N) < cos(A,P)

where as

this clearly mentions coz(A,P) < coz(A,N) is for hard negative triplet" specifically indicates a triplet where the negative sample is the most difficult negative example to differentiate from the anchor.

Both are two different scenarios depending on the samples relativity to anchor.

1 Like