Part I ยท Ch. 4 โ€” Projections and Shadows

Part I ยท Chapter 4 of 4

Projections and Shadows

Choosing the flashlight angle, and what a two-dimensional picture is allowed to prove


You have already seen a thousand of these

Open any paper about embeddings and somewhere in it there is a scatter plot: a few hundred colored dots on a flat pair of axes, with clusters labeled "sports," "medicine," "recipes." It is the picture everyone reaches for, and it is genuinely useful.

The previous chapter just told us those dots live in 1000 dimensions. So the plot is not the space. It is a shadow of the space, cast onto a page โ€” and a shadow is a real measurement with real rules about what it can and cannot establish. This chapter is about those rules. By the end you will know how such a picture is made, how to make a better one on purpose, and, most usefully, exactly which conclusions you are entitled to draw from someone else's.

A shadow is two readings

We built the machinery for this in Chapter 1 and have not used it since. Recall: a unit vector is a ruler, and dotting a point with it hands back one number โ€” how far the point reaches along that direction.

To put a point on a page we need two numbers. So we choose two ruler directions, take two readings, and plot the results. That is the entire operation.

$$\text{across} = \mathbf{x} \cdot \hat{\mathbf{a}}, \qquad \text{up} = \mathbf{x} \cdot \hat{\mathbf{b}}$$

In words: the horizontal position of a dot is the point's reading along the first chosen direction, and the vertical position is its reading along the second. Nothing else about the point survives onto the page.

We pick the two rulers at right angles to each other, so that the two readings do not double-count the same information. The result is called an orthogonal projection โ€” the shadow a point casts when a light shines straight down onto the plane those two rulers define.

Three bordered panels in a row, each showing the shadow of the same three-dimensional cloud of points cast onto a different flat plane. The cloud has three groups drawn in mint, amber and blue. Left panel, headed 'a bad angle': the amber and blue groups are piled on top of each other in one blob while the mint group sits apart, noted 'two groups, not three'. Middle panel, headed 'better': all three are visible but the mint and blue groups nearly touch. Right panel, headed 'the best available': all three sit apart with clear gaps, noted 'three, clearly'.
Same cloud, same points, three flashlight angles. The structure did not change; only what the shadow keeps did. The left panel would have you report two groups where there are three.

The three panels above are one cloud of points, photographed from three directions. Nothing about the data differs between them โ€” those are genuine projections of the same list of points onto three different planes. Turn the flashlight and groups that were piled on top of one another come apart, or the reverse. A shadow always loses something, and which something it loses is a choice somebody made.

That is the whole tension of this chapter. The question is not "is this plot true" but "which of the true things did it choose to keep?"

Choosing the angle on purpose

If the angle is a choice, we should make it deliberately. The standard way of making it is PCA โ€” principal component analysis โ€” and stripped of its machinery it is one sentence: point the flashlight so the shadow is as spread out as possible.

The reasoning is that a direction along which the data barely varies carries almost nothing to distinguish one point from another, so losing it costs little. A direction along which the data varies a lot is doing real work, and we should keep it. So: rank every possible direction by how much the data spreads along it, and keep the top two.

Two housekeeping steps come first, and both matter. Center the data โ€” subtract the average point โ€” so that the readings describe displacement from the middle of the cloud instead of from an arbitrary origin. And use unit ruler directions, so a reading is a coordinate and not a coordinate multiplied by some leftover scale factor.

Finding the best angle by hand

Four points, already centered on the origin: $[3, 4]$, $[-3, -4]$, $[-0.8, 0.6]$ and $[0.8, -0.6]$. Let us try three candidate rulers and see which spreads them most. Spread here is the average of the squared readings, which is the ordinary variance.

Ruler 1, straight across, $[1, 0]$. The four readings are 3, โˆ’3, โˆ’0.8 and 0.8. Squared: 9, 9, 0.64, 0.64. Average: $19.28 \div 4 = 4.82$.

Ruler 2, straight up, $[0, 1]$. Readings 4, โˆ’4, 0.6, โˆ’0.6. Squared: 16, 16, 0.36, 0.36. Average: $32.72 \div 4 = 8.18$.

Ruler 3, the tilted one, $[0.6, 0.8]$ โ€” our unit vector from Chapter 1. First point: $3 \times 0.6 + 4 \times 0.8 = 1.8 + 3.2 = 5$. Second: โˆ’5. Third: $-0.48 + 0.48 = 0$. Fourth: 0. Squared: 25, 25, 0, 0. Average: $50 \div 4 = 12.5$.

In words: the tilted ruler spreads these points more than either of the two we were handed โ€” 12.5 against 8.18 and 4.82. It is the first principal component of this little cloud, and neither of the axes the data arrived with was it.

Now the second component. It must be at right angles to the first, which in two dimensions leaves exactly one choice: $[-0.8, 0.6]$. Its readings are 0, 0, 1, โˆ’1, so its variance is $2 \div 4 = 0.5$.

Add the two up: $12.5 + 0.5 = 13.0$. Now add up the two we started with: $4.82 + 8.18 = 13.0$. The same total. Turning the rulers moved the spread around between them but never created or destroyed any, and that conservation is what makes the next number meaningful.

$$\text{share kept} = \frac{12.5}{13.0} \approx 0.96$$

In words: the first direction alone accounts for about 96% of all the spread in this cloud. Keep it and throw the other away, and you have lost 4% of what distinguished these four points.

A plane with four white points at 3 comma 4, minus 3 comma minus 4, minus 0.8 comma 0.6, and 0.8 comma minus 0.6. Three candidate ruler directions run through the origin: two dashed amber lines lying along the horizontal and vertical axes, and a solid violet line tilted along 0.6 comma 0.8. A legend in the empty upper left reads 'spread along each candidate ruler', then 'a-hat = 0.6, 0.8 โ€” 12.5, the winner', '0, 1 โ€” 8.18', '1, 0 โ€” 4.82'. Thin dashed lines drop from each point perpendicularly onto the violet line.
Rank the directions by spread and keep the best. The winner is tilted at about 53 degrees, and neither of the axes the data arrived with was close to it.

That percentage โ€” the variance explained โ€” is the single most important number on any embedding plot, and it is also the one most often left off. A two-dimensional shadow of a 1000-dimensional space frequently keeps less than 15% of the spread. The picture may still be worth looking at. But you are looking at a seventh of the evidence, and nobody has told you which seventh.

What a shadow is allowed to prove

Here is the part worth memorizing, because it turns "be careful with these plots" into two precise rules that point in opposite directions.

When a point is projected, its journey splits into two perpendicular pieces: the part that landed on the page, and the part that was lost. Those two pieces and the original form a right triangle, so Pythagoras applies to them โ€” which gives us a hard guarantee.

$$\|\mathbf{x}\|^2 = \|\text{shadow}\|^2 + \|\text{lost}\|^2$$

In words: the original length squared equals the shadow's length squared plus the lost part's length squared. Because the lost piece can never be negative, the shadow is never longer than the original.

Apply that to the gap between two points and the two rules fall out:

  • Distance in the shadow is never more than the true distance. So if two dots look far apart on the page, they really are far apart in the full space. A shadow cannot manufacture a separation that was not there.
  • Distance in the shadow can be much less than the true distance. So two dots sitting on top of each other prove nothing whatever. They may be neighbors, or they may be on opposite sides of the space with their difference pointing entirely in a direction the projection discarded.
A right triangle above a horizontal line marked 'the page the shadow falls on'. Two white points are joined by a mint hypotenuse labeled 'true gap 5'; the dashed vertical leg between them is labeled 'lost 4' and a small square marks the right angle. Dotted lines drop from both points onto the page, where their shadows are joined by a thick violet segment labeled 'gap in the shadow 3'. A note reads '5 squared equals 3 squared plus 4 squared; the part that was lost is a real side of a real triangle, so the shadow is always the shorter one'.
The gap can shrink but never grow. A true gap of 5 shows as 3 once the vertical difference of 4 is projected away โ€” three, four, five, the oldest right triangle there is.

See it move

Turn the flashlight yourself. The cloud below has three real groups in three dimensions. Rotate the viewing direction and watch the groups merge and separate in the shadow beneath, with the share of spread kept reported live.

Where this shows up

  • Every embedding visualization you will ever be shown. The first two questions are now automatic: what share of the spread does this keep, and is this a projection or a neighbor-preserving rearrangement? If the caption answers neither, the picture is decoration.
  • Dimensionality reduction as a preprocessing step. Cutting 1000 dimensions to 100 before clustering or search is the same operation with more rulers kept. The AI/ML book's classical toolbox shows where it sits in a working pipeline.
  • Reading a model's internals. When researchers look for structure inside a network's activations, they are projecting onto a handful of chosen directions and reading the shadow. The guarantees in this chapter are exactly the guarantees on their conclusions.
  • Compression and storage. Keeping the top directions and discarding the rest is how a vector store shrinks its index, and the variance-explained figure is the honest statement of what that saving cost.

What you now know

  • A two-dimensional plot of embeddings is a shadow: two readings taken along two chosen perpendicular directions, with everything else discarded.
  • Principal component analysis chooses those directions by ranking every direction by how much the data spreads along it and keeping the top ones, after centering the cloud.
  • Turning the rulers moves spread between them without changing the total, which is what makes "share of the spread kept" a meaningful number.
  • A projection can only shrink distances, so separation on the page is real evidence while overlap on the page is no evidence at all.
  • Neighbor-preserving pictures such as t-SNE and UMAP are not projections, and neither of those rules applies to them.

Where we're headed

That completes Part I. You now have the whole instrument kit โ€” a space, two rulers, an honest account of what many dimensions do to both, and a way of looking at the result without fooling yourself. Every one of those was built without a single mention of machine learning, which was deliberate: none of them are machine-learning ideas. They are facts about space that machine learning happens to depend on.

The rest of this book puts meaning into that space โ€” how positions get earned from the company a word keeps, how context moves a point, how a probability surface is read as surprise, and what the instruments at the frontier are actually measuring. Those parts are being written; the book's front page lists what is coming. In the meantime, the next rung of the ladder is AI/ML from the Ground Up, which takes the space you have just built and starts fitting things in it.