Wrong Triplet Loss for Siamese Model

I got wrong triplet_loss value for week 4, exercise 3. Could you please let me know which part is wrong? My lab id is kmxhromq. Thanks in advance!

Below are the details:
scores: [[ 1. 0.9535077]
[-0.9535077 -1. ]]
positive: [ 1. -1.]

negative_zero_on_duplicate: [[ 0. 0.9535077]
[-0.9535077 -0. ]]
mean_negative: [ 0.9535077 -0.9535077]

mask_exclude_positives: [[1. 0.]
[0. 1.]]
negative_without_positive: [[-2. 0.9535077]
[-0.9535077 -2. ]]
closest_negative: [ 0.9535077 -0.9535077]

triplet_loss1: [0.20350772 0.29649228]
triplet_loss2: [0.20350772 0.29649228]
Triplet Loss: 0.5

Expected Output:
Triplet Loss: ~ 0.70

Just figured out that the right results should have the following:

mask_exclude_positives: [[ True False]
[ True True]]
negative_without_positive: [[-2. 0.9535077]
[-2.9535077 -2. ]]
and
triplet_loss1: [0.20350772 0. ]
triplet_loss2: [0.20350772 0.29649228]

Then only sum of the two losses is 0.70 which is considered correct. Why the instruction said " triple_loss is the fastnp.mean of the sum of the two individual losses." ?

(Solution code removed, as posting it publicly is against the honour code of this community, regardless if it is correct or not)

This is my sol may its help its correct

1 Like