SandHouse
Pages and contents

C-SWM

Contrastive Learning of Structured World Models

โ‹ฎโ‹ฎ
Field
Object-centric world models, representation learning
โ‹ฎโ‹ฎ
Authors
Thomas Kipf, Elise van der Pol, Max Welling
โ‹ฎโ‹ฎ
Year
2020
โ‹ฎโ‹ฎ
Venue
ICLR 2020
โ‹ฎโ‹ฎ
Link / arXiv
https://arxiv.org/abs/1911.12247
โ‹ฎโ‹ฎ
Code
https://github.com/tkipf/c-swm
โ‹ฎโ‹ฎ
Tags
#world-models #object-centric #contrastive-learning #graph-neural-networks #representation-learning

Problem

A useful world model should represent an environment in terms of the entities that actually determine its dynamics. In a scene containing several blocks, for example, it is useful to represent the blocks separately and model how their movements interact rather than compressing the entire image into one unstructured latent vector. Such an object-oriented representation gives the transition model a strong compositional bias: the same learned rule for moving a block can potentially apply to many blocks and to configurations that were never observed during training.

Earlier object-centric models generally learned these representations through pixel reconstruction. An encoder compresses an observation and a decoder is trained to reproduce the original image. The problem is that reconstruction rewards the representation for preserving whatever is visually prominent, rather than specifically preserving what matters for predicting dynamics. A model may spend capacity representing a detailed but static background while ignoring a tiny object whose motion is crucial for predicting the future. It also creates a tension between forcing a clean structured latent space and retaining enough information to reconstruct every pixel accurately.

C-SWM, or Contrastively-trained Structured World Model, instead learns its latent representation directly from transition prediction. The model observes offline state-action-next-state tuples and learns a latent space in which the current state plus the predicted effect of an action should lie close to the actual next state. Randomly sampled states should remain far away. The authors combine this contrastive objective with an explicitly object-factorized latent state and a graph neural network transition model, allowing object representations to emerge from pixels without object labels.

Method

Latent State and Transition Learning

The training data are an offline experience buffer โ„ฌ=(st,at,st+1)t=1T . An encoder E:Sโ†’Z maps the observation to a latent state zt=E(st) . A transition model T:Zร—Aโ†’Z predicts the change caused by action at , rather than directly predicting the entire next representation:

z^t+1=zt+T(zt,at).

The additive form is important. It treats actions as state-dependent translations through latent space. For example, if zt represents the current locations of several blocks, T(zt,at) should encode the change produced by moving one block while accounting for whether another block prevents the movement.

The energy of a genuine transition is its squared Euclidean prediction error:

H=d(zt+T(zt,at),zt+1).

A good representation and transition model therefore assign low energy to transitions that actually occurred.

Contrastive Learning

Only minimizing H has a trivial solution: the encoder could map every state to the same point. Every transition would then be predicted perfectly without representing anything about the environment. C-SWM prevents this collapse using negative states sampled randomly from the experience buffer.

Let s~t be a randomly sampled observation and z~t=E(s~t) . The training objective is

โ„’=d(zt+T(zt,at),zt+1)+maxโก(0,ฮณโˆ’d(z~t,zt+1)).

The first term pulls the predicted next representation toward the real next representation. The second pushes an unrelated state at least margin ฮณ away from zt+1 . The authors use ฮณ=1 .

This objective is adapted from TransE, a method for knowledge-graph embeddings. TransE models a relational fact such as subject + relation โ‰ˆ object. C-SWM makes the analogous identification state+action effectโ‰ˆnext state . Unlike a standard autoencoder, the representation is never directly asked to preserve pixels. The encoder therefore has an incentive to retain distinctions that matter for predicting transitions while discarding information that does not help distinguish one transition from another.

Object-Oriented Factorization

C-SWM imposes a second major inductive bias by decomposing the latent state into K object slots:

Z=Z1ร—โ‹ฏร—ZK,zt=(zt1,โ€ฆ,ztK).

The action is similarly factorized as at=(at1,โ€ฆ,atK) . In the grid-world experiments, an action is attached to the particular object being manipulated, while objects receiving no action receive a zero action vector.

The complete encoder contains two stages:

stโ†’Eext(mt1,โ€ฆ,mtK)โ†’Eenc(zt1,โ€ฆ,ztK).

Eext is a CNN whose final layer contains K feature maps. Each feature map mtk acts as an unsupervised object mask or object slot. Each mask is flattened and processed by the same MLP encoder Eenc , giving ztk=Eenc(mtk) with ztkโˆˆโ„D .

Weights are shared between object slots. This encourages the same latent coordinate system to be reused for different objects. Importantly, there is no supervision saying which pixels belong to a block or which slot should represent which object; the object decomposition is learned because it makes the transition-prediction objective easier.

The architecture in Figure 1 can be summarized as:

```mermaid
flowchart LR
S[Image s_t] --> CNN[CNN object extractor]
CNN --> M[Object masks m_t^1 ... m_t^K]
M --> ENC[Shared MLP object encoder]
ENC --> Z[Object states z_t^1 ... z_t^K]
Z --> GNN[GNN transition model]
A[Action a_t] --> GNN
GNN --> DZ[Predicted changes ฮ”z_t^k]
DZ --> P[Predicted next latent state]
P --> L[Contrastive loss]
N[Encoded true and negative states] --> L
```

Relational Transition Model

Objects cannot always be modeled independently. If a block attempts to move into a location occupied by another block, its transition depends on the state of that second object. C-SWM therefore treats the object slots as nodes in a fully connected graph and uses a GNN to model their interactions.

The transition model is

ฮ”zt=T(zt,at)=GNNโก((ztk,atk)k=1K).

For each pair of objects i and j , an edge network produces an interaction representation:

et(i,j)=fedge([zti,ztj]).

Each object then receives the sum of incoming interaction messages. Its predicted change is

ฮ”ztj=fnode([ztj,atj,โˆ‘iโ‰ jet(i,j)]).

The next object representation is zt+1jโ‰ˆztj+ฮ”ztj . Both fedge and fnode are MLPs whose parameters are shared across objects and object pairs.

This sharing is what makes the model compositional. The network does not need to separately learn the physics of "red block colliding with blue block" and "yellow block colliding with green block." Instead, the edge function can learn a general interaction rule over their latent states.

The fully connected graph requires O(K2) pairwise interactions. The authors suggest that nearest-neighbor connectivity in latent space could reduce this toward linear complexity for environments with many objects.

Object-Level Contrastive Objective

The original contrastive loss is finally factorized across objects. Positive energy becomes the average predicted transition error across all slots:

H=1Kโˆ‘k=1Kd(ztk+Tk(zt,at),zt+1k).

The energy of a randomly sampled state is

H~=1Kโˆ‘k=1Kd(z~tk,zt+1k).

The final C-SWM loss is

โ„’=H+maxโก(0,ฮณโˆ’H~).

All major components therefore train together from the same signal: the CNN must discover useful objects, the MLP must encode their relevant properties, and the GNN must learn their interaction dynamics. No decoder or object labels are required.

Results

The authors test whether C-SWM can simultaneously discover objects, predict their future latent states, and generalize to unseen configurations. Experiments include 2D Shapes, 3D Blocks, Atari Pong, Space Invaders, and a continuous three-body gravitational simulation. Training experience is generated by random policies, and evaluation uses held-out trajectories and environment configurations.

Rather than evaluating reconstructed pixels, the authors evaluate predictions by ranking states in latent space. After rolling the transition model forward, the predicted representation is compared against the true next representation and a collection of reference states. Hits@1 (H@1) measures how often the correct state is ranked first, while Mean Reciprocal Rank (MRR) gives larger scores when the correct state appears close to the top of the ranking.

Multi-Step Prediction

A useful summary is the 10-step H@1 result:

Environment
C-SWM
World Model AE
World Model VAE
โ‹ฎโ‹ฎ
2D Shapes
99.9
6.5
1.4
โ‹ฎโ‹ฎ
3D Blocks
99.9
4.0
7.2
โ‹ฎโ‹ฎ
Pong
11.5 with K=1
1.2
1.0
โ‹ฎโ‹ฎ
Space Invaders
11.8 with K=5
3.8
1.0
โ‹ฎโ‹ฎ
3-Body Physics
75.5
67.9
23.6

The contrast is strongest in the structured grid worlds. C-SWM predicts almost perfectly ten steps into the future, while autoencoder-based models perform well at one-step prediction but deteriorate severely as errors compound. The learned latent spaces visibly reproduce the underlying grid geometry even though position is never provided as supervision. Figure 3 shows that the learned representation is essentially a rotated or reflected version of the true spatial grid.

The 3-body experiment also demonstrates that the method is not restricted to discrete grid positions. Object slots learn representations tracking continuous location and velocity, and predicted trajectories reproduce the circular structure of the physical dynamics. Performance still deteriorates for trajectories that strongly differ from those represented in the training set.

What the Ablations Show

The ablations are especially informative because all three major ingredients matter.

Removing the GNN interactions and replacing the transition model with independent object-wise MLPs reduces 10-step H@1 from 99.9 to 89.7 on 2D Shapes and 86.0 on 3D Blocks. The independent model cannot correctly handle situations where the transition of one object depends on another object, such as a blocked movement.

Removing object factorization is substantially worse. The model must encode the entire scene in one latent vector and has difficulty recombining familiar object states into unseen global configurations. This supports the paper's central argument that factorization provides useful compositional generalization.

Replacing the contrastive objective with pixel reconstruction is most damaging. Ten-step H@1 falls to 1.4 on 2D Shapes and 3.1 on 3D Blocks. Appendix A.1 visualizes why: the pixel-trained model loses the clean, regular latent transition geometry learned by C-SWM. Pixel reconstruction can produce visually reasonable representations without producing a latent coordinate system in which simple transition rules generalize.

The robustness experiment in Appendix A.5 gives another useful result. Adding a no-op action has essentially no effect: 10-step H@1 remains 99.9. Adding an independently moving random object reduces it to 90.4, exposing the weakness of the model's deterministic transition assumption.

Object Discovery

The learned CNN filters correspond to individual objects in the simple structured environments despite receiving no segmentation labels. Furthermore, the latent transition graph for each object is nearly identical even when the objects look different. This indicates that weight sharing successfully encourages a common representation of object dynamics rather than separate representations tied to appearance.

The behavior is less clean on Atari. Pong performs best with only K=1 , while Space Invaders benefits from more slots. The learned slots are also less interpretable because objects are not exchangeable, one action can indirectly affect many visible entities, and many objects share identical appearances. Thus the impressive object-discovery results are strongest in environments whose structure matches the model's object-slot assumptions.


The largest architectural limitation is instance disambiguation. The simple feed-forward object extractor relies on different objects having distinguishable visual features. It cannot reliably assign two visually identical instances to separate persistent slots. The authors point toward iterative approaches such as MONet, dynamic routing, iterative inference, or sequential masking as possible solutions. This is particularly relevant in environments such as Space Invaders containing many visually identical objects.

C-SWM also assumes deterministic, Markovian dynamics. Its transition model produces one deterministic next latent state, so it cannot properly represent inherently stochastic futures. The model also assumes that the current state and action contain all information required to predict the next state. Partially observable environments would therefore require a memory mechanism such as an RNN or another history-dependent state representation.

Object discovery is not completely stable across random initializations. The authors find it highly stable in the controlled grid-world environments but more initialization-dependent in Atari and the three-body simulation. Choosing the number of object slots K is another practical issue: too many or too few slots can hurt performance, and the architecture does not naturally learn that some slots should remain empty.

C-SWM is closely related to earlier structured dynamics models such as Interaction Networks and Neural Relational Inference, which likewise use graphs to model object interactions. Its main distinction is that the structured object state is learned directly from pixels without object supervision and without requiring a pixel reconstruction loss. It is also related to object-centric generative approaches such as MONet and COBRA, but the paper deliberately replaces their reconstruction-driven representation objective with transition-based contrastive learning. The contrastive objective itself is inspired by TransE and relational graph embeddings, transferring the idea of scoring valid versus corrupted relational triples to state-action-state transitions.

The most useful sections for a deeper read are Sections 2.2โ€“2.3, which contain the contrastive objective and complete object-factorized architecture, Section 4.6 for the main ablations and quantitative evidence, and Section 4.7 / Appendix A for the limitations and failure cases.