Scaled Dot-Product Attention
Scaled Dot-Product Attention is a core component of Transformer models and a specific implementation of the Query-Key-Value (QKV) attention paradigm. Its operation is defined by the formula: In this formula:
- (Queries), (Keys), and (Values) are the input matrices, where .
- The attention scores are calculated via the dot product of the Query and transposed Key matrices ().
- These scores are scaled by the square root of the key vector dimension, , to maintain stable gradients during training.
- An optional
Maskmatrix is added to the scaled scores. This is crucial in settings where attention should be restricted, such as preventing a position from attending to subsequent positions in autoregressive tasks. - The Softmax function normalizes the scores into attention weights (probabilities).
- The final output is a weighted sum of the Value vectors based on these weights.

0
1
References
Reference of Foundations of Large Language Models Course
Reference of Foundations of Large Language Models Course
Reference of Foundations of Large Language Models Course
Reference of Foundations of Large Language Models Course
Reference of Foundations of Large Language Models Course
Reference of Foundations of Large Language Models Course
Reference of Foundations of Large Language Models Course
Reference of Foundations of Large Language Models Course
Tags
Ch.2 Generative Models - Foundations of Large Language Models
Foundations of Large Language Models
Foundations of Large Language Models Course
Computing Sciences
Ch.5 Inference - Foundations of Large Language Models
Related
Scaled Dot-Product Attention
Causal Self-Attention in Autoregressive Decoders
A model is processing a sequence of three tokens. For the query at position 2, the un-normalized attention scores with respect to the keys at positions 0, 1, and 2 are calculated as [1.0, 2.0, 3.0] respectively. What is the final attention weight that the token at position 2 will assign to the token at position 1?
Attention Output as a Weighted Sum of Values
Impact of Masking on Attention Weight Distribution
True or False: In a self-attention mechanism, if you add the same constant value to all un-normalized attention scores corresponding to a single query vector, the final normalized attention weights for that query will change.
Attention Weight Formula ()
Single-Query Attention Computation with Multiplicative Scaling
Scaled Dot-Product Attention
General Attention Formula
Value Matrix for Causal Attention (V_≤i)
Value Matrix from a Sliding Window
An attention mechanism processes an input sequence of 20 tokens, where each token is represented by a 256-dimensional vector. A Value matrix (V) is generated as part of this process. Which of the following statements most accurately describes the properties and role of this V matrix?
Determining Value Matrix Dimensions
Debugging an Attention Mechanism
Scaled Dot-Product Attention
Multi-Head Self-Attention Function
Purpose and Structure of the Feed-Forward Network (FFN) in Transformers
A standard processing block in a Transformer model consists of two main sub-layers applied in sequence. The first sub-layer's primary role is to relate different positions of the input sequence to compute a new representation for each position. The second sub-layer then applies an identical non-linear transformation to each position's representation independently. How does the core computational function, denoted as
F(·), implemented within each of these sub-layers, differ?A standard processing block in a certain neural network architecture consists of two main sub-layers. Each sub-layer's computation can be described as applying a core function,
F(·), within a structure that also includes a residual connection and layer normalization. Match each sub-layer type with the correct description of its core computational function,F(·).Identifying Core Functions in a Transformer Block
Learn After
Causal Attention Input Structure
Causal Attention Mask Matrix Definition
Causal Attention Weight Matrix Calculation
An engineer is implementing an attention mechanism where the output is a weighted sum of Value vectors, with weights determined by a Softmax function applied to scores. They observe that as the dimension (
d) of the Query and Key vectors increases, the attention weights become extremely concentrated on a single position (e.g.,[0.01, 0.98, 0.01]), causing training instability. The scores are derived from the dot product of Query (Q) and Key (K) matrices. What is the most likely cause of this issue?Attention Mechanism Misapplication in Summarization
Analyzing the Role of the Mask in Attention
Selecting an Attention Design for Long-Context, Low-Latency Inference
Diagnosing and Redesigning Attention for a Long-Context, Cost-Constrained LLM Service
Choosing an Attention Stack for a Regulated, Long-Document Review Assistant
Attention Redesign for a Long-Context Customer-Support Copilot Under GPU Memory Pressure
Attention Redesign for a Multi-Tenant LLM with Long Context and Strict KV-Cache Budgets
Attention Architecture Choice for On-Device Meeting Summarization with 60k Context
You’re debugging an LLM inference service that mus...
You’re reviewing a design doc for a Transformer at...
Your team is deploying a chat-based LLM that must ...
You’re leading an LLM platform team that must supp...