# C5W4 Programming Ass UNQ\_C3

**URL:** <https://community.deeplearning.ai/t/c5w4-programming-ass-unq-c3/25458>\
**Category:** Sequence Models\
**Tags:** coursera-platform\
**Created:** [August 6, 2021, 1:16am UTC](https://community.deeplearning.ai/t/c5w4-programming-ass-unq-c3/25458 "2021-08-06T01:16:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![walrus](https://avatars.discourse-cdn.com/v4/letter/w/51bf81/32.png) [@walrus](https://community.deeplearning.ai/u/walrus)\
**Post date:** [August 6, 2021, 1:16am UTC](https://community.deeplearning.ai/t/c5w4-programming-ass-unq-c3/25458/1 "2021-08-06T01:16:40Z")

</div>

I’m stuck. Can’t find the problem. I’m applying the mask and -1e9 when computing the scaled\_attention\_logits. I don’t understand why it is += instead of multiplication. Keep getting the following error.

I’m using tf.nn.softmax to compute attention\_weights on the scaled\_attention\_logits, axis = 1.

* * *

AssertionError Traceback (most recent call last)  
 in   
1 # UNIT TEST  
----\> 2 scaled\_dot\_product\_attention\_test(scaled\_dot\_product\_attention)

~/work/W4A1/public\_tests.py in scaled\_dot\_product\_attention\_test(target)  
73 assert np.allclose(weights, [[0.30719590187072754, 0.5064803957939148, 0.0, 0.18632373213768005],  
74 [0.3836517333984375, 0.3836517333984375, 0.0, 0.2326965481042862],  
—\> 75 [0.3836517333984375, 0.3836517333984375, 0.0, 0.2326965481042862]]), “Wrong masked weights”  
76 assert np.allclose(attention, [[0.6928040981292725, 0.18632373213768005],  
77 [0.6163482666015625, 0.2326965481042862],

AssertionError: Wrong masked weights

---

<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:** [August 6, 2021, 1:52am UTC](https://community.deeplearning.ai/t/c5w4-programming-ass-unq-c3/25458/2 "2021-08-06T01:52:09Z")

</div>

Did you read this part of the instructions carefully?

 ![image](https://global.discourse-cdn.com/dlai/original/2X/3/3ea8e9249d50e7cadbd38aa9c44ed6e183c41643.png)

---

<div class="post-metadata">

**Author:** ![walrus](https://avatars.discourse-cdn.com/v4/letter/w/51bf81/32.png) [@walrus](https://community.deeplearning.ai/u/walrus)\
**Post date:** [August 6, 2021, 2:41am UTC](https://community.deeplearning.ai/t/c5w4-programming-ass-unq-c3/25458/3 "2021-08-06T02:41:06Z")

</div>

I read, multiple them, so I have the following

(1.-mask) \* -1e9

---

<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:** [August 6, 2021, 2:51am UTC](https://community.deeplearning.ai/t/c5w4-programming-ass-unq-c3/25458/4 "2021-08-06T02:51:02Z")

</div>

> [@walrus](#):
>
> I’m using tf.nn.softmax to compute attention\_weights

Try using tf.keras.activations.softmax(…) instead. You don’t need an “axis” argument.

---

<div class="post-metadata">

**Author:** ![walrus](https://avatars.discourse-cdn.com/v4/letter/w/51bf81/32.png) [@walrus](https://community.deeplearning.ai/u/walrus)\
**Post date:** [August 6, 2021, 3:50am UTC](https://community.deeplearning.ai/t/c5w4-programming-ass-unq-c3/25458/5 "2021-08-06T03:50:54Z")

</div>

wow! so I don’t need an axis, that solved it, thank you!

---

<div class="post-metadata">

**Author:** ![walrus](https://avatars.discourse-cdn.com/v4/letter/w/51bf81/32.png) [@walrus](https://community.deeplearning.ai/u/walrus)\
**Post date:** [August 6, 2021, 3:52am UTC](https://community.deeplearning.ai/t/c5w4-programming-ass-unq-c3/25458/6 "2021-08-06T03:52:13Z")

</div>

Why is axis a problem here?

---

<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:** [August 6, 2021, 6:27am UTC](https://community.deeplearning.ai/t/c5w4-programming-ass-unq-c3/25458/7 "2021-08-06T06:27:43Z")

</div>

If you’re going to specify an axis, you need to be sure it’s the correct one.  
In this case, the default axis is the correct one.

---

<div class="post-metadata">

**Author:** ![wayne9598](https://avatars.discourse-cdn.com/v4/letter/w/c0e974/32.png) [@wayne9598](https://community.deeplearning.ai/u/wayne9598)\
**Post date:** [August 6, 2021, 3:08pm UTC](https://community.deeplearning.ai/t/c5w4-programming-ass-unq-c3/25458/8 "2021-08-06T15:08:13Z")

</div>

what does this:

Multiply (1. - mask) by -1e9 before applying the softmax.

even mean??

---

<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:** [February 24, 2024, 7:42am UTC](https://community.deeplearning.ai/t/c5w4-programming-ass-unq-c3/25458/9 "2024-02-24T07:42:15Z")

</div>

Closed on February 24, 2024, 7:42am UTC


