Each token's embedding is projected by learned matrices into a query (Q), key (K) and value (V).
Scores = Q times K transposed, divided by the square root of the key dimension; softmax turns each row into attention weights; the output is the weighted sum of the value vectors.
Every token can directly attend to every other token, so long-range dependencies are one step away and all positions compute in parallel.
Complexity is quadratic in sequence length for both compute and memory (an n by n score matrix), which is why long contexts are expensive.
Loading…