# Encoder Layer Mask Purpose

**URL:** <https://community.deeplearning.ai/t/encoder-layer-mask-purpose/126162>\
**Category:** Sequence Models\
**Tags:** coursera-platform\
**Created:** [May 8, 2022, 5:11pm UTC](https://community.deeplearning.ai/t/encoder-layer-mask-purpose/126162 "2022-05-08T17:11:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anbu](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@Anbu](https://community.deeplearning.ai/u/Anbu)\
**Post date:** [May 8, 2022, 5:11pm UTC](https://community.deeplearning.ai/t/encoder-layer-mask-purpose/126162/1 "2022-05-08T17:11:10Z")

</div>

Dear Mentor,

Why do we need to pass mask to the encoder layer class ?

---

<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:** [May 9, 2022, 6:20am UTC](https://community.deeplearning.ai/t/encoder-layer-mask-purpose/126162/2 "2022-05-09T06:20:55Z")

</div>

Are you referring to Course 5 Week 4 Assignment 1?

---

<div class="post-metadata">

**Author:** ![Anbu](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@Anbu](https://community.deeplearning.ai/u/Anbu)\
**Post date:** [May 9, 2022, 12:26pm UTC](https://community.deeplearning.ai/t/encoder-layer-mask-purpose/126162/3 "2022-05-09T12:26:44Z")

</div>

Yes sir, why mask need to be pass to the encoder layer ?

---

<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:** [May 10, 2022, 1:04am UTC](https://community.deeplearning.ai/t/encoder-layer-mask-purpose/126162/4 "2022-05-10T01:04:41Z")

</div>

I don’t think it is really necessary. Certainly the reference paper doesn’t use a mask during encoding.

---

<div class="post-metadata">

**Author:** ![Anbu](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@Anbu](https://community.deeplearning.ai/u/Anbu)\
**Post date:** [May 10, 2022, 5:05pm UTC](https://community.deeplearning.ai/t/encoder-layer-mask-purpose/126162/5 "2022-05-10T17:05:51Z")

</div>

Thank You sir.

Also one more doubt why are we passing Query = Value = Key = X ? Why we are not doing this query = W \* X , value = W \* X, key = W \* X

---

<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:** [May 10, 2022, 8:55pm UTC](https://community.deeplearning.ai/t/encoder-layer-mask-purpose/126162/6 "2022-05-10T20:55:24Z")

</div>

I believe the weight product happens inside the Embedding layer.

---

<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:** [May 11, 2022, 2:57pm UTC](https://community.deeplearning.ai/t/encoder-layer-mask-purpose/126162/7 "2022-05-11T14:57:32Z")

</div>

The MHA documentation says that for self-attention, the input data X is used for Q, K, and V.
