C5W4: AssertionError: Wrong masked weights

I am working on the last week’s assignment in course5 and implementing function scaled_dot_product_attention(q, k, v, mask). However I get error while testing this function. Below is my code.

def scaled_dot_product_attention(q, k, v, mask):

    # mentor edit: code removed

    return output, attention_weights

The error I get is,

AssertionError                            Traceback (most recent call last)
<ipython-input-46-00665b20febb> in <module>
      1 # UNIT TEST
----> 2 scaled_dot_product_attention_test(scaled_dot_product_attention)

~/work/W4A1/public_tests.py in scaled_dot_product_attention_test(target)
     73     assert np.allclose(weights, [[0.30719590187072754, 0.5064803957939148, 0.0, 0.18632373213768005],
     74                                  [0.3836517333984375, 0.3836517333984375, 0.0, 0.2326965481042862],
---> 75                                  [0.3836517333984375, 0.3836517333984375, 0.0, 0.2326965481042862]]), "Wrong masked weights"
     76     assert np.allclose(attention, [[0.6928040981292725, 0.18632373213768005],
     77                                    [0.6163482666015625, 0.2326965481042862],

AssertionError: Wrong masked weights

I don’t understand what is the mistake I am doing. Tried using different ways but still I get the same error. Can someone please help.

Read the instructions again for using the mask. You need to subtract it from 1.


Thank you. I was actually looking at the formula and trying to replicate it and later tried with code from tensorflow doc which didn’t workout.

Do not pay much attention to the TensorFlow tutorials. The programming assignments do not follow them.