Week 4 Assignment - Implementation of the positional_encoding function

Hi everyone.

I cannot figure out what I am supposed to do in the ** Exercise 2 - positional_encoding** of the Week 4 Assignment. The get_angles() function takes in three arguments pos, i and d, however, in the positional_encoding() function, only two of them, positions and d, are present. Any thought on how this function call should be made?

1 Like

Hello!

Please just have a look at the code cells 3 (unit tests for get_angles function). In the end, you can find example usage of the code there which might be useful for you.

3 Likes

Could you please explain a little more? :pleading_face: I can see how the even_col and odd_col would probably be useful …

There is an example in the cell. You can find the usage of the get_angles function there. The code is following (I just copied the text from the cell, so that you can find the cell if needed).

I hope it can help you to use the get_angle function properly! :slight_smile:

Example

position = 4
d_model = 8
pos_m = np.arange(position)[:, np.newaxis]
dims = np.arange(d_model)[np.newaxis, :]
get_angles(pos_m, dims, d_model)

14 Likes

I have one thing to add to jiri.palek’s answer. (Thank you very much, by the way, for your answer, jiri.palek, it helped me a lot!)

Have a look at the dimensions of the vectors pos and k provided in the beginning of the function get_angles. k has d entries in it and pos has N entries in it. This is the reason we have only two arguments in the function positional_enconding. The argument positions equals to N and we can use it to specify the pos argument in the get_angles function. The argument d can be used to specify both the i argument in the get_angles function (i can be expressed through k and k has d entries) and the d argument in the get_angles function.