I am having the error

AssertionError Traceback (most recent call last)

in

1 # UNIT TEST

----> 2 positional_encoding_test(positional_encoding, get_angles)

~/work/W4A1/public_tests.py in positional_encoding_test(target, get_angles)

31

32 assert tf.is_tensor(pos_encoding), “Output is not a tensor”

—> 33 assert pos_encoding.shape == (1, position, d_model), f"Wrong shape. We expected: (1, {position}, {d_model})"

34

35 ones = sin_part ** 2 + cos_part ** 2

AssertionError: Wrong shape. We expected: (1, 8, 16)

I dont understand how do I solve this

It is a mistake to file this under “General Discussion”. This Discourse instance supports at least 4 different specializations at this point, with more being added frequently. Which specialization and which course are you referring to as Week4 here? I’m guessing it’s DLS Course 5. I’ll use the “edit pencil” icon on the title to move it for you.

I’m not familiar with this particular assignment, but anytime you get a shape mismatch, the first question you need to answer is “Well, what shape is it?” Then “How did it get that way?”

Hi!

I think your problem is due to passing wrong arguments to the “get_angles” function inside the “positional_encoding” function. Particularly, this type of error is a result of passing the input argument *position* directly into the “get_angle”.

If you feel confused about how to produce the proper input arguments, considering the test cell from exercise 1 (the last code cell before the implementation of positional_encoding) will hopefully help.

2 Likes

Yes they should make sure to pass on the positions as a column vector containing the positions [[0], [1], …,[N-1]]. Hint: get_angles function (see the arguments of that function)