独热编码 · 类别变成位置
One-hot Encoding · Turn Categories into Positions
cat → [1,0,0] · dog → [0,1,0] · bird → [0,0,1]
独热编码用仅一个 1 和其余 0 表示离散类别。它能保住“是谁”,却不会自动表达“谁和谁更像”。
One-hot encoding represents a discrete category with one 1 and zeros elsewhere. It preserves identity but does not express which categories are more alike.
01 · 想象三盏呼叫灯
01 · Imagine three call lights
猫、狗、鸟各按一盏专属灯,能知道谁按了;能知道猫更像狗还是鸟吗?
Cat, dog, and bird each press a dedicated light. You know who pressed it—but can you tell whether cat is closer to dog or bird?
0·1·0
02点类别,观察哪格亮起
Choose a Category and Watch One Cell Light Up
唯一变量:类别One variable: category
当前类别Category
猫Cat
index 0
亮格Hot cells
1
其余全为 0all others are 0
异类距离
Other-class distance
√2
≈ 1.414
03三格向量的 4 个零件
Four Parts of the Three-cell Vector
identity, not similarity
CATEGORY
离散类别 Discrete category
猫、狗、鸟是互斥标签,不是连续数值。
Cat, dog, and bird are mutually exclusive labels, not continuous numbers.
POSITION
专属位置Dedicated position
每个类别在向量中占一个固定索引。
Each category owns one fixed vector index.
HOT
唯一的 1The single 1
所选类别位置亮起,其余位置为 0。
The selected category turns on; every other position stays 0.
DISTANCE
等距Equal distance
任意两个不同独热向量的距离都为 √2。
Every pair of distinct one-hot vectors is √2 apart.
04最小机制:索引相同才落在同一点
Minimal Mechanism: Only the Same Index Shares a Point
e i
onehot(i)j
= { 1 if i=j · 0 otherwise }
不同类别在两个位置上相差 1,所以距离 √(12+12
) = √2。上方切换任意类别都能验证。
Two distinct categories differ by 1 in two positions, so distance √(1
2+12
) = √2. Verify by choosing any category above.
05 边界实验:把类别编号当距离会造假
Boundary Test: Treating Category IDs as Distance Invents Order
主动制造失败Create a failure
把猫=0、狗=1、鸟=2 直接算差
Compute differences from cat=0, dog=1, bird=2
这样会凭空得到“猫到鸟是猫到狗的两倍远”,而编号只用于识别,不承载大小。
This invents “cat is twice as far from bird as from dog,” although IDs identify categories and carry no magnitude.
尚未执行。先确认独热距离全部相同。
Not run yet. First confirm all one-hot distances are equal.
✗ 类别 ID 越接近,类别越相似。
Closer category IDs mean more similar categories.
→ ✓
ID 是索引,不是量尺。
An ID is an index, not a ruler.
✗
独热编码能表达猫比鸟更像狗。
One-hot encoding says cat is more like dog than bird.
→ ✓
所有不同类别都等距。
All distinct categories are equally distant.
✗
向量有数字就一定有语义距离。
Numeric vectors always have semantic distance.
→ ✓
编码方式决定距离是否有意义。
The encoding determines whether distance is meaningful.
06 · 一句话带走06 · One line to keep
独热编码用唯一的 1 表示离散类别,能区分身份却让任意两类等距;上方切换类别即可检验。
One-hot encoding identifies a discrete category with one 1, separating identity while making every distinct pair equally distant. Choose categories above to verify.