liveBook · Manning

Inner product

As explained in Math and Architectures of Deep Learning

A scalar computed from two vectors by multiplying corresponding components and summing them, used here to measure one vector's projection along another.

The inner product, usually called the dot product, turns two vectors of equal length into one scalar. For vectors a = [a₁,…,aₙ] and b = [b₁,…,bₙ], a · b = Σᵢ aᵢbᵢ: multiply corresponding components, then add the products. Equal dimensions are required. This compact notation replaces a long weighted sum such as x₀w₀ + x₁w₁ + b with x · w + b, regardless of how many features a model has. section 2.5.2

Geometrically, a · b = ‖a‖‖b‖cos(θ), where θ is the angle between the vectors. It captures how much one vector lies along the other: aligned vectors produce a large positive value, perpendicular vectors produce zero, and oppositely directed vectors produce a negative value. Vectors with dot product zero are orthogonal, meaning that one has no component in the other’s direction. section 2.5.6 section 2.6

Feature similarity

Represent each document by a vector of word-feature values. Two documents with no shared relevant words can have dot product 0, while documents sharing many relevant words have a larger dot product. The dot product therefore provides a quantitative first estimate of document similarity; a larger value loosely indicates greater agreement between feature vectors. section 2.5.6 section 4.1

A dot product is the unit computation behind larger linear-algebra operations. Matrix–vector multiplication computes one dot product per matrix row, producing weighted-sum outputs for many input instances. In a neural-network linear layer, each output neuron similarly forms a dot product between its incoming activations and its weight vector, then incorporates bias and activation processing. section 2.5.3 section 8.3.1

Figure 2.7 Vector components and dot product

(a) Components of a 2D vector along coordinate axes. Note that |||| is the length of hypotenuse.

(b) Dot product as a component of one vector along another ⋅ = T = axbx + ayby = |||| ||||cos(θ).

This diagram links component projections in two dimensions to the formula a · b = ‖a‖‖b‖cos(θ). section 2.5.6

PyTorch computation

For a = [1, 2, 3] and b = [4, 5, 6], use torch.dot(a, b) to compute 1×4 + 2×5 + 3×6. For perpendicular vectors [1, 0] and [0, 1], torch.dot returns zero. section 2.7.2

How Math and Architectures of Deep Learning covers it

How deep it goes
Defines componentwise computation, develops projection and orthogonality intuition, then connects it to matrix operations and PyTorch.
Examples
Uses cat-brain weighted sums, document word vectors, physical push and displacement, and PyTorch vector tensors.
What it assumes
Builds from vector representations and requires only that paired vectors have the same dimensions.
What you can do after
Apply it via PyTorch to compute vector products and interpret zero, positive, and negative results geometrically.
How it connects
Connects vectors, matrix-vector multiplication, orthogonality, document similarity, linear models, and neural-network linear layers.

Also explained in

Compare how 12 books explain inner product →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Math and Architectures of Deep Learning. The section links point to the parts of the book it draws on.