Index Ai Academy
Foundation · Foundation mathVectors and matrices

Sliding dot products: convolution

About 40 minLooking ahead: some prerequisites aren't done yet

Why this matters

A layer from lesson 56 gives every input its own weight for every output. For a picture, that's a lot of weights, and it ignores something true of pictures: an edge looks the same wherever it is. Image and audio models do something smarter. They slide one small pattern across the input and take a dot product at each stop. That's a convolution, and it's the dot product from lesson 50, repeated.

  • Slide a 3-number pattern along a list and compute every output as a dot product
  • Predict how many outputs there are, (n + 2p − k) ÷ s + 1 rounded down, with stride s and padding p
  • Do the same in two dimensions: a 3 × 3 pattern over a 5 × 5 trail sign, with two loops
  • Say what a pattern detects from its numbers, and count the weights it saves by sharing them
Quick check
Have a guess before you start. A window 3 numbers wide slides along a list of 7 numbers, one place at a time, and never hangs off the end. How many places can it sit?

The math: one pattern, many stops

Purpose. Slide a small pattern along a list, take a dot product at every stop, and count the stops.

Here's a row of 6 pixels from a photo, dark on the left and bright on the right: x = (2, 2, 2, 7, 7, 7). And here's a pattern, or kernel, of 3 numbers: w = (−1, 0, 1). Lay w over the first 3 pixels, the window, and take the dot product: 2 × (−1) + 2 × 0 + 2 × 1 = 0. Slide one place right and do it again. Each stop gives one output number. The list of outputs, y, is the convolution of x with w.

yj=w⋅(xj,xj+1,xj+2)y_j = \mathbf{w} \cdot (x_j, x_{j+1}, x_{j+2})

In plain words: output j is the pattern dotted with the window that starts at place j.