W4 A1: initialization problem in positional_encoding()

I’m totally stuck with this exercise.

I’m initializing angle_rads with this:

angle_rads = get_angles(np.arange(position)[:, np.newaxis], np.arange(d)[np.newaxis, :], d)

and get 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)

My shape is (1, 4, 16)

I read through the many posts concerning ths problem, but I don’t get it what is wrong.
Any help is appreciated.

1 Like

Unfortunately, there is a global variable, “position”.
On the other hand, a parameter passed is “positions”. So, this must refer a global variable…

2 Likes

I stared too long on the screen to spot it. Thanks a lot!