# C5W4A1 Attention(Q,K,V) why we use matmul not dot product

**URL:** <https://community.deeplearning.ai/t/c5w4a1-attention-q-k-v-why-we-use-matmul-not-dot-product/598491>\
**Category:** Sequence Models\
**Tags:** week-module-4, coursera-platform\
**Created:** [March 26, 2024, 1:27am UTC](https://community.deeplearning.ai/t/c5w4a1-attention-q-k-v-why-we-use-matmul-not-dot-product/598491 "2024-03-26T01:27:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Chen1](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Daniel\_Chen1](https://community.deeplearning.ai/u/Daniel_Chen1)\
**Post date:** [March 26, 2024, 1:27am UTC](https://community.deeplearning.ai/t/c5w4a1-attention-q-k-v-why-we-use-matmul-not-dot-product/598491/1 "2024-03-26T01:27:48Z")

</div>

C5W4A1 Why attention formula in a transformer assignment formula (4) in the assignment means to use matmul instead of dot product? Isn’t matmul usually indicated by \* and without it means dot product?

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [March 26, 2024, 2:03am UTC](https://community.deeplearning.ai/t/c5w4a1-attention-q-k-v-why-we-use-matmul-not-dot-product/598491/2 "2024-03-26T02:03:36Z")

</div>

No, both `tf.matmul` and `np.matmul` are dot product style multiply.

---

<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:** [March 26, 2024, 2:05am UTC](https://community.deeplearning.ai/t/c5w4a1-attention-q-k-v-why-we-use-matmul-not-dot-product/598491/3 "2024-03-26T02:05:38Z")

</div>

Np.multiply is element-wise, and equivalent to \*.

---

<div class="post-metadata">

**Author:** ![Daniel\_Chen1](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Daniel\_Chen1](https://community.deeplearning.ai/u/Daniel_Chen1)\
**Post date:** [March 26, 2024, 2:44am UTC](https://community.deeplearning.ai/t/c5w4a1-attention-q-k-v-why-we-use-matmul-not-dot-product/598491/4 "2024-03-26T02:44:41Z")

</div>

Oh, I got it. I thought matmul is element-wise multiplication. Thanks!
