Transformer Math · Authored by Sandeep Belgavi

Dot Product Geometry (2D)

Measure vector dot products, unit normalization, projection and zero-vector boundaries with editable coordinates.

Experiment

Diagram labels stay full size. On narrow screens, scroll the diagram horizontally or focus it and use the arrow keys. Exact values follow below.

Direct mathematical inspection: change an input to recompute the result immediately.

Dot Product Geometry (2D): experiment guide

This is a direct geometry instrument. The four coordinate fields specify vectors a and b in a two-dimensional Euclidean space, with the same units on both axes. Changing any coordinate immediately recalculates the picture and numerical results. You can also drag either labeled endpoint using a mouse, pen, or touch; the numeric fields provide the same operation from a keyboard. The coordinate range is −5 to 5, and dragging rounds to tenths so that experiments are reproducible. Reset restores a = (3, 4), b = (4, 0), and turns normalization off. There is no playback timer because the model is a measurement of the current vectors, not a process unfolding over time.

Worked details 1

The dot product is ax × bx + ay × by. Magnitudes are square roots of the sums of squared components. When neither vector is zero, cosine similarity divides the dot product by the product of the two magnitudes, and the angle is the inverse cosine expressed in degrees. The dashed segment is the projection of a onto the line through b: b multiplied by (a dot b) / (b dot b). Its endpoint can lie opposite the arrow for b when the dot product is negative. The plot uses labeled arrows as well as different colors, while the result below supplies the coordinates, magnitudes, angle, cosine, and projection as text.

Worked details 2

Start with the reset values. Predict a magnitude of 5 for a, 4 for b, a dot product of 12, cosine similarity 0.6, and projection (3, 0). The angle is approximately 53.130102 degrees. Enable Normalize vectors: each nonzero vector is divided by its own original magnitude, so both displayed magnitudes become 1 and the dot product becomes 0.6. The input fields retain the original coordinates; the picture and result display the transformed unit vectors. Disable normalization before dragging so that the endpoints once again correspond directly to the input coordinates. When normalization is enabled, dragging is disabled to avoid silently changing a different coordinate than the displayed unit endpoint.

Worked details 3

For an orthogonality experiment, enter a = (1, 0), b = (0, 1). The dot product and projection are zero, and the angle is 90 degrees. Change b to (−1, 0): the dot product becomes −1 and the angle becomes 180 degrees. Finally set a to (0, 0). Its raw dot product remains zero, but cosine similarity and angle are undefined because their denominator vanishes. Enabling normalization now reports an explicit boundary instead of inventing a unit vector. This two-dimensional demonstration omits learned embeddings, attention scaling, positional encoding, and softmax. Similarity here is a geometric calculation, not a claim about semantic relevance or a trained model’s confidence.

Views are my own and do not represent any employer, past or present.