# C4W2 Decoder passes all ex3 test but throws an error in Transformer ex4 (positional encoding)

**URL:** <https://community.deeplearning.ai/t/c4w2-decoder-passes-all-ex3-test-but-throws-an-error-in-transformer-ex4-positional-encoding/588334>\
**Category:** NLP with Attention Models\
**Tags:** week-module-2\
**Created:** [March 11, 2024, 9:43am UTC](https://community.deeplearning.ai/t/c4w2-decoder-passes-all-ex3-test-but-throws-an-error-in-transformer-ex4-positional-encoding/588334 "2024-03-11T09:43:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Onema](https://avatars.discourse-cdn.com/v4/letter/o/48db29/32.png) [@Onema](https://community.deeplearning.ai/u/Onema)\
**Post date:** [March 11, 2024, 9:43am UTC](https://community.deeplearning.ai/t/c4w2-decoder-passes-all-ex3-test-but-throws-an-error-in-transformer-ex4-positional-encoding/588334/1 "2024-03-11T09:43:57Z")

</div>

As in the subject line, my implementation of the decoder passed all tests for exercise 3, but the line with positional encoding causes an error in Transformer in exercise 4.

Any help will be very much appreciated, I have no clue what might have gone wrong.

 ![error](https://global.discourse-cdn.com/dlai/original/3X/d/1/d1fce42a1d65778b8fb25c8ec3a07473ec7710f7.jpeg)

---

<div class="post-metadata">

**Author:** ![gent.spah](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/gent.spah/32/136423_2.png) [@gent.spah](https://community.deeplearning.ai/u/gent.spah)\
**Post date:** [March 11, 2024, 11:21am UTC](https://community.deeplearning.ai/t/c4w2-decoder-passes-all-ex3-test-but-throws-an-error-in-transformer-ex4-positional-encoding/588334/2 "2024-03-11T11:21:44Z")

</div>

How are you finding seq\_len?

---

<div class="post-metadata">

**Author:** ![Onema](https://avatars.discourse-cdn.com/v4/letter/o/48db29/32.png) [@Onema](https://community.deeplearning.ai/u/Onema)\
**Post date:** [March 11, 2024, 11:43am UTC](https://community.deeplearning.ai/t/c4w2-decoder-passes-all-ex3-test-but-throws-an-error-in-transformer-ex4-positional-encoding/588334/3 "2024-03-11T11:43:27Z")

</div>

seq\_len = tf.shape(x)[1]

This is a line from the provided code (before the START CODE HERE annotation), I didn’t change anything.

---

<div class="post-metadata">

**Author:** ![Onema](https://avatars.discourse-cdn.com/v4/letter/o/48db29/32.png) [@Onema](https://community.deeplearning.ai/u/Onema)\
**Post date:** [March 13, 2024, 1:08pm UTC](https://community.deeplearning.ai/t/c4w2-decoder-passes-all-ex3-test-but-throws-an-error-in-transformer-ex4-positional-encoding/588334/4 "2024-03-13T13:08:25Z")

</div>

Could someone please try to help? It’s really frustrating, I’ve been stuck with the issue and don’t have a clue why the decoder worked in the tests but fails in another exercise… I’d be really grateful for any hint.
