# Scaled\_dot\_product\_attention C5W4

**URL:** <https://community.deeplearning.ai/t/scaled-dot-product-attention-c5w4/40320>\
**Category:** Sequence Models\
**Tags:** coursera-platform\
**Created:** [September 21, 2021, 2:03pm UTC](https://community.deeplearning.ai/t/scaled-dot-product-attention-c5w4/40320 "2021-09-21T14:03:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JFREZ](https://avatars.discourse-cdn.com/v4/letter/j/b782af/32.png) [@JFREZ](https://community.deeplearning.ai/u/JFREZ)\
**Post date:** [September 21, 2021, 2:03pm UTC](https://community.deeplearning.ai/t/scaled-dot-product-attention-c5w4/40320/1 "2021-09-21T14:03:23Z")

</div>

Sorry but I have been stuck for a week here and ai already read a lot of posts about this function but i still stuck.

I can’t get the right weights

Mentor edit, description of code removed.

* * *

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:** ![JFREZ](https://avatars.discourse-cdn.com/v4/letter/j/b782af/32.png) [@JFREZ](https://community.deeplearning.ai/u/JFREZ)\
**Post date:** [September 21, 2021, 2:09pm UTC](https://community.deeplearning.ai/t/scaled-dot-product-attention-c5w4/40320/2 "2021-09-21T14:09:46Z")

</div>

Solved using (1.0-mask)\*-1e9

---

<div class="post-metadata">

**Author:** ![reinoudbosch](https://avatars.discourse-cdn.com/v4/letter/r/22d042/32.png) [@reinoudbosch](https://community.deeplearning.ai/u/reinoudbosch)\
**Post date:** [September 29, 2021, 1:33pm UTC](https://community.deeplearning.ai/t/scaled-dot-product-attention-c5w4/40320/3 "2021-09-29T13:33:02Z")

</div>


