# C5W4 Assignment Exercise 5 - Encoder

**URL:** <https://community.deeplearning.ai/t/c5w4-assignment-exercise-5-encoder/780258>\
**Category:** Sequence Models\
**Tags:** week-module-4, coursera-platform\
**Created:** [March 4, 2025, 8:15pm UTC](https://community.deeplearning.ai/t/c5w4-assignment-exercise-5-encoder/780258 "2025-03-04T20:15:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zaine\_111](https://avatars.discourse-cdn.com/v4/letter/z/82dd89/32.png) [@zaine\_111](https://community.deeplearning.ai/u/zaine_111)\
**Post date:** [March 4, 2025, 8:15pm UTC](https://community.deeplearning.ai/t/c5w4-assignment-exercise-5-encoder/780258/1 "2025-03-04T20:15:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [March 4, 2025, 8:54pm UTC](https://community.deeplearning.ai/t/c5w4-assignment-exercise-5-encoder/780258/2 "2025-03-04T20:54:22Z")

</div>

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.
