Issue with precision in the assignment

Hello Everyone,
I am struggling with issue for following example in triplet loss

y_pred_perfect = ([[1., 1.]],[[1., 1.]], [[0., 0.,]])
loss = triplet_loss(y_true, y_pred_perfect, 3)
assert loss == 1., "Wrong value. Check that pos_dist = 0 and neg_dist = 2 in this example"

I am getting following values in my code

anchor   = [[1.0, 1.0]]
positive = [[1.0, 1.0]]
negative = [[0.0, 0.0]]
pos_dist=tf.Tensor([0.], shape=(1,), dtype=float32)
neg_dist=tf.Tensor([1.9999999], shape=(1,), dtype=float32)
loss=tf.Tensor(1.0000001, shape=(), dtype=float32)

The issue is expected value for neg_dist=2 and loss=1

One way to solve the problem is change the type of tensor to float64 for anchor, positive and negative. But it is not mentioned anywhere in the assignment instructions. So I am not sure whether it is correct or not?
Any help is appreciated. Thanks in advance!

There is a comment there in the previous exercise which says:
# Step 4: Take the maximum of basic_loss and 0.0. Sum over the training examples.
This should convert the result into a float anyways.

No still doesn’t work but I figured out the issue. Thanks for the help!

1 Like