プリンキピア

第11章注意機構とTransformer

11.5.1. Model11.5.1 モデル

Before providing the implementation of multi-head attention, let’s formalize this model mathematically. Given a query 𝐪∈ℝdq, a key 𝐤∈ℝdk, and a value 𝐯∈ℝdv, each attention head 𝐡i (i=1,…,h) is computed as
英語のヒント
マルチヘッド注意の実装を示す前に、このモデルを数学的に定式化しよう。クエリ𝐪∈ℝdq、キー𝐤∈ℝdk、バリュー𝐯∈ℝdvが与えられると、各注意ヘッド𝐡i(i=1,…,h)は次のように計算される。
𝐡i=f(𝐖i(q)𝐪,𝐖i(k)𝐤,𝐖i(v)𝐯)∈ℝpv,(11.5.1)
where 𝐖i(q)∈ℝpq×dq, 𝐖i(k)∈ℝpk×dk, and 𝐖i(v)∈ℝpv×dv are learnable parameters and f is attention pooling, such as additive attention and scaled dot product attention in Section 11.3. The multi-head attention output is another linear transformation via learnable parameters 𝐖o∈ℝpo×hpv of the concatenation of h heads:
英語のヒント
ここで、𝐖i(q)∈ℝpq×dq、𝐖i(k)∈ℝpk×dk、𝐖i(v)∈ℝpv×dvは学習できるパラメータであり、fは、11.3節の加法注意やスケール化内積注意のような注意プーリングである。マルチヘッド注意の出力は、h個のヘッドの連結を、学習できるパラメータ𝐖o∈ℝpo×hpvで線形変換したものである。
𝐖o[𝐡1⋮𝐡h]∈ℝpo.(11.5.2)
Based on this design, each head may attend to different parts of the input. More sophisticated functions than the simple weighted average can be expressed.
英語のヒント
この設計にもとづけば、各ヘッドは入力の異なる部分に注意を向けられる。単純な重みつき平均より洗練された関数を表せる。