C3W2 Assigment : Grading Error with Exercice 4 Masked Loss - Expected output OK & All tests passed

Hi everyone,

Once again, there seems to be an issue with the grading system for Exercise 4: Masked Loss. Here’s what’s happening:

  • I get the expected output and all the tests passed successfully:

    Expected Output:

    tf.Tensor(1.1242604, shape=(), dtype=float32)
    
  • After running the test:

    w2_unittest.test_masked_loss(masked_loss)
    

    I get: All tests passed.

However, the grading system still gives me 0/10, and I see the following error:

Error from the grader:

There was an error grading your submission. Details:
{{function_node __wrapped__SparseSoftmaxCrossEntropyWithLogits_device_/job:localhost/replica:0/task:0/device:CPU:0}} Received a label value of -1 which is outside the valid range of [0, 17).  
Label values: 9 10 15 15 9 9 9 9 9 9 9 9 9 9 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
[Op:SparseSoftmaxCrossEntropyWithLogits] name:

I’ve double-checked my implementation, and I don’t understand what’s wrong. All the tests pass, and I get the expected output.

To troubleshoot, I tried the Save + Restart & Clear Output procedure, but unfortunately, this didn’t resolve the issue.

I scored 10/10 on all other exercises, but because of this issue, my final grade is 83.33% instead of 100%. While I passed the assignment, this is very frustrating.

Is anyone else experiencing the same issue? Any guidance on how to fix or report this would be greatly appreciated!

Thanks!

hi @Christophe_Lancien

while
Calculate the loss for each item in the batch. Remember to pass the right arguments, as discussed above!
loss_fn

Did you miss the ignore_class instructions

ignore_class: This indicates which class should be ignored when computing the crossentropy. Remember that the class related to padding value is set to be 0.

The below instruction should help you what ignore_class you need to use

Instructions: You will use a tf.keras.losses.SparseCategoricalCrossentropy object to create a loss function that ignores the padded value related to the label. Remember that for padding you are using the value -1 and not 0, as opposed to the text padding!

this should resolve your issue as your grade states it doesn’t want -1 label value to be seen, you need to ignore -1 class labels.

1 Like

Hi @Deepti_Prasad

Thank you so much ! Your explanation was spot on. I realized I had overlooked the ignore_class instructions where the padded value of -1 needed to be explicitly ignored in the loss function.

After updating my code to account for the correct ignore_class, everything works perfectly now, and I’ve finally achieved 100% on the assignment.

Interestingly, the output of Exercise 6 is now perfect, even though it already passed before.

However, I still believe the unit test for Exercise 4 should have failed if such an error existed in my implementation. This was quite confusing and led to unnecessary frustration.

Thanks again for the clarification, and I hope this post helps others avoid the same mistake! :blush:

1 Like

I just checked the unittest and it does shows an error for passing incorrect label class for -1. perhaps you needed to fresh or update the lab for that unittest to fail.

Still tagging @lucas.coutinho to check upon again. hey Lucas can you confirm if the unittest was checked upon to fail if the label class were passed on for label_class -1?

happy that you solved your issue with the hint.

Keep learning!!!

1 Like

@Deepti_Prasad,

Thank you for checking! I truly appreciate your follow-up and the help you’ve provided.

I’m fairly confident that the unittest does not test whether the label class -1 is correctly ignored. To confirm this, I can share my previous code (with the mistake) where I didn’t handle the ignore_class properly. Despite this, the unittest still passed without any errors, which led to my confusion.

I believe this could be worth investigating further to ensure the unittest properly flags such issues, as it would save others from similar frustration in the future.

Thank you again for your support and encouragement!

1 Like

Thanks @Deepti_Prasad,

Sorry for the late response. I’m right now investigating it, I remember fixing it in some recent time ago. I’ll let you guys know soon about what is going on.

1 Like