Course 5 Week 4 Assignment 1 Positional Encoding

The instructions for the assignment for Course 5 Week 4 Assignment 1 (on Transformer Architecture) is kind of ambiguous. I am not able to understand from given instructions that how can I take “sin” of all the values that are even and “cos” of all the values that are odd when get_angles() takes three arguments (out of which k is not given)
The snippet is as below:

apply sin to even indices in the array; 2i

angle_rads[:, 0::2] = *********

Let me explain this: [:, 0::2]

  1. : means "select all elements of rows
  2. 0::2, this part is used for selecting specific elements in columns
  • The 0 specifies the starting index.
  • The 2 specifies the step size. It means that the selection will skip one element for every two elements.

In the assignment, you have:

# apply sin to even indices in the array; 2i
angle_rads[:, 0::2] = None
  
# apply cos to odd indices in the array; 2i+1
angle_rads[:, 1::2] = None

You just need to replace the None with the correct terms. Use np.sin or np.cos and pass the (what is in the left hand side to the None) to it.

I am stuck at Exercise 5 now. I understand that the output of dropout layer is to be passed on to the encoder layer but the encoder layer is a collection of layer and when I am calling self.enc_layers with X as input, it is throwing an error : List object is not callable.

I understand that it means that I cant use “()” to put x inside. However, it is not working with as well and there is no other layer that I can use to call in the box. I am using below in the for loop:
x = self.enc_layers(x)

You have this comment before the code:
# Pass the output through the stack of encoding layers

I think this is not a clear guide. Instead, read this:
# Pass the output through the stack of encoding layers by passing it through the i-th encoder layer function along with the training and mask.

Please let me know if it doesn’t help.