C4W2 - Grading Error

Hi! Is there anyone who can help me? I’m having a grading error.
I passed all the test but my grade is 0.
It said that:
There was a problem compiling the code from your notebook. Details:
Exception encountered when calling layer ‘softmax_3’ (type Softmax).

{{function_node _wrapped__AddV2_device/job:localhost/replica:0/task:0/device:CPU:0}} Incompatible shapes: [1,2,2,150] vs. [1,1,1,2] [Op:AddV2] name:

Call arguments received by layer ‘softmax_3’ (type Softmax):
• inputs=tf.Tensor(shape=(1, 2, 2, 150), dtype=float32)
• mask=tf.Tensor(shape=(1, 1, 1, 2), dtype=float32)

Please help

Passing the tests in the notebook does not prove your code is perfect. The grader uses different tests.

Perhaps your code is using some fixed index value, or a global variable, which the grader’s tests do not provide.

Hi @Sadiah_Safirah

This error indicates that the shape of the mask is not the same as shape of the inputs (in the scaled_dot_product_attention case the inputs are scaled_attention_logits).
So the most probable place to look for a mistake is below the code comment:
# add the mask to the scaled tensor. Here you would calculate the masked “inputs” for the softmax. (The hint suggests:

Reminder: The boolean mask parameter can be passed in as none or as either padding or look-ahead.

  • Multiply (1. - mask) by -1e9 before adding it to the scaled attention logits.

The other probable mistake could be how the softmax is calculated (TensorFlow intricacies…). Are you using:
tf.keras.activations.softmax(..) for the attention_weights computation?

Let me know if you found the problem.

1 Like


I’m having the same trouble on my notebook. I pass all the unit tests and used tf.keras.activations.softmax() for implementing the softmax, but get the following error when trying to use the summarize function. Did @Sadiah_Safirah find a resolution to this error? Thanks!


Oh, sorry, further searching the forum and I found the answer here: C4W2 cannot graded

1 Like