World Models 101
Contents
04

What Is Latent Space?

By Nilushanan Kulasingham

PDF

A camera measures tens of thousands of numbers and the decision needs two or three. What happens at the squeeze between them, and why that narrow point sets the ceiling on everything downstream.

Stand in a doorway and look into a room. Your eyes are taking in something like a hundred million measurements a second. Now decide whether to walk forward. For that decision you need almost none of them.

How far away is the far wall? Is there a way through, and roughly where? That is two or three numbers, and everything else your eyes collected was, for this decision, decoration.

the room those two numbers decode to

the space itself. drag anywhere in it

How far the wall is
0.45
Where the way through is
0.62

Numbers in the picture

74,800

Numbers in the description

2

Fig. 4.1Have a go at this one before reading on. Drag anywhere in the square on the right. Every point in it decodes to a room, and the room is computed from those two numbers rather than looked up. Watch how little drag it takes to change what you would do. The picture is tens of thousands of numbers, and the description that produced it is two.

Those two or three numbers have a name. They are the latent (latent means hidden, or not directly visible. The numbers are never shown to you and nothing labels them, but the picture is what it is because of them) description of the scene. You will meet the phrase "latent space" in nearly every paper from here on.

Somewhere between the camera and the decision there has to be a squeeze, and whatever comes out the other side is all the rest of the system ever gets. That is the case for latents, and the same fact is the case against them.

The squeeze

The architecture is a narrow opening in the middle of a system. One half turns the picture into a short list of numbers. The other half takes the list and tries to rebuild the picture. Train the pair together and there is only one way to succeed: the short list has to carry what the picture was made of.

  • how far the wall is
  • where the way through is
  • which way the camera is tipped
  • gravel on the floor
  • sensor noise
  • how bright it is

Could you decide what to do?

Yes. Two numbers is the whole decision.

What the extra width bought

Nothing wasted yet. Everything through the squeeze changes what you would do.

Fig. 4.2This is that narrow opening with a dial on it. The scene is generated from six numbers and the squeeze keeps the first few. Slide the width up from zero and watch the two readouts underneath. Two numbers in, the decision is settled. The rest is gravel and sensor noise, real but beside the point.

The figure is rigged: the two factors the decision turns on sit in its first two slots. A learned system gets no such ordering for free.

Geoffrey Hinton and Ruslan Salakhutdinov made the case for the squeeze in 2006, in Reducing the Dimensionality of Data with Neural Networks. Hinton taught in Toronto and had stuck with neural nets through the lean years, when most of the field had moved on. Salakhutdinov was his student. They put the paper in Science rather than a machine learning journal, which tells you who they wanted to win over.

Everything since has been that argument with better kit. But a bottleneck creates pressure without naming the answer. Many equally short lists of numbers can rebuild the same pictures, and nothing makes one number mean distance and another mean lighting. You need a bias for that, in the architecture, the data or the task.

Irina Higgins and colleagues at DeepMind, Google's London lab, made the case for such a bias in 2016. The paper was Early Visual Concept Learning with Unsupervised Deep Learning. A good representation, they argued, is one whose directions each mean one thing: turn one number and only the lighting changes.

The room, redrawn from the two numbers

Drag the point, or use the arrow keys

What axis 1 changes

depth and brightness

Sharpness

sharp

Turn one number and two things change. Neither axis has a name yet.

Fig. 4.3This is Higgins's test, with the dial from the next paragraph added. Leave the pressure low and drag the point around the square: the wall moves and the light changes together, so neither axis has a name. Now turn the pressure up and drag again. One direction moves the wall and the other changes the light, and the room has gone soft. Everything here is illustrative.

Their beta-VAE a year later was an autoencoder of this shape with one dial added. The dial (the beta in the name) turns the pressure on the bottleneck up, and past one the axes start lining up with nameable things, the turn of a face or the size of a shape. The same paper shows the cost, which you just saw: press harder and the pictures go blurry.

By 2018 the squeeze was inside a working agent. David Ha and Jürgen Schmidhuber published World Models that year, an agent that learned a driving game through a model of it. Every frame was crushed to thirty-two numbers, and the parts that predicted and chose never saw a pixel.

The same year Danijar Hafner and colleagues built PlaNet, with Ha among the authors. The paper was Learning Latent Dynamics for Planning from Pixels. It squeezed raw pixels the same way, then planned inside what came out, and never rebuilt a frame to decide anything. At decision time the short list was all it had, the bolder of the two designs.

This is the frame as it was recorded. Pick a change and watch the thirty two numbers.

Change

none

Numbers that moved

0 of 32

Steering

0.0 unchanged

Fig. 4.4One frame from the driving game, and the thirty-two numbers it was crushed to. Press a change and watch which of the numbers move and whether the steering moves with them. Move the bend or the car and several do. Reshuffle the gravel or reshape the cloud and the picture is plainly different while not one number moves, so nothing after the squeeze ever hears about it. The numbers are illustrative.

Then in 2019 Francesco Locatello and colleagues closed the question Higgins had opened. Pulling the hidden factors apart, one per axis, is called disentanglement. With no labels and no built-in bias, they proved, it cannot be done. For any squeeze whose axes mean something, another draws the same pictures just as well with axes that mean nothing.

They then trained thousands of models, and which axes you got came down mostly to the random seed. The paper was Challenging Common Assumptions in the Unsupervised Learning of Disentangled Representations. It took the best paper award at the ICML conference that year. A lot of latent-space writing has not caught up with it.

Press Retrain. Watch the rooms on the right and the arrows on the left.

Redraw of the nine rooms

identical every time

What axis 1 means

how far the wall is

Fig. 4.5Press Retrain a few times. Each press is a fresh random seed, and each one hands you a different pair of axes over the same rooms. Read the two lines underneath: the pictures come back the same every time, and what the first axis means does not. That is Locatello's result, and it is also why Figure 4.2 had to be rigged. Illustrative.

Look at who was unaffected. Ha and Schmidhuber's agent never needed its thirty-two numbers to mean anything a person could name, and neither did PlaNet's planner. The squeeze carried on, because the agents built on it had only ever asked that it keep what the next step turns on.

A place, not a list

Those numbers are coordinates. In a latent space that training has shaped well, they name a point with useful neighbours, directions and distances. Nothing guarantees that; a plain autoencoder can learn a twisted lookup table instead.

Once it has been shaped, you can do things there that make no sense in pixels. You can ask what is nearby, move in one direction and watch the world change smoothly in one way, or take two rooms and stand between them. That last one is the figure below.

one room

average the two pictures

another room

average the two numbers, then decode

Is the blended picture a room?

No. It is two rooms at once, which is not a thing you could walk into.

Is the decoded one a room?

Yes, everywhere along the slider. Every point in that space decodes to one.

Fig. 4.6Both rows are real output from this constructed decoder. Drag the blend slider and watch the two middle panels. Averaging two pictures gives you both rooms at once, faintly. Averaging the two coordinates and decoding stays among the rooms the decoder has learned to draw. A real latent space only does this if training has made the region between examples mean something.

Halfway between two pictures is a ghost, and halfway between two descriptions is a room. That matters because prediction, planning and search all move somewhere you have not been, and if every step lands on nonsense none of them work.

What makes one good

Being small is not the goal in itself. A single number is very small and useless. What you want is that the things which matter are easy to get at, and the things that do not are gone. Yoshua Bengio, Aaron Courville and Pascal Vincent set that down in 2013, in a survey called Representation Learning: A Review and New Perspectives.

The three were colleagues in Montreal. Bengio had kept a neural network lab going through the same lean years as Hinton, and would later share the Turing Award with Hinton and Yann LeCun. The survey is still the best single statement of what a learned representation is for. So let's take three tests from it, in rough order of how often they fail.

Does it keep what the future turns on? Take two situations that lead to different outcomes and land on the same point: nothing downstream can tell them apart. This is the failure that shows least, because the reconstructions can look fine while it happens. Ha and Schmidhuber's thirty-two numbers were trained only to redraw frames, and the authors flagged the risk themselves.

Scored on

Which way will the ball go?

press a corridor first

Where the two land

press both to see

Press A, then B, and watch the square.

Fig. 4.7Two corridors, and the only difference is which way the ball is rolling. Press each one in turn and watch where it lands in the square: the same point, because a squeeze scored on redrawing the frame found nothing worth keeping in a few pixels of motion. Now look at the redraw, which is fine, and at the question underneath, which cannot be answered. Flip to scoring on the next frame and the two land apart. Illustrative.

Do nearby points mean nearby things? A space where a small step can land anywhere is just a lookup table. Smoothness lets you move through it on purpose, and it is what the VAE's noise was built for. As you saw in Figure 4.6, it is also what lets you stand between two rooms.

Is it easy to predict forward? A description can be perfectly faithful and still be a nightmare to run forward in time. The reason anyone compressed was to get something they could roll forward cheaply.

What the squeeze costs

Rebuilding the picture is a proxy, and proxies drift. The test asks whether the short list can redraw what the camera saw. What you wanted to know is whether it kept what the decision turns on.

The things that take up the most pixels are usually not the things that matter. A description scored on rebuilding pixels spends itself on texture and weather, and loses the small fast object you needed to avoid. Figure 4.2 was rigged to hide this, so let's take the rigging off.

  • the wall
  • the sky
  • the light
  • the gravel
  • the cyclist

Nothing came through.

Redraw score

none

The cyclist

gone

Figure 4.2 kept the decision's two factors first. A redraw score keeps the biggest first.

Fig. 4.8The same kind of squeeze as Figure 4.2, but this time the slots go to whatever covers the most pixels, which is what a redraw score rewards. Slide the budget up and watch the order things come through: the wall, the sky, the light, the gravel, and only then the cyclist. Now read the two lines underneath. The redraw score is high long before the one thing you needed arrives. Illustrative.

The second cost is subtler, and I think more serious. Anything the squeeze drops is gone for good from that point on. Everything after the bottleneck works from the short list and nothing else.

That choice is made early, by a part of the system that has no idea what task is coming, and it sets the ceiling on everything after it.

That is why the argument since has been about the middle of the pipe. PlaNet trained the squeeze together with the forward model, and LeCun's JEPA line (chapter 7) asks whether to rebuild pixels at all.

Hopefully this chapter helped. There is a short quiz below if you want to check the ideas stuck. If I have got something wrong, or you know a better source than the ones I used, the About page has a corrections section and I would be glad to hear from you.

Try it

1 / 8Score 0

A camera hands you tens of thousands of numbers per frame. Deciding whether to walk forward needs two or three. What is the bottleneck for?

Pick one

Fig. 4.9Eight questions on the squeeze and the space it produces. The last two are about the parts that are easy to nod along to and hard to keep hold of.

Everything here has happened one moment at a time. A picture goes in, a short description comes out, and nothing has moved yet.

Sources

  1. Challenging Common Assumptions in the Unsupervised Learning of Disentangled RepresentationsLocatello et al., 2019The result that prevents a bottleneck from being magic: without inductive biases, unsupervised disentanglement is impossible in general and the axes are not identifiable.
  2. Auto-Encoding Variational BayesKingma & Welling, 2013The variational autoencoder. The noise it adds is the reason the space ends up navigable instead of a scatter of unrelated addresses.
  3. Reducing the Dimensionality of Data with Neural NetworksHinton & Salakhutdinov, 2006The bottleneck argument before it had modern machinery behind it. Paywalled.
  4. World ModelsHa & Schmidhuber, 2018Every frame crushed to thirty-two numbers, and everything after that working only from those. The clearest example of the squeeze in a working agent.
  5. Learning Latent Dynamics for Planning from Pixels (PlaNet)Hafner et al., 2018Encodes pixels to a compact state and then plans in it, without ever rebuilding a frame in order to decide anything.
  6. Neural Discrete Representation Learning (VQ-VAE)van den Oord et al., 2017What happens when the short list is forced to be a handful of discrete symbols rather than continuous numbers.
  7. beta-VAEHiggins et al., 2017Turn the pressure on the bottleneck up and the axes start to line up with things you can name. Also a good demonstration of what that costs.
  8. Early Visual Concept Learning with Unsupervised Deep LearningHiggins et al., 2016The argument that a good representation is one whose directions mean something, written before it was a crowded field.
  9. Representation Learning: A Review and New PerspectivesBengio, Courville & Vincent, 2013Still the best single statement of what a learned representation is supposed to be for, and of how many of these questions were already open.
Fig. 4.10I've ordered these for someone building on this rather than for historical completeness.

This chapter is free and open source. A star helps the next person find it.

Star on GitHub21
Star on GitHub21