Error positional_encoding

image
code for me : angle_rads = get_angles(np.arange(positions)[:, np.newaxis],
np.arange(d)[np.newaxis, :],
d)
# apply sin to even indices in the array; 2i
angle_rads[:, 0::2] = np.sin(angle_rads)

# apply cos to odd indices in the array; 2i+1
angle_rads[:, 1::2] = np.cos(angle_rads)
# END CODE HERE

Why are they not working please help me. I spent a long time but no results.

Hi, shouldn’t it be
angle_rads[:, 0::2] = np.sin(angle_rads[:, 0::2])
angle_rads[:, 1::2] = np.cos(angle_rads[:, 1::2])
instead?

Have you passed the exercise above it? exercise 1 get_angles?
I have the code:
angles = pos / np.power(10000, 2*i/d)
and it fails the tests… could you help me there? Thanks!

5 Likes

Above code gives this error:

AssertionError Traceback (most recent call last)
in
29
30
—> 31 positional_encoding_test(positional_encoding)

in positional_encoding_test(target)
24 trueAngs = get_angles(pos_m, dims, d_model)[:, 0::2] % (2 * np.pi)
25
—> 26 assert np.allclose(angs[0], trueAngs), “Did you apply sin and cos to even and odd parts respectively?”
27
28 print("\033[92mAll tests passed")

AssertionError: Did you apply sin and cos to even and odd parts respectively?

For exercise 1 get_angles, the code should be:

angles = pos / (10000 ** ((2*(i//2))/d))

1 Like

thank , I had overcome it

What was wrong? I’m still stuck on that part :frowning:

Hi @SKim20,

Here and here some information that may be useful.

Can you share it with us

How? can u share with us ?

Here you can find a solution with fairly enough explanation
get_angles()