NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Learning Generalizable Behavior via Visual Rewrite Rules

Yiheng Xie, Mingxuan Li, Shangqun Yu, Michael L. LittmanarXiv 2021

Abstract

Deep Reinforcement Learning (DRL) often struggles with sample inefficiency and poor generalization due to the entanglement of world-modeling and policy learning. We present Visual Rewrite Rules (VRRs), a non-neural approach that learns local state transitions as discrete rules. By decomposing the environment into object-centric representations and using search-based planning, the VRR agent achieves zero-shot generalization across environment sizes and requires significantly fewer training steps than state-of-the-art DRL models.

Introduction

Deep Reinforcement Learning (DRL) has achieved remarkable success in complex gaming environments. However, these agents are often brittle and sample-inefficient. Standard DRL agents act as "black boxes," frequently memorizing specific pixel patterns rather than understanding the underlying logic of a task. This leads to failure when encountering distribution shifts, such as moving from a $6 \times 6$ training grid to a $32 \times 32$ test grid. Furthermore, these models typically require millions of frames of experience to learn simple behaviors. The authors argue that by forcing a neural network to learn both the representation of the world and the policy simultaneously, we create a system that is difficult to audit and prone to overfitting.

Methods

The proposed approach is a structured, non-deep method based on the intuition that most actions in a game only cause local changes. The system is built on several key components:

Visual Rewrite Rules (VRRs)

Instead of a neural network, the agent maintains a dictionary of rules. A rule is defined as: (local_state_before, action) -> (local_state_after, reward). When an action is taken, the agent compares the "before" and "after" images, masking out static elements to record only the pixels that changed (the "rewrite").

Figure 1: The process of extracting a Visual Rewrite Rule (VRR) by comparing consecutive states and masking static pixels.

Object-Centric Representation and Planning

To handle raw pixels, the system discretizes the screen into a grid of "sprites" or object types. It searches for the minimal grid size that yields the simplest set of object IDs. Because the VRRs form a perfect world model, the agent does not need a policy network. Instead, it uses Breadth-First Search (BFS) to plan a sequence of actions toward a goal state using its learned rules.

Expectation Correction

If the agent encounters a situation where its rules predict a change but none occurs—such as walking into a wall—it updates its local "mask" to include the obstacle, refining its understanding of the environment's constraints.

Figure 2: Expectation correction occurs when a predicted move is blocked by an obstacle, leading to a rule where the local state remains unchanged.

Evaluation and Results

The approach was evaluated on two procedurally generated environments: Sokoban and MiniGrid (DoorKey). The VRR agent was tested under various distribution shifts, including map rotation and size scaling.

  • Sample Efficiency: In Sokoban, the VRR agent converged in roughly 440 steps, whereas deep RL baselines like PPO and IMPALA required $10^5$ to $10^6$ steps.
  • Zero-Shot Generalization: When moved from a $6 \times 6$ to a $32 \times 32$ DoorKey map, the VRR agent maintained a 1.0 success rate, while DreamerV2 and PPO dropped to 0.0.
  • Interpretability: By separating the world model (rules) from the planner (BFS), the agent avoids the "black box" problem. The dictionary of rules provides a transparent view of the agent's knowledge.

Discussion and Future Work

While highly effective in grid-based, deterministic environments, the VRR approach has limitations. It currently relies on discrete spaces; extending this to continuous 3D environments would require external object detectors. Additionally, the model assumes state changes are agent-triggered, which may pose challenges in dynamic environments where objects move independently. Future work may explore more sophisticated search algorithms like MCTS to handle larger state spaces and extending the dictionary to store outcome distributions for stochastic games.

Summary updated

BibTeX
@misc{xie2021learning,
  author = {Yiheng Xie and Mingxuan Li and Shangqun Yu and Michael L. Littman},
  title = {{Learning Generalizable Behavior via Visual Rewrite Rules}},
  year = {2021},
  eprint = {2112.05218},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2112.05218},
}
Figure