C5W4: Transformers assignment

In Exercise 5 I get the assertion error “Output should be a tensor”. I debugged using print statement after each code block to indicate whether the output is a tensor. It indicated that the output from repeated calls to encoder layers is not a tensor. I also checked the output from encoder layer function (Exercise 4) and the output is a tensor.

Kindly guide me on the error.

Hello Akshay

That’s great that you tried looking for the error solution.

But can we have a screenshot of the error log. Please don’t post any codes.

Thank You
Regards
DP

Please find the error log screenshot

Can you check again into these codes

Scale embedding by multiplying it by the square root of the embedding dimension

Add the position encoding to embedding

Make sure you followed these instructions (especially point 2)

  1. Pass your input through the Embedding layer.
  2. Scale your embedding by multiplying it by the square root of your embedding dimension. Remember to cast the embedding dimension to data type tf.float32 before computing the square root. Did you cast the embedding dimension?
  3. Add the position encoding: self.pos_encoding [:, :seq_len, :] to your embedding.

Your first codes line where you input the encoder output should be tensor from the previous cell

Pass input through the Embedding layer

    x = MAKE SURE TO USE THE RIGHT INPUT

Hello Deepti
So, I found the mistake. We need to index the encoder layer with the iteration variable and then pass the input variable. I didnt do these steps earlier.