on-internet
← Community

Why are the matrices in BERT called Query, Key, and Value?

Stack Overflow ·

Within the transformer units of BERT, there are modules called Query, Key, and Value, or simply Q,K,V. Based on the BERT paper and code (particularly in modeling.py), my pseudocode understanding of the forward-pass of an attention module (using Q,K,V) with a single attention-head is as follows: q_param = a matrix of learned parameters k_param = a matrix of learned parameters v_param = a matrix of learned parameters d = one of the matrix dimensions (scalar value) def attention(to_tensor, from_tensor, attention_mask): q = from_tensor * q_param k = to_tensor * k_param v = to_tensor * v_param atte

Comments

Sign in or sign up to comment and upvote.

No comments yet.