Course5 Week4 Exercise 2

I am stuck with this, especially the dimensions of the angle_rads

To initialize the matrix for angle_rads, and how to solve for the sin part and cosine part.
I am looking for the sine and cosine of the angle_rads variable and that gives me the error above.
Someone should help point me in the right direction please

First thing to check:
In the positional_encoding() function, there is a trick for the np.sin() and np.cos() calls.
You have to use exactly the same “angle_rads[…]” arguments from the left side of the = sign in the sin and cos calls.
This is because sin is only applied to the even-numbered elements, and cos is applied to the odd-numbered elements.

2 Likes

Thanks, that did the trick for me

Also, computing the angle_rads values is bizarrely complicated and non-obvious, using np.arange() and np.newaxis. We’ll check that next if necessary.

3 Likes

Thanks, @TMosh can you tell me what I am doing wrong here?

{mentor edit: code removed- not allowed by the course Honor Code}

1 Like

can u help me. i m not getting what to take the value of i in
angle_rads = get_angles( position, ?, d).

{mentor edit: code removed - not allowed by the course Honor Code}

I m getting an error-
outpu

@ankit_singh: Passing the value ‘1’ to get_angles() is not correct. You need to write some code to compute the correct number of dimensions.

@karimkhan123: You have hard-coded some values for postition and d_model. That is a big mistake.