# W4a1 unq\_c5 Encoder

**URL:** <https://dlai.staged-by-discourse.com/t/w4a1-unq-c5-encoder/130303>\
**Category:** Sequence Models\
**Tags:** coursera-platform\
**Created:** [May 22, 2022, 11:37am UTC](https://dlai.staged-by-discourse.com/t/w4a1-unq-c5-encoder/130303 "2022-05-22T11:37:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hasan\_Resul\_Cesur](https://avatars.discourse-cdn.com/v4/letter/h/8797f3/32.png) [@Hasan\_Resul\_Cesur](https://dlai.staged-by-discourse.com/u/Hasan_Resul_Cesur)\
**Post date:** [May 22, 2022, 11:37am UTC](https://dlai.staged-by-discourse.com/t/w4a1-unq-c5-encoder/130303/1 "2022-05-22T11:37:52Z")

</div>

Hello,

I am getting “AssertionError: Wrong values case 1” error for this assignment.  
I passed the UNQ\_C4 assignment.  
I applied the square root of the embedding dimension, self.pos\_encoding `[:, :seq_len, :]` and training for dropout.  
There is nothing to code aside from these.

What could be the reason, could you please help ?

---

<div class="post-metadata">

**Author:** ![Elemento](https://sea1.discourse-cdn.com/dlaistaging/user_avatar/dlai.staged-by-discourse.com/elemento/32/854_2.png) [@Elemento](https://dlai.staged-by-discourse.com/u/Elemento)\
**Post date:** [May 22, 2022, 12:44pm UTC](https://dlai.staged-by-discourse.com/t/w4a1-unq-c5-encoder/130303/2 "2022-05-22T12:44:03Z")

</div>

Hey @Hasan_Resul_Cesur,  
Welcome to the community. It’s hard to find the exact issue without taking an exact look at your code for the `Encoder` class. Additionally, it might be possible that your first 4 functions have passed the test cases, but still might have an error. A common issue could be to use the global variables inside the functions at places where they are not intended to, or to hard-code some variables to pass the corresponding test cases.

Can you please DM me your code so that I can find the exact issue? Make sure to not post it publicly since it is strictly against the community guidelines. Just click on my name, and select “Message”.

Regards,  
Elemento

---

<div class="post-metadata">

**Author:** ![Hasan\_Resul\_Cesur](https://avatars.discourse-cdn.com/v4/letter/h/8797f3/32.png) [@Hasan\_Resul\_Cesur](https://dlai.staged-by-discourse.com/u/Hasan_Resul_Cesur)\
**Post date:** [May 22, 2022, 3:52pm UTC](https://dlai.staged-by-discourse.com/t/w4a1-unq-c5-encoder/130303/3 "2022-05-22T15:52:22Z")

</div>

Hello,

I found the problem.  
“self.enc\_layers” definition inside the “ **init** ” part is a list comprehension. I thought it’s a fixed size list. So the problem was with the indexing while using “self.enc\_layers” later on.

Thank you @Elemento for your consideration and help.

---

<div class="post-metadata">

**Author:** ![Elemento](https://sea1.discourse-cdn.com/dlaistaging/user_avatar/dlai.staged-by-discourse.com/elemento/32/854_2.png) [@Elemento](https://dlai.staged-by-discourse.com/u/Elemento)\
**Post date:** [May 23, 2022, 5:06am UTC](https://dlai.staged-by-discourse.com/t/w4a1-unq-c5-encoder/130303/4 "2022-05-23T05:06:01Z")

</div>

Hey @Hasan_Resul_Cesur,  
I am glad you were able to find the issue.

Regards,  
Elemento

---

<div class="post-metadata">

**Author:** ![sergio\_cr](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@sergio\_cr](https://dlai.staged-by-discourse.com/u/sergio_cr)\
**Post date:** [April 7, 2025, 1:23am UTC](https://dlai.staged-by-discourse.com/t/w4a1-unq-c5-encoder/130303/5 "2025-04-07T01:23:48Z")

</div>

Hi everyone,

I’m stumped with this one. I’m trying to use i to index through x but clearly that is not right. I picked up on the tip that `self.enc_layers` are a ListWrapper and that we’d be using the objects inside the list inside the wrapper. I’m trying to understand what you mean by the problem being with 'the indexing while using `self.enc_layers` later on '.

Another post also suggested looking at the `Enconder_test` function in public tests for clues but I haven’t been able to see the pattern.

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlaistaging/user_avatar/dlai.staged-by-discourse.com/tmosh/32/9321_2.png) [@TMosh](https://dlai.staged-by-discourse.com/u/TMosh)\
**Post date:** [April 7, 2025, 11:40pm UTC](https://dlai.staged-by-discourse.com/t/w4a1-unq-c5-encoder/130303/6 "2025-04-07T23:40:32Z")

</div>

Indexing through ‘x’ is not correct.  
Use ‘i’ to index through the layers via `self.enc_layers[i](...)`, where you keep overwriting the ‘x’ value after you pass it to the Encoder layer.

---

<div class="post-metadata">

**Author:** ![sergio\_cr](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@sergio\_cr](https://dlai.staged-by-discourse.com/u/sergio_cr)\
**Post date:** [April 8, 2025, 3:51am UTC](https://dlai.staged-by-discourse.com/t/w4a1-unq-c5-encoder/130303/7 "2025-04-08T03:51:23Z")

</div>

Thanks TMosh, I found out my mistake was during scale embedding by multiplying it by the square root of the embedding dimension. I was repeating the multiplication and ignoring `*=`. I misspoke but I meant exactly what you wrote for slicing through `self.enc_layers` using `i`.
