Triplet Loss for Siamese Model

I cant get the right output for UNQ_C3

Where do things fall apart here?

scores [[ 1. 0.9535077] [-0.9535077 -1. ]] (scores =, v2.T))
batch_size 2
positive: [ 1. -1.] (positive = fastnp.diagonal(scores))
negative_without_positive: [[-1. 0.9535077] [-0.9535077 -3. ]] (scores - (fastnp.eye(batch_size) * 2.0))
closest_negative [ 0.9535077 -0.9535077] fastnp.max(negative_without_positive, axis = 1)
negative_zero_on_duplicate: [[ 0. 0.9535077] (1 - fastnp.eye(batch_size)) * scores
[-0.9535077 -0. ]]
mean_negative: [ 0.9535077 -0.9535077]
Triplet Loss: 1.3285077

Any help would appreciated. Happy to get on DM for further help and a code walkthrough

Thank you

Hi @eranpick,

Can you share your lab ID with me ? In the assignment, when you click the top right “Help” button, a panel will open and your lab ID will be shown at the bottom.

I shall take a look.

When you reply back, kindly tag me in the post so that I’m notified.


@Mubsi - Thank you for your reply! and appreciate the guidance.
LAB ID: bjgzfgzu
Thank you,

Hi @eranpick,

I have just updated the code cell comments for that exercise (Ex 3), that should help you spot your mistake, you were calculating the loss_1 and loss_2 incorrectly. Read the updated instructions before copy/pasting your previous work for that exercise.

While I was looking at your work, I noticed you were using integers in that exercise when you should have been using floats. For example 0.0 instead of 0.


1 Like