# Scales dot product attention

**URL:** <https://community.deeplearning.ai/t/scales-dot-product-attention/14712>\
**Category:** Sequence Models\
**Tags:** coursera-platform\
**Created:** [June 17, 2021, 12:25pm UTC](https://community.deeplearning.ai/t/scales-dot-product-attention/14712 "2021-06-17T12:25:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![isuru](https://avatars.discourse-cdn.com/v4/letter/i/ecb155/32.png) [@isuru](https://community.deeplearning.ai/u/isuru)\
**Post date:** [June 17, 2021, 12:25pm UTC](https://community.deeplearning.ai/t/scales-dot-product-attention/14712/1 "2021-06-17T12:25:49Z")

</div>

in scaled\_dot\_product\_attention\_test(target)  
10 assert np.allclose(weights, [[0.2589478, 0.42693272, 0.15705977, 0.15705977],  
11 [0.2772748, 0.2772748, 0.2772748, 0.16817567],  
—\> 12 [0.33620113, 0.33620113, 0.12368149, 0.2039163]])

I got the error like this please help me I am stuck at this place for 4 hours now  
if mask is not None:  
scaled\_attention\_logits += mask \* -1e9  
is the above statement is write  
please help

I used-\> dk = k.shape[-1]  
scaled\_attention\_logits = matmul\_qk/np.sqrt(dk)

also  
used tf.keras.activations.softmax(scaled\_attention\_logits, axis = dk) to get attention weights

---

<div class="post-metadata">

**Author:** ![MichaelAnderson](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@MichaelAnderson](https://community.deeplearning.ai/u/MichaelAnderson)\
**Post date:** [June 17, 2021, 4:12pm UTC](https://community.deeplearning.ai/t/scales-dot-product-attention/14712/2 "2021-06-17T16:12:34Z")

</div>

Hi @isuru use tf.linalg.matmul for the output, that should fix it

---

<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:** [June 18, 2021, 12:11am UTC](https://community.deeplearning.ai/t/scales-dot-product-attention/14712/3 "2021-06-18T00:11:13Z")

</div>

@isuru  
I do not see any issues there.

Please edit your message and remove your code fragments. Posting your code breaks the Honor Code.
