Example

Example of Causal Attention Dot Products

In a causal self-attention mechanism, a query at a given position i is restricted to attending only to keys at positions j that are less than or equal to i (jleij \\le i). This ensures that the prediction for a token depends only on the preceding tokens. The following list illustrates the specific query-key dot products that are computed for a sequence, demonstrating the lower-triangular pattern of attention scores before masking:

  • For query mathbfq0\\mathbf{q}_0: mathbfq0mathbfk0T\\mathbf{q}_0 \\mathbf{k}_0^T
  • For query mathbfq1\\mathbf{q}_1: mathbfq1mathbfk0T\\mathbf{q}_1 \\mathbf{k}_0^T, mathbfq1mathbfk1T\\mathbf{q}_1 \\mathbf{k}_1^T
  • For query mathbfq2\\mathbf{q}_2: mathbfq2mathbfk0T\\mathbf{q}_2 \\mathbf{k}_0^T, mathbfq2mathbfk1T\\mathbf{q}_2 \\mathbf{k}_1^T, mathbfq2mathbfk2T\\mathbf{q}_2 \\mathbf{k}_2^T
  • For query mathbfq3\\mathbf{q}_3: mathbfq3mathbfk0T\\mathbf{q}_3 \\mathbf{k}_0^T, mathbfq3mathbfk1T\\mathbf{q}_3 \\mathbf{k}_1^T, mathbfq3mathbfk2T\\mathbf{q}_3 \\mathbf{k}_2^T, mathbfq3mathbfk3T\\mathbf{q}_3 \\mathbf{k}_3^T

This pattern continues for the entire sequence length.

0

1

Updated 2026-06-27

Contributors are:

Who are from:

Tags

Ch.2 Generative Models - Foundations of Large Language Models

Foundations of Large Language Models

Foundations of Large Language Models Course

Computing Sciences