Machine learning with football · Chapter 9

Embeddings

A one-hot club is 20 numbers with nothing in common. An embedding packs it into a few numbers that put similar clubs side by side.

Estimated time: 5 minutes · page 1 of 5

The trouble with one-hot

Chapter 6 turned each club into a one-hot vector, 20 numbers with a single 1. That works, but it has a cost. Feed it into a layer of 8 neurons and the club alone needs 20 × 8 = 160 weights. With every player in Europe instead of every club, it would be tens of thousands of inputs and millions of weights. More weights need more data, more computing, and more memory, which hurts most on a phone.

There's a deeper problem. One-hot makes every club exactly as different from every other club. Arsenal is as far from Liverpool as from the bottom side, and the model has to learn each one from scratch.

Encoding is the first way you turn data into numbers, one-hot for instance. An embedding is a short, dense vector, a handful of numbers per club, arranged so that similar clubs end up close together. The board already shows one, every club of Premier League as a point in two dimensions. The next pages explain where those positions come from.

Check yourself

A one-hot club feature for 20 clubs feeds a first layer of 8 neurons. How many weights does that layer need for the club alone?
What is the difference between encoding and embedding?

Leagues