Inside the Attention Hull
Why an attention head’s weighted average stays inside the value hull, and what changes after output projection.
Before you start: vector addition, dot products, and weighted averages. The lesson introduces convex combinations and their geometric meaning.
The pre-projection softmax weighted sum
Can an attention head’s weighted average leave the value hull? Nonnegative weights that sum to one keep h inside it. An output map and residual write can move y outside the original hull, while y stays inside its transformed hull.
Start with three non-collinear value vectors v₁, v₂ and v₃ in a plane. Their convex hull is the filled triangle joining their tips. Keys determine how strongly each value is weighted; a key and its corresponding value need not be the same vector.
For a query q and keys kᵢ, write the score as sᵢ = q · kᵢ. A positive temperature τ scales these scores before softmax. This lesson uses temperature as an adjustable teaching parameter.
wᵢ = exp(sᵢ / τ) / Σⱼ exp(sⱼ / τ), with τ > 0. The head mixture is h = Σᵢ wᵢ vᵢ.
For finite, unmasked scores, softmax weights are positive and sum to one in exact arithmetic. Changing the query changes their balance. Lower temperature concentrates weight on the highest-scoring values; tied highest scores can share that weight. None of these changes lets h cross the original hull boundary.
Standard scaled dot-product attention divides q · kᵢ by √dₖ, where dₖ is the key dimension. A separate temperature would divide that scaled score again. The geometric argument depends on the resulting weights, so either positive scaling leaves it intact.
Geometry example unavailable
This page’s figure needs a configuration update.
A geometric teaching fixture, not a trained Transformer. The same weights combine the original values into h and their affine images into y.
Mathematical criterion & coordinate check
Output projection and residual addition are a different step from forming the weighted average. In this simplified example, all vectors use the same two-dimensional coordinates, so we can compare the original and transformed hulls directly.
y = x_res + Wₒ h = Σᵢ wᵢ (x_res + Wₒ vᵢ).
For a fixed matrix Wₒ and residual vector x_res, y belongs to the transformed hull conv{x_res + Wₒvᵢ}. That hull can be translated, rotated, stretched, reflected or collapsed. It need not lie inside the original conv{vᵢ}, so y may leave the original hull without violating the convex-combination rule.
In a full Transformer, a head’s value space and the residual stream may have different dimensions. Multi-head attention concatenates head outputs before an output projection. This fixture isolates a single-head affine map; it does not represent the complete block, layer normalization, masking or dropout.
For a non-collinear triangle, every point in the plane has unique barycentric coordinates λ₁, λ₂ and λ₃. They sum to one and reconstruct the point. All three coordinates are nonnegative exactly when the point is in the closed original triangle. A negative coordinate shows that it is outside.
Optional: why the criterion works
A convex hull is the set of all nonnegative combinations of its vertices whose coefficients sum to one. For a non-collinear triangle, the barycentric representation is unique. Therefore its barycentric coordinates are nonnegative if and only if the point belongs to the triangle.
For h, these coordinates are precisely the softmax weights. Positive weights put h in the interior of a non-collinear triangle. In general, a hull may be lower-dimensional; “relative interior” is the appropriate statement. Masked or manually zeroed weights can put a mixture on an edge or vertex.
The same reasoning applies after an affine map because the weights still sum to one: adding x_res once is the same as adding Σᵢ wᵢx_res. This proves membership in the transformed hull, even if that hull collapses to a segment or point.
Optional: a TypeScript coordinate calculation
This illustrative calculation assumes finite inputs and a well-conditioned, non-collinear triangle. It returns the coordinates; it does not choose a floating-point inclusion tolerance.
type Vec2 = { x: number; y: number };
function barycentric(p: Vec2, a: Vec2, b: Vec2, c: Vec2) {
const det = (b.y-c.y)*(a.x-c.x)
+ (c.x-b.x)*(a.y-c.y);
if (det === 0) throw new Error('Degenerate triangle');
const l1 = ((b.y-c.y)*(p.x-c.x)
+ (c.x-b.x)*(p.y-c.y)) / det;
const l2 = ((c.y-a.y)*(p.x-c.x)
+ (a.x-c.x)*(p.y-c.y)) / det;
return [l1, l2, 1-l1-l2];
}In exact arithmetic, test every λᵢ ≥ 0. In floating-point code, inspect the residual and choose a scale-aware tolerance. A near-zero determinant is numerically unstable even when it is not exactly zero; the short example is not a general robust geometry library.
3D extension: four value vectors in space
Four non-coplanar value vectors in three dimensions span a tetrahedron. The same convex-combination rule applies: a weighted average with nonnegative weights adding to one stays inside or on its surface. Camera motion changes only the picture, not the world-space mixture.
For coefficients rᵢ ≥ 0 with Σⱼ rⱼ > 0, let αᵢ = rᵢ / Σⱼ rⱼ. Then h = α₁v₁ + α₂v₂ + α₃v₃ + α₄v₄.
These four controls are direct mixture coefficients, rather than scores passed through softmax. A zero coefficient is allowed and can put the mixture on a face or edge. Only the positive-total condition makes the normalization defined. If all four controls are zero, the fixture explicitly uses equal weights instead; it is not normalizing a zero total.
Geometry example unavailable
This page’s figure needs a configuration update.
Glossary & references
Convex hull, conv(V): every weighted average of the vectors in V with nonnegative weights that sum to one. A triangle includes its edges; a tetrahedron includes its faces.
Softmax: an exponential normalization of scores into weights. Finite scores and positive temperature give positive weights in exact arithmetic. Masked scores and numerical rounding require separate care.
Barycentric coordinates: coefficients summing to one that express a point relative to simplex vertices. They are unique for a non-degenerate simplex. Membership in its closed hull is equivalent to nonnegative coordinates.
Affine map: a linear map followed by a translation. Here the map is h ↦ x_res + Wₒh. It preserves convex combinations, but does not necessarily preserve membership in the original hull.
Vaswani and colleagues introduced scaled dot-product attention and the multi-head output projection in Attention Is All You Need (2017). The geometric argument and the small interactive fixtures here are an explanatory derivation, not a reproduced model experiment.