attention mechanis 的数学理解
生活随笔
收集整理的這篇文章主要介紹了
attention mechanis 的数学理解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
參考鏈接
attention其實就是一個加權求和
import numpy as np import tensorflow as tfa=np.array((list(range(3*4)))).reshape((3,4))*1.0 b=a+3.0 katten=tf.keras.layers.Attention()([a, b])print('keras attention=',katten)從算法本質上理解attention ,就是三次矩陣運算
weight=a@b.T weight1=tf.nn.softmax(weight) attent=weight1@bprint('my attention=',attent) keras attention= tf.Tensor( [[11. 12. 13. 14.][11. 12. 13. 14.][11. 12. 13. 14.]], shape=(3, 4), dtype=float32) my attention= tf.Tensor( [[11. 12. 13. 14.][11. 12. 13. 14.][11. 12. 13. 14.]], shape=(3, 4), dtype=float64)總結
以上是生活随笔為你收集整理的attention mechanis 的数学理解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ubuntu 输入法问题:显示繁体
- 下一篇: python 实现 softmax