C5 W4 UNQ_C7 Decoder

I have been getting this error :


AssertionError Traceback (most recent call last)
in
1 # UNIT TEST
----> 2 Decoder_test(Decoder, create_look_ahead_mask, create_padding_mask)

~/work/W4A1/public_tests.py in Decoder_test(target, create_look_ahead_mask, create_padding_mask)
226 assert type(att_weights) == dict, “Wrong type for att_weights[0]. Output must be a tensor”
227 assert len(keys) == 2 * num_layers, f"Wrong length for attention weights. It must be 2 x num_layers = {2*num_layers}"
→ 228 assert tf.is_tensor(att_weights[keys[0]]), f"Wrong type for att_weights[{keys[0]}]. Output must be a tensor"
229 shape1 = (x.shape[0], num_heads, x.shape[1], x.shape[1])
230 assert tuple(tf.shape(att_weights[keys[1]]).numpy()) == shape1, f"Wrong shape. We expected {shape1}"

AssertionError: Wrong type for att_weights[decoder_layer1_block1_self_att]. Output must be a tensor


I’m pretty sure my code for UNQ_C7 is correct, but I cant find out if anything is wrong with my code for UNQ_C6 since it passes all tests

Passing the unit tests is no guarantee that your code is perfect.

Yeah! I figured that much. I’m browsing some threads and reading all my codes again for the last hours and I cant seen to find where its wrong. Thought I would give a shot posting my error.

“wrong type” should be easy to spot. Check if you used a numpy function somewhere instead of the equivalent tensorflow function.

Yes, I checked that out too. Only used numpy in the positional encoding function (arange, newaxis) and to get the sqrt of the dimension of keys (Exercise 3). Been checking everythings types and all objects that matter to the Decoder function are tensors

In scaled_dot_product_attenation, did you use tf.matmul(…)?
That returns a tensor.
If you used a matrix product, you would not have a tensor.

Yes ! And I checked that both my outputs are tensors

Sorry Sir, actually just sent you my entire code up until this exercise, if you have some time to check it out it would help a lot…