# Week4 - Assignment 1 / 3.2. Triplet Loss

Hej guys,

Thank you for the fantastic course and all that support you’re giving here on a daily base.
I stumbled upon an Issue in the named notebook and hoped, it might help, if i mentioned it.
I had a bit of a trouble figuring out, why my code didn’t run and eventually figured, there might be a mistake in the evaluation code for the Triplet Loss (W4/A1/3.2 Triplet Loss):
The problem I see is that the batch dimension in the first few examples is missing, thus the result is not correctly computed. As soon as you wrap the first dimension around it, all the steps pass perfectly:
i.e.
y_pred_perfect = ([1., 1.], [1., 1.], [1., 1.,]) you wrap the batch around them like so:
y_pred_perfect = ([[1., 1.]], [[1., 1.]], [[1., 1.,]])

Then all the tests, even the untouched ones, pass perfectly
Or was it intended otherwise?
(Sorry for pasting in code, but since it’s the evaluation code, i hoped you wouldn’t mind too much )

Best regards,
Christian

Sorry, but I think that means you wrote the code in a way different than was intended. I did not encounter this problem. Are you sure you specified the axis values correctly? And that you did not include keepdims anywhere?

What is the error you get if you don’t “fix” the inputs in that way?

I tried several variations, but ended up with the version that got me to the point I described. If i then leave out the batch dimension I end up with. that one:
“Invalid reduction dimension (1 for input with 1 dimension(s) [Op:Sum]”
at the point where the I have to reduce the sum of the squared distances for the positive /negative distance calculation.
I did not use keepdims
The axis I took was the 1st, as it would refer to the dimension of the elements in a batch… but that might be it… writing this i recognize, one could also solve it differently. Apparently now I got, how you intended it to be (now that took a while).

Thank you!

I think the problem is the axis: it should be the last axis not the first, right? If you express that as axis = -1, then it works whether the input is 1D or 2D.

Indeed, that was the solution.

Thank you.
Thanks for the great work.