What is a dot product and what does it measure?easy

Type
conceptual
Topic
vectors
Frequency
very common
Tags
vectors
Answer

The dot product of two vectors is the sum of element-wise products: a dot b = sum aibi. It equals |a||b|cos(theta) - so it measures how aligned two vectors are.

Explanation

If a dot b = 0, the vectors are orthogonal (perpendicular). If a dot b > 0, they point roughly the same direction. If a dot b < 0, they point roughly opposite directions. In ML: attention scores in transformers are dot products of query and key vectors. Neural network layers compute Wx + b, which is a matrix of dot products. Cosine similarity normalizes the dot product to a [-1, 1] range for similarity comparisons.

Follow-upHow is the dot product used in the self-attention mechanism?