Scaled Dot-Product Attention › Key Parameters

Michael BrenndoerferMay 25, 20252 min read
Language AI HandbookAll chapters
Part 13 of 67Self-Attention
Chapter 92Scaled Dot-Product Attention › Key Parameters
Reading section 12 of 15 · Key Parameters · 2 minSection 12 of 15 · 2 min

Book contents

Section 12 of 15 · 2 min read

Scaled Dot-Product Attention › Key ParametersOne section · Sections in this chapter12 / 15 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Scaled dot-product attention introduces two primary hyperparameters, both of which interact with the quadratic complexity we analyzed above.

The first is dkd_k (query/key dimension): the dimensionality of the query and key projections. Larger dkd_k allows queries and keys to encode more complex patterns. This provides more expressive capacity for the similarity computation. However, it increases computational cost as O(n2dk)O(n^2 d_k) and also increases the number of parameters in WQW^Q and WKW^K. Too small a dkd_k may not provide enough expressive capacity to represent the diversity of relationships the model needs to capture. Too large a dkd_k wastes computation on dimensions that carry little signal. Typical values range from 64 to 256 per head in multi-head attention, with 64 being the value used in the original transformer paper's base model.

The second is dvd_v (value dimension): the dimensionality of the value projections and the output. The value dimension controls the richness of the information each token contributes when attended to. Setting dvd_v smaller than dkd_k creates a bottleneck that forces the model to compress information, which can be a useful regularizer. Setting dvd_v larger allows richer information transfer. In practice, dv=dkd_v = d_k is by far the most common choice, and it simplifies the architecture by making all projection dimensions equal. Changing dvd_v changes the size of the output representation without affecting the attention weights.

The scaling factor dk\sqrt{d_k} is not a hyperparameter: it is derived from dkd_k and applied without modification. There is no reason to tune it separately; it is a fixed normalization constant whose derivation we worked through in the scaling section above.