Question Description
Embedding dimension : d m o d e l = 4 d_{model} = 4 d m o d e l = 4
Input sequence (sequence length = 2 = 2 = 2 , d m o d e l = 4 d_{model} = 4 d m o d e l = 4 ) :
X = [ 1 0 0 2 1 0 0 2 ] X = \begin{bmatrix} 1 & 0 \\ 0 & 2 \\ 1 & 0 \\ 0 & 2 \end{bmatrix} X = 1 0 1 0 0 2 0 2
Number of heads: 2 (each head operates on 2 dimensions)
For both the heads d K = d Q = d V = 2 d_K = d_Q = d_V = 2 d K = d Q = d V = 2
Weight matrices for W Q , W K , W V W_Q, W_K, W_V W Q , W K , W V first head :
W Q 1 , W K 1 , W V 1 = [ 1 1 1 1 2 2 2 2 ] W_Q^1, W_K^1, W_V^1 = \begin{bmatrix} 1 & 1 & 1 & 1 \\ 2 & 2 & 2 & 2 \end{bmatrix} W Q 1 , W K 1 , W V 1 = [ 1 2 1 2 1 2 1 2 ]
Weight matrices for W Q , W K , W V W_Q, W_K, W_V W Q , W K , W V second head :
W Q 2 , W K 2 , W V 2 = [ 1 0 1 0 1 1 2 1 ] W_Q^2, W_K^2, W_V^2 = \begin{bmatrix} 1 & 0 & 1 & 0 \\ 1 & 1 & 2 & 1 \end{bmatrix} W Q 2 , W K 2 , W V 2 = [ 1 1 0 1 1 2 0 1 ]
The output from both heads are concatenated, then projected by:
W O = [ 0.5 0 0 0 0 0.5 0 0 0 0 1 0 0 0 0 1 ] W_O = \begin{bmatrix} 0.5 & 0 & 0 & 0 \\ 0 & 0.5 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} W O = 0.5 0 0 0 0 0.5 0 0 0 0 1 0 0 0 0 1
Scaled Dot-Product Attention (Q, K, V ) = softmax ( Q T K d k ) V T \text{Scaled Dot-Product Attention (Q, K, V )} = \text{softmax}\left(\frac{Q^T K}{\sqrt{d_k}}\right) V^T Scaled Dot-Product Attention (Q, K, V ) = softmax ( d k Q T K ) V T
Based on the above data, answer the given subquestions.
Select the scaled dot-product attention for the first head: