SandHouse
Pages and contents

PHWM v2

PHWM, second statement

Written 2026-08-28 after the MiniGrid and crafting-grid campaigns. This is the theory as it stands now, with the architecture that implements it and the mathematics written out. Where the first statement (phwm.md) said something the experiments contradicted, this file says what replaced it and points to the evidence. Chronology and numbers are in notes/experiment-notes-1..4.md; the code is phwm/full_model.py, phwm/craft_env.py, phwm/craft_experiment.py, and phwm/craft_policy.py.

Summary. A world is a set of object tokens. A world model predicts each token's next state by attending to the other tokens. Schemas are small reusable rules that predict how one token changes given its relations to the tokens the world model attended to. Binding (which tokens a rule applies to) is inherited from the world model's attention; consequences are predicted as changes; the rule's inputs are relations, not object identities. What this achieves: reuse of a learned rule on new layouts and on new combinations of known objects. What it does not achieve yet: extending a rule along an ordinal scale to a pair of objects never seen together, and rules that relate one event to another.

1\. Setting

An episode is a sequence of observations ot and actions at . Each observation is a set of N tokens, one per object slot:

ot=xt,1,…,xt,N,xt,i∈0,1F

Each token is a concatenation of one-hot fields: the object kind ΞΊi∈1,…,C , a state field ni∈0,…,Sβˆ’1 (an inventory count, or open/closed), the position relative to the agent, the absolute position, and a flag Ο†i∈0,1 marking the object the agent faces. Inventory items are tokens whose state field is their count. The agent takes one of A primitive actions, at∈1,…,A . Nothing is rewarded during representation learning.

A training row is a triple (xt,at,xt+1) . For each token the change indicator is

Ο‡i=[(ΞΊt+1,i,nt+1,i)β‰ (ΞΊt,i,nt,i)]

so that a row with βˆ‘iΟ‡i=0 is a row on which nothing happened.

Event time. Most steps change nothing but the agent's position. The steps that matter are attempts: atβˆˆπ’œatt=interact,place,craftp,wait . The world model and schemas are trained only on rows with atβˆˆπ’œatt . Movement between attempts is the job of a separate goal-conditioned policy (section 6). This is the temporal abstraction: abstract time advances once per attempt.

The crafting grid. Objects have tiers. Resources have tiers r∈0,…,Tβˆ’1 (0 = tree); pickaxes have tiers p∈1,…,Tβˆ’1 , the empty hand counts as p=0 , and a pickaxe of tier p is crafted from the tier (pβˆ’1) resource. The rule the learner is meant to find is one inequality:

mine(p,r) succeeds⟺pβ‰₯r

A held pair (p*,r*) is removed from training wherever it occurs; the just-sufficient pair p*=r* sits on the boundary of the inequality and is the extrapolation test. Held episodes are the last 20 of episodes, all rows, and test reuse on new layouts.

2\. World model

Encoder. Each raw token is mapped independently to a latent of dimension d=48 :

zi=E(xi),E: β„F→ℝ96→ℝ96→ℝd

a two-hidden-layer MLP with GELU units (a single linear map in the MiniGrid extrapolation runs).

Interaction. The next latent of token i is predicted from its own latent and a context read from the other tokens by multi-head self-attention with H=4 heads of width dh=d/H . The action enters through the query:

qi=LayerNorm⁑(zi+Wa,onehot⁑(a))
Ah[i,j]=softmaxj⁑(WQhqi)⊀(WKhqj)dh,h=1,…,H
ci=WOconcath⁑(βˆ‘jAh[i,j],WVhqj)
z^i=D(zi,ci,onehot⁑(a)),D: β„2d+A→ℝ96→ℝ96→ℝd

Each row Ah[i,β‹…] is a distribution over tokens and is kept after the forward pass. It is the world model's own statement of which tokens interact, and the schemas read it.

Field heads. From z^i , linear heads give logits for each token field at t+1 : β„“iΞΊ=WΞΊz^iβˆˆβ„C for the kind, β„“in=Wnz^iβˆˆβ„S for the state, and β„“iΞ½ for the nuisance field.

Losses. Every per-token loss is weighted so that the rare tokens that change count more than the many that stay the same:

wi=1+λχ,Ο‡i,λχ=6

The field loss is the weighted cross-entropy summed over fields,

β„’tok=βˆ‘field∈κ,n,Ξ½βˆ‘iwiCE⁑(β„“ifield,fieldt+1,i)βˆ‘iwi

The latent prediction loss is the JEPA term, the squared error to the encoder's latent of the actual next token with the target detached, scaled by the target variance so its size does not depend on the latent scale:

β„’lat=meani,c⁑(z^i,cβˆ’sg⁑(zt+1,i,c))2Var⁑(sg⁑(zt+1))

The variance–covariance regulariser (VICReg style) keeps the latent coordinates spread and decorrelated over the batch:

β„’var=1dβˆ‘c=1dmax⁑(0, 1βˆ’Vari⁑(zi,c)+Ο΅),β„’cov=1dβˆ‘cβ‰ cβ€²Covi⁑(zi,c,zi,cβ€²)2
β„’WM=β„’tok+0.25,β„’lat+0.1,β„’var+0.01,β„’cov

Frozen interface. The schema loss does not send gradients into the encoder or the world model: every schema reads sg⁑(z) and sg⁑(Ah) . Joint gradients helped binding in MiniGrid and destroyed the world model's fit on the crafting grid (0.90β†’0.34 all-token accuracy); with binding inherited from attention they are no longer needed.

3\. Schemas

There are K=5 schemas. Every schema is applied to every token at every attempt; the applicability gate (below) decides which schema's prediction counts. A schema k is the tuple

Ξ£k=(roles, Ο•k,ψk, fk, gk, Pβ€Ύk, Rβ€Ύk, mk)

The roles are shared by all schemas because they come from the world model; everything after them is per schema.

Roles. For token i , the roles are its own latent and the token each attention head points at most strongly:

jh(i)=arg⁑maxj⁑Ah[i,j],ri=(ri,0,ri,1,…,ri,H)=(zi, zj1(i), β€¦, zjH(i))

so each token has 1+H=5 roles, each a d \-vector. The argmax is hard in the forward pass and straight-through in the backward pass, i.e. the read uses A~h=onehot⁑(jh(i))+Ahβˆ’sg⁑(Ah) (under the frozen interface this gradient stops at the schema anyway). This is the binding: the schema never searches for its participants; it takes the ones the world model already uses. The same pointers jh(i) are used to read the roles at t+1 , so a binding persists across the transition.

Relations. The schema's inputs are relations among the roles, not the roles themselves. Each schema has Hr relation heads; head h is a pair of bias-free linear maps Ο•h,ψh:ℝd→ℝdr of rank dr . For each ordered pair of roles (u,v)∈0,…,H2 :

Rh[u,v]=βŸ¨Ο•h(ri,u), Οˆh(ri,v)⟩dr(product form)
Rh[u,v]=Ο•h(ri,u)βˆ’Οˆh(ri,v),dr=1(difference form)

Two maps rather than one make the relation asymmetric, Rh[u,v]β‰ Rh[v,u] , which is what "sufficient for" needs. The pinned runs use dr=1 . The flattened matrix

Fi=vec⁑(R1,…,RHr)βˆˆβ„Hr(H+1)2

is the only thing the schema's abstract maps see. This is the relational bottleneck in the Abstractor form: perception decides which comparisons are made, but the values of the objects do not pass through.

Optional switches on the relation entries (the scarcity variants):

β€’ exclude self: Rh[u,u]←0 , since a token compared with itself identifies it;
β€’ noise: Rh[u,v]←Rh[u,v]+σΡ , Ξ΅βˆΌπ’©(0,1) , during training;
β€’ quantisation to Kr learned bins b1,…,bKr : with Ο€m∝exp⁑(βˆ’(Rh[u,v]βˆ’bm)2) , the entry is snapped to barg⁑maxm⁑πm in the forward pass with the straight-through gradient of Ο€ (for Kr=2 on the difference form this is a monotone comparison by construction);
β€’ usage charge: with quantisation on, let Ο€β€Ύh,u,vβˆˆΞ”Kr be the mean of Ο€ over the batch and over tokens; then β„’use=βˆ‘h,u,vH(Ο€β€Ύh,u,v) . An entry that is constant across rows costs nothing; every entry the model varies to fit the data costs its entropy.

Abstract state and action. Both are small tanh-bounded MLPs of the relation vector:

sβ€Ύi=fk(Fi)∈[βˆ’1,1]8,aβ€Ύi=gk(Fi,onehot⁑(a))∈[βˆ’1,1]6

Abstract transition. An MLP on the abstract pair predicts the abstract state of the same roles at t+1 :

sβ€Ύ^i=Pβ€Ύk(sβ€Ύi,aβ€Ύi)βˆˆβ„8,target sβ€Ύβ€²i=fk(Fβ€²i)

where Fβ€²i is the relation vector of the roles read at t+1 through the pointers jh(i) fixed at t .

Consequence. A trunk ui=Tk(sβ€Ύi,aβ€Ύi)βˆˆβ„96 feeds two heads. The kind head gives 1+C logits, "keep" or a new kind; the state head gives 2ρ+1 logits over a count delta Ξ΄βˆˆβˆ’Ο,…,ρ , ρ=2 . The predicted distributions over the next fields are the residual mixtures

pk(ΞΊt+1,i=c)=pk(keep),[c=ΞΊt,i]+pk(new=c)
pk(nt+1,i=m)=βˆ‘Ξ΄=βˆ’ΟΟpk(Ξ΄),[clip⁑(nt,i+Ξ΄, 0, Sβˆ’1)=m]
pk(outi)=pk(ΞΊt+1,i),pk(nt+1,i)

Consequences are changes, not states: "no change" is the default, and the abstract state never has to carry the count it is meant to abstract away. Without this the schema loss could not fit inventory counts at all.

Applicability and gate. Each schema estimates its own applicability from the same relation vector and the action,

mk(i)=MLP⁑(Fi,onehot⁑(a))βˆˆβ„,Ξ³k(i)=exp⁑(mk(i)/Ο„)βˆ‘kβ€²exp⁑(mkβ€²(i)/Ο„)

with temperature Ο„=1 . The gate is a normalised responsibility across schemas, which is what stops every schema from abstaining at once.

Mixture loss. The main schema loss is the negative log of the gated mixture of the schemas' outcome likelihoods, with the change weights normalised over the batch, w~i=wi/βˆ‘jwj :

β„’mix=βˆ’βˆ‘iw~ilogβ‘βˆ‘k=1KΞ³k(i),pk(outi)

Transition loss. With ek(i)=18|sβ€Ύ^iβˆ’sg⁑(sβ€Ύβ€²i)|2 and the posterior responsibility

ρk(i)∝γk(i),pk(outi),exp⁑(βˆ’0.2,ek(i))

the abstract transition is trained only where a schema is responsible:

β„’trans=βˆ‘iw~iβˆ‘ksg⁑(ρk(i)),ek(i)

Regularisers. With Ξ³β€Ύk the mean gate over batch and tokens and Aβ€Ύ=1Hβˆ‘hAh :

β„’bal=Kβˆ‘kΞ³β€Ύk2βˆ’1,β„’ent=βˆ’meaniβ‘βˆ‘kΞ³k(i)log⁑γk(i),β„’att=meani⁑H(Aβ€Ύ[i,β‹…]),β„’sβ€Ύ=mean⁑,sβ€Ύ2

β„’bal is zero exactly when the schemas are used equally and pushes against a single schema taking everything; β„’ent pushes each token's gate toward one schema; β„’att sharpens attention rows, but under the frozen interface it carries no gradient and is only reported.

Total.

β„’sch=β„’mix+0.2,β„’trans+0.1,β„’bal+0.02,β„’ent+0.005,β„’att+10βˆ’4,β„’sβ€Ύ+Ξ»use,β„’use
β„’=β„’WM+2,β„’sch

Because of the stop-gradients, β„’sch reaches only the schema parameters and β„’WM only the world model; the factor 2 is therefore a learning-rate ratio, not a trade-off.

Prediction and scoring. At test time each token's next kind and count are the argmax of the gated mixture,

ΞΊ^t+1,i=arg⁑maxcβ‘βˆ‘kΞ³k(i),pk(ΞΊt+1,i=c),n^t+1,i=arg⁑maxmβ‘βˆ‘kΞ³k(i),pk(nt+1,i=m)

A row is exact when every token is right, ∏i[κ^t+1,i=κt+1,i][n^t+1,i=nt+1,i]=1 . The world model is scored the same way from its own field heads. Every accuracy is reported against the ceiling: a hand-written abstraction Q maps a row to an abstract key (for the grid: family, faced kind, held tier code, action), a table T records the majority change per key on the training rows, and the ceiling is the exact accuracy of T∘Q on the held rows. It is the best any learner can do that has found exactly that abstraction; on the six-tier grid it is 0.98 on held episodes.

4\. What the experiments established

Reuse across layouts. On the crafting grid, held-out episodes (new layouts, same rules) are predicted at 0.99 against a hand ceiling of 0.98 . On MiniGrid, a held-out combination of known key and door colours is predicted at 0.90 –0.94 against 0.98 . Both hold in every seed and need no symmetry prior. This is the claim the theory can make.

Two participants. Inventory changes depend on two other tokens (the faced object and the tool). One bound participant caps the schema fit at 0.77 ; all H heads as roles gives 0.99 . The faced flag Ο†i on tokens is likewise necessary (0.83 without).

Interpolated pairs. A tool–resource pair inside the range of seen pairs (iron pickaxe on stone, when iron works on everything else) is filled in by schemas and world model alike (0.78–0.85).

Ordinal extrapolation, the open problem. A just-sufficient pair never seen (tier-2 pickaxe on tier-2 stone) is not filled in by the world model at all (0.02–0.19). With six tiers and dr=1 , the schemas fill it in three seeds out of six at 4k training steps and lose it by 8k steps as they replace the rule with a per-pair table. Every pressure tried to keep the rule β€” bins, noise, no self-relations, a charge on relations in use β€” fails at 8k steps for one reason: relations between a participant and a fixed reference object (agent, table) act as identity bits, and several entries of R together spell out the pair. Penalties make that dearer, not impossible.

Routing. Prediction alone never made schemas partition by interaction family (NMI 0.1 –0.4 ). The relation-usage charge does (0.4–0.7), because each schema pays for its own live comparisons and specialises. This is the one label-free routing result.

Second-order relations. An episode memory of past events, retrieved by participant match and read out with the past outcome, became a lookup: fit up, held pair down. If revisited, the read must be a relation between the retrieved event's relation vector and the current one, never the outcome.

5\. What the theory now claims and does not claim

Claims.

1. Binding is inherited from an interaction world model, not learned by the schema. Every attempt to learn it inside the schema failed.
2. A schema's consequence is a change to its token; its inputs are relations among its roles.
3. Compression is a capacity limit on what the abstract map can see, not a penalty on the abstract state. Penalties are paid off by long training; limits are not.
4. Reuse of a rule on new layouts and on new combinations of known objects follows from 1–3 without a symmetry prior.

Does not claim.

5. Extrapolation along an ordinal scale to an unseen pair. This needs the comparison to be one relation entry that the map cannot supplement with identity bits; the proposed form is hard selection of a fixed small number of entries of R (notes/next-experiments.md, item 1).
6. Rules relating one event to another. Requires a relational read of memory, not built.
7. Any of this from pixels. Tokens come from structured state; the plan is ViT/JEPA patch tokens plus HUD tokens, with the crosshair patch as the faced flag.

6\. Control (built, not yet integrated)

Realiser. A goal is an event to cause, g=(i*,a*) : an object slot and an attempt action. The policy Ο€(a∣x,g) is a token-set encoder with the goal marked on its token:

z~i=Enc⁑([xi, [i=i*], onehot⁑(a*)]),z~←LayerNorm⁑(z~+Attn⁑(z~))
Ο€(β‹…βˆ£x,g)=softmax⁑(MLP⁑[meani⁑z~i, z~i*])

It is trained by hindsight imitation on the explorer's own trajectories: walking each episode backwards, every step is labelled with the next attempt as its goal (i* the faced slot at that attempt, a* its action), and the loss is the cross-entropy of the step's actual action. On fresh layouts it reaches sampled goals in 0.86 –0.95 of cases within 40 steps (mean under 6).

Planning (not built). Search over sequences of schema applications in abstract state to reach a sparse goal; hand each application to the realiser. The world model at event time plus the realiser are the two halves; the search and its comparison against a flat RL baseline are E4 in notes/scaling-plan.md.

7\. Pinned configuration (crafting grid)

```
--world-dynamics attention --world-heads 4
--schema-binding interaction --interaction-context head_hard_all
--schema-residual --no-joint-schema-gradients --action-map-from-features
--relation-channel relational --relation-dim 1 [--relation-heads 1
--relation-form difference --relation-exclude-self --relation-quantize 2]
--schemas 5, latent 48, hidden 96, 4000 steps, batch 256
```

The bracketed switches are the scarcity variants; they change routing, not extrapolation.

Glossary

Attempt step. A step whose action is in π’œatt (interact, place, craft, wait); the only steps the world model and schemas train on.

Applicability gate (mk, Ξ³k ). A schema's estimate that it applies to a given token and action; the softmax over schemas of these logits mixes the schemas' predictions.

Binding. Choosing which tokens a schema's roles refer to. Here: the tokens the world model's attention heads point at, jh(i) .

Ceiling (perfect quotient). Accuracy of a lookup table built by hand from the intended abstraction on the training rows and applied to the held rows. The best any learner can do if it has found exactly that abstraction; every result is reported against it.

Change weighting. Loss weight wi=1+6Ο‡i on each token, so rare events count more than the many tokens that stay the same.

Consequence (Rβ€Ύk). The schema's prediction of how its token changes: keep or new kind, and a count delta.

Critical cell. A subset of test rows that decides a claim, such as all mining attempts with tool tier 2 on resource tier 2.

Event time. Counting steps by attempts rather than by primitive actions.

Faced flag (Ο†i). A token field set to 1 on the object in the agent's front cell; the observation Minecraft gives as the crosshair target.

Frozen interface. The schema loss sends no gradient into the encoder or world model; schemas read sg⁑(z) and sg⁑(Ah) .

Head-hard context. For each attention head, the single token with the highest weight, selected hard in the forward pass with straight-through gradients.

Held pair / held recipe. A (tool tier, resource tier) combination removed from training wherever it occurs; tests extrapolation.

Held episodes. The last 20 of collected episodes, all rows; tests reuse on new layouts.

Interpolated pair. A held pair whose neighbours on both sides were seen (the rule can be filled in without an ordering).

Just-sufficient pair. Tool tier equal to resource tier, p=r ; the boundary of the rule, unconstrained by the other cells.

Realiser. The goal-conditioned policy Ο€(a∣x,g) that makes a chosen event happen.

Relation head. One (Ο•h,ψh) pair; the number of independent comparisons the schema can compute per role pair.

Relational bottleneck. The design rule that downstream computation sees relations between objects, not the objects (Webb et al. 2023); here, fk , gk , and mk read only Fi .

Relation-usage charge (β„’use). Loss term: entropy of each relation entry's bin assignment over the batch; an entry that varies costs, a constant one does not.

Residual consequence. Predicting the change of a field rather than its next value; "no change" is then the default.

Roles (ri). The 1+H latents a schema reads for one token: itself and one token per attention head.

Schema (Ξ£k). One reusable rule: roles, relation maps Ο•k,ψk , abstract state map fk , abstract action map gk , abstract transition Pβ€Ύk , consequence Rβ€Ύk , and applicability mk .

sg. Stop-gradient: the value passes forward, no gradient passes back.

Straight-through. A hard choice (argmax, bin assignment) in the forward pass whose backward pass uses the gradient of the soft version.

Tier. The level of a resource (0 \= tree, …, Tβˆ’1 ) or of a pickaxe (1 , …, Tβˆ’1 ); a pickaxe of tier p is crafted from the tier-(pβˆ’1) resource and mines tiers r≀p .

Token (xi). One object slot's observation vector: kind, state/count, relative and absolute position, faced flag; inventory items are tokens with a count.