Chapter 5 · Turning language into numbers
Cosine similarity
Cosine similarity measures the angle between two vectors: same direction means similar meaning.
Chapter 5 · Turning language into numbers
Cosine similarity measures the angle between two vectors: same direction means similar meaning.
0° → score 1.00
Almost the same direction: very similar
Cosine similarity only looks at the angle. Same direction scores 1, a right angle scores 0, and opposite directions score −1.
An embedding is a vector, so you can picture it as an arrow from the centre. Similar meanings point in similar directions.
Drag the A and B handles, or use the sliders. Try pointing them the same way, at right angles and in opposite directions. Then stretch B without turning it.
The arrows are flat (2 numbers) so you can drag them. The word scores come from the 3-number hand-made map of the Embeddings lesson. Real embeddings have far more numbers but use the same formula.
Two arrows point in exactly the same direction. What is their cosine similarity?
You stretch one arrow to twice its length without turning it. What happens to the score?
Two arrows at a right angle score about…