A vector is a list of numbers.
A vector is a list of numbers in a fixed order. Two vectors are close when their numbers are close.
new words
- Vector
- A list of numbers in a fixed order. [170, 34, 39] is a vector.
- Dimension
- How many numbers the list has. [170, 34, 39] has three dimensions.
- Distance
- One number that says how far apart two vectors are. Small means similar.
the lesson
Write three people as three numbers each: height in centimetres, age in years, shoe size. Anna, Levon and Karen are example names.
| Person | Height | Age | Shoe |
|---|---|---|---|
| Anna | 170 | 34 | 39 |
| Levon | 172 | 35 | 40 |
| Karen | 195 | 60 | 47 |
Anna and Levon differ by 2, 1 and 1. Anna and Karen differ by 25, 26 and 8. So Anna is closer to Levon. Once a thing is numbers, "similar" is arithmetic, and a computer does it a million times a second.
The distance is the subtraction, number by number, each difference squared, the squares added, and the square root taken:
Levon − Anna = [2, 1, 1] 2² + 1² + 1² = 6, √6 = 2.45 Karen − Anna = [25, 26, 8] 625 + 676 + 64 = 1,365, √1,365 = 36.95
An embedding vector works the same way with 1,536 numbers instead of three. The one difference: nobody named the columns. Inside a model, each token's vector is one row of a table set by training: How a model works, lesson 3.
try it
Type this and press Enter:
Three people as vectors of height in cm, age, shoe size: Anna [170, 34, 39], Levon [172, 35, 40], Karen [195, 60, 47]. Which two are closest? Subtract number by number, square the differences, add them, take the square root, and show the work.
you should see
- Levon − Anna = [2, 1, 1], 4 + 1 + 1 = 6, √6 = 2.45. Karen − Anna = [25, 26, 8], 625 + 676 + 64 = 1,365, √1,365 = 36.95.
- Anna and Levon are the closest pair. The smaller number is the closer person. Lesson 5 shows the measure retrieval uses instead: the angle.