C4 W4 Face Recognition triplet loss

Hi
I’ve submitted my assignment several times, and I haven’t found any errors. But I get this error code on grader board, which is

Cell #5. Can't compile the student's code. Error: SyntaxError('EOF while scanning triple-quoted string literal', ('/tmp/student_solution_cells/cell_5.py', 37, 1677, '\'\'\'\ntf.random.set_seed(1)\ny_true = (None, None, None) # It is not used\ny_pred = (tf.keras.backend.random_normal([3, 128], mean=6, stddev=0.1, seed = 1),\n          tf.keras.backend.random_normal([3, 128], mean=1, stddev=1, seed = 1),\n          tf.keras.backend.random_normal([3, 128], mean=3, stddev=4, seed = 1))\nloss = triplet_loss(y_true, y_pred)\n\nassert type(loss) == tf.python.framework.ops.EagerTensor, "Use tensorflow functions"\nprint("loss = " + str(loss))\n\ny_pred_perfect = ([1., 1.], [1., 1.], [1., 1.,])\nloss = triplet_loss(y_true, y_pred_perfect, 5)\nassert loss == 5, "Wrong value. Did you add the alpha to basic_loss?"\ny_pred_perfect = ([1., 1.],[1., 1.], [0., 0.,])\nloss = triplet_loss(y_true, y_pred_perfect, 3)\nassert loss == 1., "Wrong value. Check that pos_dist = 0 and neg_dist = 2 in this example"\ny_pred_perfect = ([1., 1.],[0., 0.], [1., 1.,])\nloss = triplet_loss(y_true, y_pred_perfect, 0)\nassert loss == 2., "Wrong value. Check that pos_dist = 2 and neg_dist = 0 in this example"\ny_pred_perfect = ([0., 0.],[0., 0.], [0., 0.,])\nloss = triplet_loss(y_true, y_pred_perfect, -2)\nassert loss == 0, "Wrong value. Are you taking the maximum between basic_loss and 0?"\ny_pred_perfect = ([[1., 0.], [1., 0.]],[[1., 0.], [1., 0.]], [[0., 1.], [0., 1.]])\nloss = triplet_loss(y_true, y_pred_perfect, 3)\nassert loss == 2., "Wrong value. Are you applying tf.reduce_sum to get the loss?"\ny_pred_perfect = ([[1., 1.], [2., 0.]], [[0., 3.], [1., 1.]], [[1., 0.], [0., 1.,]])\nloss = triplet_loss(y_true, y_pred_perfect, 1)\nif (loss == 4.):\n    raise Exception(\'Perhaps you are not using axis=-1 in reduce_sum?\')\nassert loss == 5, "Wrong value. Check your implementation"\n'))

And this is my code and result for triplet_loss function.

{moderator edit - solution code removed}

I don’t know which part cause this kind of error.
Thanks for any feedback!

The code you show looks correct to me. I’m guessing there is something structural wrong with your notebook. Have you downloaded it and modified it with other tools besides the Coursera website?

One thing to try would be to get a clean copy by using the relevant topic on the FAQ Thread. Then very carefully “copy/paste” over just your completed code and then try submitting again.

Thanks for your help! I cleaned it and rewrote the code. then it works well!

That’s great! Glad to hear that you found the solution. Thanks for confirming.