Imagine Before You Act: World Models — Part 0: What Is a World Model?
November 21, 2026 · 8 min read · World Models, Reinforcement Learning, Machine Learning
Before a basketball player takes a free throw, they often pause and picture the shot: the arc, the ball dropping through the rim. They aren't simulating every muscle fibre or the air pressure in the ball. They run a quick, rough version of the future in their head, check that it ends well, and then shoot.
A world model is the machine-learning version of that pause. It's a model, learned from data, that predicts what happens next, especially what happens next if I do this. An agent with a world model can try things out in its head before trying them for real.
This post covers four things every later part relies on:
- the three different things people mean by "world model",
- the four-box picture that organizes the whole series,
- GapWorld, the small environment we use in every hands-on part,
- notation, and a first taste of "imagine, then act" in twenty lines of code.
You need some comfort with Python and NumPy, and a rough idea of what a neural network is. No reinforcement learning background is needed. Every term is explained when it first appears.
1. Three meanings of "world model"#
The phrase is used for three related but different things. It's worth separating them now, because papers rarely say which one they mean.
| Meaning | What it is | Famous examples | Parts |
|---|---|---|---|
| A dynamics model for control | Learns how the world responds to actions, so an agent can plan or practise with it | PETS, PlaNet, Dreamer, MuZero, TD-MPC | 1–4 |
| A generative simulator | Generates the next video frame from the current ones and your action, so a person or an agent can "play" it | GameNGen, DIAMOND, Genie, Cosmos | 5 |
| An implicit world model | The internal picture of the world that a predictor builds without being asked to, such as a language model tracking a game board | Othello-GPT | 6 |
All three predict the future. They differ in what they predict (a compact state, a full image, or nothing explicit at all) and in who uses the prediction (a planner, a person, or the model itself).
2. Why bother?#
Why not just learn by trial and error in the real world, as many reinforcement learning (RL) agents do? Four reasons:
- Sample efficiency. Real experience is slow, expensive or dangerous to collect: a robot arm wears out, a car crashes. A model lets one real experience be reused for thousands of imagined ones.
- Planning. With a model, an agent can compare several possible futures before committing, instead of only learning habits from past rewards.
- Safety. You can test a risky action in imagination first. You can also ask the model "what would happen if...?" about situations you never want to see for real.
- Understanding. A model that predicts well has captured something about how the world works, and you can inspect it (Part 6 does exactly this).
There is a catch, and it is the theme of the whole series: the model is never perfect, and an agent that trusts it too much will exploit its mistakes. Part 1 shows a planner whose small modelling errors steer the puck into a dead end it cannot plan its way out of. Part 2 shows an agent that learns to "win" inside its own dream by making the puck vanish. Learning to live with an imperfect model is most of the craft.
3. The four-box picture#
Every method in this series fits into one diagram:
- Observe. The raw input: a camera image, a list of sensor readings, a sequence of moves.
- Encode. Squeeze the observation into a compact state : a short vector that keeps what matters and drops the rest. What to keep is a real decision, and Part 4 is about it.
- Predict. The heart of a world model: given the state and an action , predict the next state. Repeat this, feeding each prediction back in, and you get an imagined rollout, a whole possible future.
- Use. Do something with the imagined futures: plan (search for good actions, Parts 1 and 3), learn (train a policy on imagined experience, Parts 2 and 3) or simulate (show the future to a person, Part 5).
- Decode (optional). Turn a predicted state back into an image. Some world models need this, some never do, and whether they should is one of the field's big debates.
Each part opens by saying which box it changes. The question that keeps coming back is what should the model predict? Every pixel? A compact state? Only the things that matter for reward? Each answer has a cost, and the parts show them one at a time.
ELI5: the free-throw shooter observes the hoop, keeps only what matters (distance, angle, not the colour of the seats), imagines the ball's flight for a given push, and uses that to adjust the shot. They never need to picture the seats, which is why skipping "decode" can be fine.
4. GapWorld: one small world for the whole series#
To compare methods fairly, Parts 1–5 use one small environment, built for this series. We call it GapWorld:
- A puck (blue) starts somewhere in the left half of a square room. Each step, you push it with a 2-D force .
- The puck has momentum and friction: it keeps sliding after a push and slows down over time. It bounces to a stop against the walls.
- A wall splits the room, with one gap. The goal (green) is on the other side, not in line with the gap, so a straight push doesn't work.
- The reward at each step is minus the distance to the goal: the closer, the better. An episode lasts 50 steps and counts as a success if the puck ever gets within 0.06 of the goal.
- In Parts 4 and 5, a fly (orange) also buzzes around the room at random. It has nothing to do with the task, which is exactly why it's useful.
The agent can see GapWorld two ways: as the state , four numbers with the puck's position and velocity (Part 1), or as a 64×64 image (Parts 2–5), which is closer to how a robot sees the world through a camera.
GapWorld is tiny on purpose. Each part trains its models in minutes to about half an hour on a single GPU (most of Part 1 also runs on a laptop CPU). That makes every result reproducible. It also means the systems we build are miniature versions of the ones in the papers. Each part says plainly what was scaled down.
The right panel above shows the core idea in one picture. Each grey line is one imagined future, from a different random sequence of pushes. Most bump into the wall. If you can imagine futures, you can pick the one that ends at the goal (blue) and do that.
5. Notation#
| Symbol | Meaning |
|---|---|
| observation at step (an image, or the state itself) | |
| true state of the environment (in GapWorld: position and velocity) | |
| the model's compact latent state, learned from observations | |
| action at step (in GapWorld: a push, two numbers in ) | |
| reward (in GapWorld: minus the distance to the goal) | |
| the true dynamics: how the world moves on | |
| or | a learned dynamics model with parameters |
| horizon: how many steps ahead the model imagines | |
| policy | a rule (often a neural network) that picks actions |
| rollout | a sequence of states produced by repeatedly applying a model (or the world) |
6. Imagine, then act, in twenty lines#
Here is the whole idea in code. To pick each push, we imagine 200 random futures 20 steps ahead, score each by how close it stays to the goal, and take the first push of the best one. Then we do it all again at the next step. For now the "model" is the real simulator, g.dynamics. From Part 1 on, it will be a learned network.
import numpy as np
import gapworld as g # scripts/blog/world_models/gapworld.py
rng = np.random.default_rng(0)
def imagine_then_act(s, model, n_futures=200, horizon=20):
"""Random shooting: imagine n random futures, keep the first push of the best one."""
plans = rng.uniform(-1, 1, (n_futures, horizon, 2))
sims = np.repeat(s[None], n_futures, 0)
cost = np.zeros(n_futures)
for t in range(horizon):
sims = model(sims, plans[:, t])
cost += np.linalg.norm(sims[:, :2] - g.GOAL, axis=1) # distance to goal, summed
return plans[cost.argmin(), 0]
wins = 0
for episode in range(50):
s = g.reset(1, rng)[0]
for t in range(g.EPISODE_LEN):
a = imagine_then_act(s, g.dynamics) # the "model" is the real simulator here
s = g.dynamics(s[None], a[None])[0]
wins += g.success(s[None])[0]
print(f"reached the goal in {wins} of 50 episodes")
# reached the goal in 37 of 50 episodes
Even this crude search, with no learning at all, reaches the goal 74% of the time, where random pushing almost never does (2% in Part 1's test). Two questions are left, and they drive the rest of the series. Where does the model come from when we don't have a simulator? And what happens when it's wrong?
7. The plan#
| Part | Title | Box it changes | The question it answers |
|---|---|---|---|
| 1 | Learn the Dynamics, Then Plan | predict + use | Can a learned model replace the simulator above? What goes wrong? |
| 2 | Learning in a Dream | encode + use | Can an agent learn entirely inside its own imagination, from pixels? |
| 3 | Latent Dynamics: PlaNet and Dreamer | predict | How do modern agents build a compact, uncertain state that's good for imagining? |
| 4 | What Should a World Model Predict? | encode / decode | Pixels, rewards and values, or embeddings? What does each one keep? |
| 5 | Generative World Models: Playable Video | decode | How do you generate the next frame, and why do long rollouts drift? |
| 6 | Do Language Models Have World Models? | implicit | Does a transformer trained only on game moves build a picture of the board? |
| 7 | Evaluating World Models, and a Checklist | all | When is a world model good enough? |
Recap#
- A world model is a learned model that predicts what happens next, especially as a result of an action, so an agent can try things in imagination.
- "World model" means three things: a dynamics model for control, a generative simulator you can play, or the implicit model a predictor builds inside.
- Every method fits the four boxes observe → encode → predict → use, with an optional decode. The recurring question is what to predict.
- GapWorld, a puck pushed through a gap in a wall to a goal, is the testbed for Parts 1–5.
- The central difficulty: models are imperfect, and agents exploit their errors.
Next up — Part 1: Learn the Dynamics, Then Plan. We replace the real simulator with a neural network trained on random experience, plan with it, and watch where it fails: errors that compound over time, a planner that leans on a wall it thinks is soft, and how an ensemble of models can tell us when not to trust them.
