Tokenized Game and Environment Models › From frames to environment tokens
World Models HandbookAll chapters Tokenized Game and Environment Models › From frames to environment tokensOne section · Sections in this chapter3 / 11 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
The starting point is a trajectory: a sequence of interactions with an environment. If we write the observation, action, reward, and termination flag at time , the natural notation for a trajectory is
where:
- : the rendered observation at time in the image-based setting studied here. It may be an RGB or grayscale frame, or a stack of frames, possibly with a HUD overlay. Other interfaces, such as RAM observations, require different notation.
- : the discrete control chosen at time . In the Arcade Learning Environment, the full discrete Atari action set has 18 controls; a game's reduced action set may contain far fewer. A multi-game dataset may use a union of the included games' actions, with each game using its applicable subset.
- : the reward received after the transition into time . Depending on the game, rewards may be sparse or frequent; pickups, scores, and deaths are possible reward events.
- : the termination flag for the transition into time . When , the episode ends; a subsequent reset begins a new episode.
- : the length of the episode.
We use for the observation and action indices and for the reward index on purpose. Reward is associated with the transition after action ; in a partially observed environment it may depend on hidden state, not solely on the two rendered frames. Part II, Ch 1: Markov and Partially Observable Decision Processes used this indexing convention. A model that misaligns rewards with actions can learn the wrong decision signal even if frame reconstruction looks good.
The tuple above is a single trajectory. The index labels the observation, labels its reward and termination, and the episode ends at , so a trajectory contains observations and action-reward bundles. Any model we build will be asked to predict the next element of this sequence given the preceding ones.
It is worth pausing on how much structure the raw trajectory leaves implicit. The observation is high-dimensional and redundant. The action is a small discrete label with no meaning until we connect it to an effect. The reward and termination carry explicit task feedback, yet a naive "predict the next frame" objective does not train separate predictions for them. They may also be rare compared with ordinary visual changes. The rest of this section is about the first compression step, and the following section is about the second.
Why tokenize at all
A preprocessed RGB frame contains channel values; this is not the native resolution of every game interface. A sixty-second clip at 30 frames per second has frames. Feeding all pixel values directly into a sequence model is costly, while adjacent frames share much of their content. The model may devote capacity to predicting unchanged walls instead of small events that alter the game's state.
A tokenizer can map each observation (or short clip) into a shorter sequence of discrete symbols. If the token count is reduced by relative to a specified raw-pixel tokenization, the dynamics model sees roughly one-hundredth as many symbols per frame. Its predictions become class labels rather than continuous intensities. A softmax over those labels represents a categorical distribution over code outcomes; whether that distribution is calibrated must be tested separately.
An environment tokenizer maps an observation, or a short temporal window of observations, to a sequence of discrete codes with each . A corresponding decoder attempts to reconstruct an observation from the codes. The quadruple is the tokenization scheme. The dynamics model is trained on the sequence of rather than on .
The token count per frame and vocabulary size are two design knobs. is the number of codes emitted per observation; is the number of entries in the shared vocabulary. At a fixed token-count context window, increasing shortens the frame history that fits. Increasing at fixed does not change that token count, but changes the information capacity per token and the model's embedding and output-classification costs. These are separate tradeoffs, not interchangeable ways of setting the context length.
The combinatorial space of possible code sequences grows with both knobs. An autoregressive factorization is one tractable way to model a distribution over that space; it is not the only structured alternative.

The tokenizer can be one of several kinds:
- Deterministic and fixed: a hand-designed encoder, such as a color histogram or a downsample plus palette quantization.
- Deterministic and learned: a VQ-VAE or similar autoencoder whose encoder is trained to assign a specific code to each input under a nearest-neighbor rule.
- Stochastic and learned: a variational autoencoder with a discrete or relaxed-discrete bottleneck, where the encoder outputs a distribution over codes.
- Temporal: a video tokenizer that maps a short clip into a sequence of codes, so the dynamics model predicts a chunk of frames at once.
Which one you pick changes what the dynamics model sees. If the tokenizer is trained separately and frozen, the dynamics model inherits its quirks. If they are trained jointly, the dynamics objective can shape the tokenizer to keep information that matters for prediction, which is sometimes good and sometimes leads to degenerate codes. We will come back to this tradeoff.
A concrete tokenizer route: vector quantization
Vector quantization is a common discrete-tokenizer design. Walking through its codebook lookup helps explain representation errors that matter later in this chapter.
Suppose an encoder maps an observation to a spatial feature map of shape : . Think of it as a grid of vectors, each of dimension . We maintain a codebook of vectors . For each spatial position , we replace the feature vector with the nearest codebook entry. This is the quantize step, and it is the only place where the continuous encoder output becomes a discrete symbol:
where:
- : the encoder output at spatial position , a vector in that we want to quantize
- : the -th entry of the learned codebook, a representative vector in the same -dimensional space
- : the squared Euclidean distance between the encoder output at position and codebook entry , which measures how close the two vectors are
- : the index of the nearest codebook entry, an integer in that becomes the token for position
- : the quantized feature at position , obtained by looking up the nearest codebook vector , so the feature map is replaced by codebook entries before decoding
The discrete codes are the tokens. The decoder reconstructs an observation from the quantized features: . Training minimizes a reconstruction loss plus a commitment term that keeps the encoder close to the codebook and a codebook term that keeps the codebook close to the encoder. The two auxiliary terms, and the straight-through estimator that lets gradients pass through the non-differentiable , are engineering details; the important point for us is that the tokens are category labels, not numbers, and that the codebook is a jointly learned dictionary. A code is not "a little bit like" another code in the way two nearby real numbers are close; the codes are unordered categories, and the model has to learn any similarity structure between them from data.
The quantization step partitions the encoder's feature space by nearest codebook vector. The figure below shows the assignments; it does not depict codebook collapse, because every illustrated entry is used.

Several knobs matter for the downstream world model:
- Codebook size . A small codebook can merge visually different inputs. A very large one increases the output vocabulary and may leave some codes poorly sampled; the actual usage distribution must be measured.
- Tokens per frame . A larger can preserve more spatial detail, but always lengthens the dynamics sequence. Whether it retains task-relevant detail depends on the encoder and its training objective. The longer sequence also uses more of the sequence model's context window.
- Codebook collapse. During training, only a small fraction of the codebook may receive gradient, so most codes go unused. The effective vocabulary shrinks, and the tokenizer starts aliasing inputs that should have been distinct.
- Reconstruction vs. task sufficiency. The training objective rewards reconstructing the whole frame accurately. It does not care whether the reconstructed frame preserves the small detail that decides the game.
That last point deserves an example. Consider a key that occupies a pixel region on an screen. It covers pixels out of , or about of the pixels. A tokenizer trained to minimize mean squared reconstruction error may devote more capacity to large, frequently visible regions such as the floor and walls than to this small key. But the game cares intensely about the key: its presence can determine whether the door opens. The tokenizer can have low average reconstruction error and still lose a variable needed for this decision. The reconstruction loss and the control task measure different things.
This is why we should not equate reconstruction error with world-model quality. As we noted in Part III, Ch 2: Sufficient State and State Abstraction, a statistic sufficient for painting need not be sufficient for decisions. A tokenizer can discard a feature needed for control while still reconstructing most pixels well. That loss can propagate downstream and may escape reconstruction-only checks; targeted event probes or control tests can reveal it earlier than a failed deployment.
A token ID is a symbol from a learned dictionary. It has no intrinsic causal interpretation. A Markov state makes earlier history unnecessary for predicting the future once the current state and relevant actions are given. An object is a persistent entity in the world with identity, properties, and relations. The three can be aligned, but they are not the same thing, and a tokenized model does not automatically produce either states or objects. This is a recurring source of confusion in the literature.
A tokenized frame is an encoding that may be learned and lossy. Whether it is useful depends on the downstream task; reconstruction loss alone cannot settle whether decision-relevant distinctions survived.