Each token is projected into a query, key and value vector. The attention score between two tokens is the dot product of the query and key, scaled by the square root of the key dimension, passed through softmax to give weights.
The output for a token is the weighted sum of all value vectors, so it blends information from the tokens most relevant to it.
Multi-head attention runs several of these in parallel to capture different relationships; positional encodings supply word order, and a causal mask prevents decoder models from seeing future tokens.
Loading…