Compute the scaled dot-product score between a query and key vector โ the fundamental operation before softmax in attention.
score(Q, K) = Q ยท K / โd_kWhere d_k = length of Q (and K).
Without scaling, dot products grow large in high dimensions โ softmax becomes peaky โ vanishing gradients.
attention_score([1,0,1,0],[0,1,0,1]) โ 0.0 attention_score([1,1],[1,1]) โ 1.41421
Round to **5 decimal places**.
Test Cases (2 visible ยท 2 hidden)
Case 1: Orthogonal vectors
Input: attention_score([1,0,1,0],[0,1,0,1])
Expected: 0.0
Case 2: 2D parallel
Input: attention_score([1,1],[1,1])
Expected: 1.41421
โโต Run ยท โโงโต Submit