A language model can say what a room looks like after an action. Chain twelve actions and one early slip spreads: in this toy the plain model ends wrong on 3 of 4 objects. A state tracker that checks each step against the rules keeps all 4 right.
Learn what a language model can and cannot do as a world model: state, action, consequence, score.
Run all 12 actions with the plain model. Then switch on the state tracker and run them again. Slide the count back and watch where the first wrong cell appears. Then we build, piece by piece, the four roles of one model, probes, reasoning, imagined rollouts, executable code worlds and tests.
You need a little Python and the idea of a next-word predictor. We build the rest from zero.
Based on Lecture 19 of Penn CIS 6280: World Models (Fall 2026), taught by Jiatao Gu. Lecture slides. Every idea is re-taught here in our own words and devices. It follows Lecture 16, Learning 3D and 4D World Models in this series.
Illustrative: four objects (key, map, coin, lamp) and four places (table, chest, drawer, bag). Each step moves one object or empties one place into another. The "model" is a script. It applies each action to its own belief and slips at steps 3, 6 and 9. The tracker runs the rules on an explicit state and repairs the belief after each step. These are not measured model errors.
Chapter 0
See what a sentence keeps of a scene, and what it loses
A robot sees a red block and a blue block on a table. You say, "Place the red block on the blue block." You expect to read afterwards, "The red block is supported by the blue block."
| Part | Example |
|---|---|
| Current situation | The red and blue blocks are on the table. |
| Candidate action | Place the red block on the blue block. |
| Predicted change | The red block is supported by the blue block. |
Earlier lectures stored the world as latent variables, video or 3D structure. This lecture asks a new question. Can an LLM (large language model, a network that writes text one piece at a time) do the same job in words?
Words chain well. Words also drop detail. Move the slider to find where.
The sentence is always the same. Slide the true gap. Then switch the planner from the words to the numbers.
Illustrative: each block is 6 cm wide. One gripper finger needs 2 cm of free space to reach the red block. The planner that keeps only the sentence assumes the space is free.
Course notes: November 24 is an invited lecture. The final project report and code are due December 14. Each team gets $100 of cloud compute.
Failure. Symptom: a plan that reads well and fails on contact. Measure: replay it in a simulator and count failed grasps. Fix: keep the numbers that decide the next action in the state.
The road for the rest of the lecture:
Chapter 1
Change what you ask and the same weights state, choose, predict or judge
An LLM writes one token (a small piece of text or code) at a time. Each token it writes joins the context, the text the model reads, for the next one.
Training sets the weights θ. Pretraining predicts the next token of recorded text and code. SFT (supervised fine tuning) predicts the next token of a demonstration. A new prompt changes the context. It does not change θ.
The four roles below use one model. Only the question and the context change.
| Query | Condition on | Generate |
|---|---|---|
| State inference | history of observations and actions | a current-state description |
| Policy | history + goal | a candidate action |
| Transition | history + candidate action | a predicted consequence |
| Evaluation | outcome + task criteria | a judgment or score |
Pick a query. The weights box never changes. The input and the output do.
The scene is the red and blue block example from the lecture. The outputs are examples of what each query could return, not recorded model output.
A transition query predicts an observation before the action runs:
Now chain predictions. Say each predicted state is right 95% of the time.
Failure. Symptom: you ask what to do and get what happens, or the reverse. Measure: log the role of each call and compare its inputs with the table. Fix: name the role in the prompt, and pass the action only to the transition query.
Chapter 2
Separate a probe from a transition test, then separate reward from value
You read: "A key is inside an open chest. You pick up the key." Where is the key now? In your hand. Is the chest empty? Yes.
Li, Nye and Andreas (ACL 2021) ask if such facts can be read from the internal vectors of BART and T5 models. The story advances one event at a time. Gurnee and Tegmark (ICLR 2024) read place locations from Llama 2 vectors. Both use a probe: a small model trained to read one property from a larger model's internal vectors.
A probe shows that the fact is present. It does not show that the model can predict what happens if it acts here. That needs a separate prediction test. Try both below.
Press an event. Then switch on "Ask first" and press again: the model predicts the result and nothing changes.
Illustrative: a four-rule toy world. A closed chest blocks picking up the key and putting it in. The "prediction" is computed by the rules, as a stand-in for a model's answer.
Goals need a score. Language to Rewards (CoRL 2023) has the LLM write a motion description and reward parameters, and MuJoCo MPC searches with the physics model. Eureka (ICLR 2024) writes reward code, trains a policy with RL, and revises the code from training feedback.
| Name | Question | Meaning |
|---|---|---|
| Reward rt | Did this transition help? | A score for a state, action or outcome. |
| Value Vπ(st) | How promising is this situation? | Expected future return under a stated continuation. |
A discount γ shrinks a reward by γ for each step you wait. Take γ = 0.9 and a reward of 1 at the goal. A state 3 steps away has value 0.9 × 0.9 × 0.9 = 0.729.
Failure. Symptom: the model answers "where is the key" and still fails after a new action. Measure: compare predicted and executed results on actions held out of the story. Fix: test read-outs and transitions as two separate tests.
Chapter 3
Watch intermediate text predict a result before the model acts
The task: "Place red on blue." Blue is covered by a green block. The command pick_place(red, blue) fails, because blue is not clear. What should the model write first?
With chain of thought the model writes intermediate text z before the final command a. The weights θ stay fixed.
| Function | What the text says |
|---|---|
| Infer the state | Blue is covered. Red is on the table. |
| Set a subgoal | Clear blue before stacking red. |
| Predict a consequence | Moving the covering block will leave blue clear. |
| Evaluate and decide | That enables the goal. Move it, then check the result. |
This is one possible process. The functions need not be separate networks.
Pick commands until red is on blue. A blocked command costs a turn. Switch on "Think first" to see each command's predicted result before you press.
Illustrative: three blocks and a simulator. A block can move only if nothing is on it and its target is clear. The "thinking" lines come from the simulator, as a stand-in for model reasoning.
RL trains the model itself. RL (reinforcement learning) scores outputs that the model made. SFT gives an output to copy.
Worked toy: four samples earn rewards 1, 0, 0, 1. The mean is 0.5. Relative scores are +0.5, −0.5, −0.5, +0.5. The update raises the first and the last.
Failure. Symptom: fluent reasoning, wrong plan. Measure: compare each predicted consequence with the executed result. Fix: score with a test, and run the action before you trust the text.
Chapter 4
Choose a skill that is useful and likely to work, then read the real result
A robot has a library of skills. You say, "I spilled my drink." Which skill should it run first? SayCan (Ahn et al., Google Robotics, 2022) scores each skill twice.
| Check | Question |
|---|---|
| Task relevance | Does this skill help satisfy the instruction? |
| Feasibility | Can the skill succeed in the current situation? |
| Execution | Run the selected skill, then choose again. |
Relevance is fixed. Move the feasibility sliders, then switch feasibility on and off.
Illustrative: the relevance numbers (0.60, 0.30, 0.10) and the product rule are a toy. They are not SayCan's measured values.
Default numbers: sponge 0.60 × 0.20 = 0.12. Sink 0.30 × 0.90 = 0.27. Apple 0.10 × 0.90 = 0.09. The sink wins. Relevance alone picks the sponge, which the robot cannot reach.
ReAct (Yao et al., ICLR 2023) adds real feedback. The model writes a thought and an action. The environment answers. The answer joins the history and generation continues.
| Who | Text (ALFWorld, condensed) |
|---|---|
| LLM thought | I need the keychain before I can put it in the safe. |
| LLM action | Open the drawer. |
| Environment | The drawer contains a keychain and a watch. |
| LLM continuation | The keychain is visible. Take it from the drawer. |
Experience can change two different things. In agentic RL (CWM, Section 5) tool results join the history, external tests score the outcome, and the LLM weights update. In ASPIRE (Lu et al., 2026) the model writes a robot program, runs it, reads the execution trace and repairs it. The weights stay fixed. The program and the skill library change.
Failure. Symptom: the robot picks a useful skill that cannot succeed. Measure: the success rate of the chosen skills. Fix: score feasibility next to relevance.
Chapter 5
Look for a consequence the policy predicts before it moves
A robot arm must pick up a spray can. The model sees camera views, robot pose and gripper width, and writes the next arm or gripper command. The lecture asks where the world model is in that loop. The example is one recorded pickup by Qwen3.8-27B-PEAR on RoboDojo.
The policy part chooses the next command. The world-model part reasons about what that command will do in the current physical situation. The lecture shows three local judgments, paraphrased from an episode report.
| Part | Judgment (paraphrase) |
|---|---|
| Representation | The can is probably grasped. The arm may be at its reach limit. |
| Prediction | Retracting while lifting may let the hand rise farther. |
| Interaction | Execute the command, observe the motion, revise the hypothesis. |
The prediction depends on both the arm configuration and the action. Lifting straight up gave no more height. Retracting while lifting did. The inferred constraint is a hypothesis.
Gripper width gives a second example. If closing should stop at contact and the fingers stop early, something is between them.
The close command targets 0 cm. Slide where the fingers stopped. Then supply the closing rule.
Illustrative: widths in centimetres and the 0.5 cm tolerance are a toy. In the lecture's report, the stopping rule was supplied in the interface and the LLM applies it to this scene.
Failure. Symptom: the model calls a grasp secure after contact. Measure: lift and check that the object rises. Fix: treat contact as a hypothesis, not a result.
Chapter 6
Predict the state after each candidate, score it, and search
Blocksworld: orange and blue are clear on the table and the hand is empty. The goal: orange on blue. RAP (Hao et al., EMNLP 2023) turns the LLM into both a scorer of actions and a predictor of states.
The model imagines both branches. Neither has run. A goal-condition score compares predicted block relations with the goal. Search compares continuations. Only the chosen action goes to the environment.
Slide the look-ahead. Then make the model mispredict candidate A.
Illustrative: a real two-block search with three move types (pick up, stack, put down). The score is the number of actions to reach the goal. A wrong prediction here means the model says A leaves the hand holding blue.
Failure. Symptom: search ignores the best branch. Measure: compare predicted states with executed states on one step. Fix: check the first-step prediction before you chain it.
Chapter 7
Learn the transition from execution traces, or write it as a program and revise it
A program that acts returns a command. A program that predicts returns a consequence. The inputs and outputs decide the role.
python def choose_action(history, goal): # a program that acts return pick_place("red", "blue") # returns a command to execute def step(state, action): # a program that predicts next_state = apply_rules(state, action) return next_state # returns a consequence for a supplied action
CWM (FAIR CodeGen team, Meta, 2025) is a 32B decoder-only LLM trained on execution. Python traces pair each executed line with the change in local state. Docker interaction pairs commands with feedback from a software environment. Execution gives the target for prediction.
The same experience trains two skills. "What followed this action?" has the recorded next observation as target and teaches prediction. "Which choices led to success?" has a reward and teaches the policy.
WorldCoder (Tang, Key and Ellis, NeurIPS 2024) writes Python rules instead. It observes states, actions and results, writes the rules, then runs the model to plan. A surprise changes the model. Add the rule, then recheck the earlier transitions.
A row of 6 cells has two teleporters (purple). Replay more recorded transitions. Then add the rule.
Illustrative: a one-row version of the lecture's schematic teleporter case (Sokoban with teleporters). The recorded transitions are made up.
Replay 2 shows the first counterexample. Replay all 6 and the model without the rule misses 2 of 6. With the rule it misses 0.
Failure. Symptom: a model that fits the first few moves and fails later. Measure: replay all recorded transitions after every edit. Fix: add the rule, then recheck the old ones.
Chapter 8
Keep the state in a program and let a video model draw it
Four systems from this lecture compute the next state in four different ways. They can be combined.
| System | Next-state computation | Observation or evaluation |
|---|---|---|
| Interactive agent | The actual environment evolves. | Sensors and external task feedback. |
| Language rollout | The LLM predicts a state description. | Task rules or a learned evaluator. |
| Executable world model | Generated code executes transition rules. | Program output, checked against evidence. |
| Simulation + video | A simulator advances the proxy world. | A generative model renders observations. |
GPT4Motion (Lv et al.) splits the work. GPT-4 writes a Blender scene and simulation script. The simulation renders depth and edges. An image diffusion model draws the appearance.
Coding Agent as World Brain (Chen, Lin and Zhang, 2026) keeps persistent state and rules in a program. A coding agent edits them, and a video model renders frames from a proxy. Mundo builds a 3D proxy and an executable scene from context images.
A cup goes behind a wall. Slide how long it stays hidden. Then move the state from the recent frames into a program.
Illustrative: a model that sees only its last 4 frames. The window size is a toy value, not a property of any named system.
Failure. Symptom: an object vanishes after it leaves the view, then reappears changed. Measure: hide an object for longer and longer, and find where identity breaks. Fix: keep persistent state outside the frames.
Chapter 9
Catch a model that grades its own mistake, and a reward that misses the goal
A robot assumes it holds the object securely. It predicts that a lift will raise the object. It judges that the action will finish the task. The assumption was wrong, and it entered both the prediction and the judgment.
Slide the true grip. Three graders look at the same lift. Then add the object to the reward.
Illustrative: the grip is secure at 0.5 or more, and the hand always rises to 30 cm. This is a teaching case, not a reported Eureka experiment.
| Risk | What goes wrong | Check |
|---|---|---|
| Text loses detail | Pose, clearance and friction drop out. | Choose an abstraction that keeps what the next action needs. |
| Self-evaluation | One wrong assumption enters prediction and judgment. | An external check on the result. |
| Incomplete reward | Credit without the missing condition. | State every condition of the intended behavior. |
| Time scale | Slow task reasoning meets fast motion. | Match action duration and feedback rate to the environment. |
| Looks right | A frame looks plausible but drifts. | Score visual quality and fidelity to the world separately. |
| Capability | A direct test |
|---|---|
| State inference | Check the inferred relations against observations. |
| World prediction | Compare predicted and executed results of held-out actions. |
| Evaluation | Check judgments against external task criteria. |
| Reasoning benefit | Hold tools and compute fixed. Test whether the predictions improve decisions. |
Failure. Symptom: a high score and a failed task. Measure: the object height after the lift, from outside the model. Fix: test the prediction first, then test whether reasoning uses it.
Chapter 10
Keep the lecture on one page
World modeling can be part of reasoning. Keep track of what is true. Predict and decide. Make predictions executable so that reasoning can query them.
| Idea | Number | Chapter |
|---|---|---|
| Toy room, 12 actions | plain model wrong on 3 of 4 objects; tracker 0 of 4 | Hero |
| Gap vs finger (toy) | 1 cm gap, 2 cm needed: the sentence plan fails | 0 |
| Chained predictions (toy) | 0.95 per step, 12 steps: 0.5404 | 1 |
| Discounted value (toy) | 0.9 × 0.9 × 0.9 = 0.729 | 2 |
| Relative RL score (toy) | rewards 1, 0, 0, 1: +0.5, −0.5, −0.5, +0.5 | 3 |
| Skill scores (toy) | 0.12 sponge, 0.27 sink, 0.09 apple | 4 |
| Gripper stop (toy) | target 0 cm, stopped at 3.5 cm | 5 |
| Search length (toy) | A: goal in 2 actions. B: 4 actions | 6 |
| Replay (toy) | 2 of 6 transitions missed without the rule | 7 |
| Window (toy) | 4 frames kept, 6 hidden: object lost | 8 |
| Hand-height reward (toy) | hand 30 cm, object 0 cm: full credit, failed task | 9 |
| Term | Plain meaning | Chapter |
|---|---|---|
| LLM, token, context | a text writer, its small piece, and what it reads | 0, 1 |
| State inference, policy, transition, evaluation | four queries to one model | 1 |
| Probe | a small model that reads a fact from internal vectors | 2 |
| Reward, value, discount | a step score, a future score, a shrink per step | 2 |
| Chain of thought | reasoning text written before the command | 3 |
| RL, SFT | learn from scored outputs, or copy a demonstration | 3 |
| SayCan score | task relevance with feasibility | 4 |
| ReAct, ASPIRE, agentic RL | act and read feedback; repair a program; train on trajectories | 4 |
| RAP, goal-condition score | imagined rollouts; predicted relations versus the goal | 6 |
| CWM, WorldCoder | learn from execution; write rules as code | 7 |
| Persistent state | state kept outside the generated frames | 8 |
python def rollout(state, actions, rules): # Ch 7: explicit state, rules run every step for a in actions: state = rules(state, a) # one program, one source of truth return state def replay_misses(rules, recorded): # Ch 7: recheck all old transitions return [t for t in recorded if rules(t.state, t.action) != t.next_state] def saycan_pick(skills, relevance, feasibility): # Ch 4 return max(skills, key=lambda s: relevance[s] * feasibility[s]) def chain_ok(p_step, n): # Ch 1: 0.95, 12 -> 0.5404 return p_step ** n def value(gamma, steps_to_goal): # Ch 2: 0.9, 3 -> 0.729 return gamma ** steps_to_goal
Run chain_ok(0.95, 12) and you get 0.5404. Run saycan_pick on the Chapter 4 numbers and you get the sink.
Lecture 16 learned 3D and 4D worlds from images. This lecture asks whether language and code can carry a world model. Lecture 14 showed interactive world models that respond to actions.
Source: Penn CIS 6280: World Models, Fall 2026, Jiatao Gu. Lecture 19 slides.