Zain Dana Harpernight school / F1

Vectors. A list of numbers is a place.

Every word inside a language model is a list of numbers, and a list of numbers is a place. Pylon shows you on her harbour chart, and then hands you the chart and the model's own word table.

The film

About 5:51, hosted by Pylon. It asks you two questions and waits for your answer before it shows you. The narrated cut runs 4:50, voiced by Pylon in a synthesized voice made from the author's own voice; the author approved these cuts for publishing. Captions are on by default. The live version under it draws the same film in your browser, waits for your answer at each question, and runs a little longer; the full words are also below.

Nothing loads until you press play.

The lab: Pylon's chart room

Drag two crates and watch the dot product, the lengths and the cosine change. Then open the word table of the model from the attention lesson: 46 words, 32 numbers each. Pick a word and see its nearest neighbours, computed in your browser from the trained lists. Two controls rebuild the table: the lists shuffled between words, and the lists from before training. In the film's measurement, 80% of words had a nearest neighbour of the same kind, about 23% with shuffled lists, and 9% before training.

Everything is computed on your computer, in this page. Nothing is sent anywhere.

Everything the film says

Vectors

Vectors. A list of numbers is a place.

I run the dock at Night School. Every crate that comes in gets an address on my chart.

Two numbers make a place

Here is a crate. It sits four squares east of the corner and one and a half squares north.

Write that down as a list: four, then one and a half. That list is a vector.

You can read it as a place, or as an arrow from the corner to the crate. Same list, same thing.

Arrows add and stretch

Arrows add. Walk the first one, then walk the second from where you stopped. Where you end up is the sum, and its numbers are the two lists added place by place.

Arrows stretch. Times two keeps the direction and doubles the length. Times minus one turns it round to face the other way.

The dot product

Now two crates, and a game. Multiply their lists number by number, and add it all up.

I'll swing the second crate round the corner while the sum keeps count.

As the second crate swings round, where will the sum hit zero? (the film pauses here)

Right there. At a right angle, the sum is zero. That sum is called the dot product. It is big when two arrows point the same way, zero when they meet at a right angle, and below zero when they point apart.

Length, and the cosine

The dot product has a catch. Watch what happens if I push the second crate twice as far out, in the same direction.

What happens to the dot product? (the film pauses here)

It doubles. Nothing about the direction changed, but the score did.

So divide by the two lengths. What is left depends only on the angle. It is the cosine of the angle between the arrows: one when they point the same way, zero at a right angle, minus one when they point opposite. It always stays between minus one and one.

Thirty-two directions

My chart has two directions, east and north. A list can be as long as you like.

In the little language model from the attention lesson, every word starts as a list of 32 numbers. That makes each word a place in a space with 32 directions.

Nobody can picture 32 directions. The arithmetic doesn't care. The dot product is still multiply and add, now 32 times over, and the cosine is still a cosine.

Where the words live

Nobody set those numbers by hand. Training moved them, a little at a time, until the model got better at guessing the next word.

So look at who ended up close to whom. The nearest neighbours of kettle are map, shell and crate. Tallow's are rerun, pylon and map.

Across all 46 words, 80 percent have a nearest neighbour of the same kind as themselves: names next to names, things next to things, doing words next to doing words. Shuffle which word owns which list, and it drops to about 23 percent. Before training it was 9 percent.

Trained on hundreds of millions of words, the same idea goes much further. In 2013, researchers reported word lists where king, minus man, plus woman, landed closest to queen, once the three words in the question were left out of the search.

My cone

And then there's my cone.

A cone is cargo. It should sit with the crates. Its nearest neighbours are who, stood and mended.

In our sentences a cone only ever turns up in one phrase: put a cone on. Nothing there marks it as cargo, so the model had no reason to park it with the crates. Where it did park it is something we measured. Why there, we can only guess.

Closeness in these lists comes from how words are used in the training sentences, not from what they mean. Here, with 46 words, you can read every sentence the model learned from.

A flat picture of a big space

One warning about pictures, this lesson's included.

To lay the words out on my flat chart, I squash 32 directions down to the two that keep the most spread. Those two keep 31 percent of it.

On the flat chart, only 52 percent of the words sit nearest to a word of the same kind. In all 32 directions it was 80. Flattening throws a lot of closeness away.

Goodnight

A list of numbers is a place. The dot product mixes how much two places point the same way with how far out they are, and the cosine keeps only the direction.

Next along the coast is my crane. It moves every place on the chart at once, and that is a matrix. Goodnight.

Sources

Every claim in the film, with where it comes from and what that source does not prove. The numbers about the model are computed from its weights, which you can load and check: facts.json, model.json.

What this lesson leaves out

The words here live in a tiny model trained on a made-up language of 46 words. Its neighbours track the job a word does in those sentences, which is exactly what next-word training rewards; they do not show that the model understands anything. The kinds of word (names, things, doing words and so on) were set by us before measuring, and other choices would give other numbers.

The flat chart throws most of the space away: its two directions keep about a third of the spread. Any flat picture of a word space, including the ones in this lesson, should be read with that in mind.

Next along the hill: Matrices move space (F2).