C5W4 Assignment Exercise 5 - Encoder

I’m getting the Assertion error below. I completed the following steps:

  1. pass x through the embedding layer using self.embedding(x)
  2. Scale x by using *= tf.math.sqrt() (using tf.cast() on self.embedding_dim
  3. Add the PE as directed in the instructions
  4. For the dropout layer I used self.dropout() with training=training
  5. In the for … loop I called self.enc_layers[i]

But I’m getting this error:
AssertionError Traceback (most recent call last)
in
1 # UNIT TEST
----> 2 Encoder_test(Encoder)

~/work/W4A1/public_tests.py in Encoder_test(target)
116 encoderq_output = encoderq(x, True, None)
117
→ 118 assert tf.is_tensor(encoderq_output), “Wrong type. Output must be a tensor”
119 assert tuple(tf.shape(encoderq_output).numpy()) == (x.shape[0], x.shape[1], embedding_dim), f"Wrong shape. We expected ({x.shape[0]}, {x.shape[1]}, {embedding_dim})"
120 assert np.allclose(encoderq_output.numpy(),

AssertionError: Wrong type. Output must be a tensor

Note that the error could be in either your Encoder() class, or in your EncoderLayer() class.

The EncoderLayer_test() does not catch all possible issues.

If you open the public_tests.py file, you can find the Encoder_test() function. This will help you identify the conditions where your code does not work correctly.