Abstract
In this work we investigate the capacity of language models to generate explicit, interpretable, and interactive world models of scientific and common-sense reasoning tasks. We operationalize this as a task of generating text games, expressed as hundreds of lines of Python code. To facilitate this task, we introduce ByteSized32, a corpus of 32 reasoning-focused text games totalling 20k lines of Python code. We empirically demonstrate that GPT-4 can use these games as templates for single-shot in-context learning, successfully producing runnable games on unseen topics in 28% of cases. When allowed to self-reflect on program errors, game runnability substantially increases to 58%. While evaluating simulation fidelity is labor intensive, we introduce a suite of automated metrics to assess game fidelity, technical validity, adherence to task specifications, and winnability, showing a high-degree of agreement with expert human ratings. We pose this as a challenge task to spur further development at the juncture of world modeling and code generation.
Introduction
While Large Language Models (LLMs) like GPT-4 demonstrate impressive common-sense knowledge, this knowledge is often "locked" inside a black box. It is difficult to verify if a model truly understands the underlying causal physics and constraints of a scenario. To address this, researchers propose that code is the ultimate formal language for world modeling. By tasking an LLM with writing the full source code for a text adventure game, the model is forced to explicitly define objects, states, and the consequences of actions. The challenge lies in generating hundreds of lines of functional Python code that is not only syntactically correct but also logically sound and "winnable" by a human player.
The ByteSized32 Corpus
The study introduces the BYTESIZED32 Corpus, which consists of 32 hand-authored text games written in Python. These games serve as "micro-simulations" of common-sense or scientific reasoning tasks, such as boiling water or washing dishes. Each game provides a structured environment where actions have specific consequences, totaling approximately 20,000 lines of code across the corpus. An evaluation set of 16 unseen task specifications was used to test the models' ability to generalize and generate new simulations.
Methodology: Generation and Self-Reflection
The researchers employed a single-shot in-context learning (ICL) approach, providing GPT-4 with one highly-templated example game and a new task specification (e.g., "Create a simulation for heating milk on a stove").
A key component of the method is Self-Reflection. If the generated code fails to run or encounters an error in a Python interpreter, the error message is fed back to the model. The model then attempts to debug and rewrite the code, repeating this process for up to three iterations. To evaluate the results, an automated harness tests technical validity, specification compliance, physical reality alignment (e.g., needing to open a fridge before taking milk), and winnability.
Results and Evaluation
The iterative reflection process proved vital for success. Without reflection, only 28.1% of generated games were runnable. With three rounds of self-reflection, this success rate jumped to 57.3%.
Key insights from the evaluation include:
- Physical Alignment: After reflection, roughly 51% of the generated game trajectories accurately modeled physical reality.
- Winnability: This remains the hardest hurdle; only 37.5% of the games generated after reflection were deemed "winnable" by human evaluators.
- LLMs as Judges: GPT-4 is remarkably effective at judging the "physical reality" of generated games, showing a high correlation (κ = 0.89) with human expert ratings.
- Distractor Difficulty: Models excel at including critical objects but struggle with "distractors"—objects or actions that aren't necessary for the task but add realism and difficulty.
Conclusion and Future Work
While GPT-4 shows promise in generating explicit world models, several limitations remain. The current games are "micro-simulations," and scaling to larger, open-ended environments is a significant challenge. Furthermore, models often fail to implement correct "win condition" logic even when the simulation mechanics are sound. Future work will explore more efficient "diff-based" editing and move toward zero-shot generation to further test the autonomy of LLMs in world modeling.
Summary updated