W4 Assignment 1, tripplet_loss() instructions are confusing

I followed the instructions and hints, as confusing as they were, and no matter what I try, I get the following error: “AssertionError: Wrong value. Did you add the alpha to basic_loss?”

Here are the steps I followed:

  1. pos_dist = reduce_sum of square of differences between anchor and positive encondings along the last axis (-1)
  2. neg_dist = reduce_sum of square of differences between anchor and negative encondings along the last axis (-1)
  3. basic_loss = add alpha to the difference between pos_dist and neg_dist (NO REDUCE_SUM)
  4. loss = the max of 0.0 and the reduce_sum of basic_loss along the first axis (0)

I have no more brain cells left to fix this!!!

Step 4 is: select the maximum from basic_loss and 0 and then apply the reduce_sum so the resulting loss is a scalar value.

I flipped it around, but the result is exactly the same. When I debug, the loss within the function is:
tf.Tensor(10.0, shape=(), dtype=float32)

I checked a million times that the axis in steps 1 and 2 is -1 and that the axis in step 4 is 0. What else is there to do?

what does this mean in step 3: “Compute the formula per training example”; I thought that there was no reduce_sum in step 3

Can someone rewrite the steps for the exercise in a way that makes sense? This is so unclear and frustrating!!!

Your step 1, 2, and 3 seems correct to me but double-check step 4. Flipping the input parameters of max function doesn’t make any difference as it will select a max value. But you have to use max and reduce_sum, both in step 4.

The max of 0.0 and basic_loss, and then do reduce_sum.

I didn’t mean flip parameters within max, I meant flip max() and reduce_sum().

I wrote step 4 exactly as you described, and still getting the same exact issue.

I have a couple of questions:

  1. do we use axis=-1 for steps 1 and 2?
  2. is there a reduce_sum() in step 3?
  3. do we use axis=0 for step 4?

We’re supposed to do step 4 in a single line, so I wrote it as:
loss = the reduce_sum of the max of 0.0 and basic_loss along the first axis (0)

I keep getting a loss of 10 instead of a loss of 5. Where else could be the problem?

  1. Yes
  2. No
  3. No

Hint for step 4:

  • For tf.reduce_sum to sum across all axes, keep the default value axis=None.

Let me make it easier for you: First, use reduce_sum and inside it, use maximum and pass the basic_loss and 0.0 as parameters to the maximum.

If still getting an error, send me your code in a private message. Click my name and message.

I figured out the error was in step 3, I was using positive and negative instead of pos_dist and neg_dist. I spent all the time on the other steps without revisiting this one. Thanks for the assist!

I am glad you figured it out on your own.