CoolFace
Apppublic

anthonym21/world-model-demo

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes
App README

๐Ÿง  World Model Demo

An interactive visualization of model-based reinforcement learning concepts

What is a World Model?

A world model is an internal representation that an AI agent uses to simulate the environment without actually interacting with it. Think of it as the agent's "imagination" - it can mentally rehearse actions and predict their outcomes before committing to them in the real world.

The Key Insight

Instead of learning through pure trial-and-error (which is slow and potentially dangerous), an agent with a world model can:

  1. 1.Imagine possible futures by simulating "what if I do X?"
  2. 2.Evaluate which imagined future looks best
  3. 3.Plan a sequence of actions to reach that future
  4. 4.Act with confidence, having already "seen" the outcome

How This Differs from Language Models

AspectLanguage Model (GPT, Claude)World Model (MuZero, Dreamer)
Primary functionPredict next token in a sequencePredict next state given an action
Training signalText prediction lossReward from environment
"Imagination"Generates plausible text continuationsSimulates future environment states
PlanningImplicit (via chain-of-thought)Explicit (via tree search or rollouts)
GroundingStatistical patterns in textCausal dynamics of an environment

A Concrete Example

Language Model: "If I push a ball off a table, it will..." โ†’ generates plausible text based on patterns

World Model: Given state (ball on table) + action (push) โ†’ predicts new state (ball falling, trajectory, landing position) with enough fidelity to plan around it

What You're Seeing in This Demo

This visualization shows a simplified world model operating on a grid navigation task:

The Four Phases

  1. 1.๐Ÿ” Observe: The agent perceives the current grid state (its position, goal location, obstacles)
  1. 1.๐Ÿ’ญ Imagine: The world model predicts what would happen for each possible action (up/down/left/right). You see this as the "mental simulation" exploring future states.
  1. 1.๐ŸŒณ Plan: Using tree search (similar to how chess engines work), the agent evaluates sequences of actions by imagining multiple steps ahead. Better paths to the goal get higher scores.
  1. 1.โšก Act: The agent executes the best action found during planning, then the cycle repeats.

Why This Matters for AI Safety

World models are crucial for AI safety research because:

  • โ€”Predictability: Agents that plan can be analyzed - we can inspect what futures they're considering
  • โ€”Corrigibility: Planning agents can incorporate "don't do irreversible things" into their search
  • โ€”Interpretability: The world model's predictions can be examined for accuracy and bias
  • โ€”Scalable oversight: Humans can audit the agent's "reasoning" by inspecting its simulated futures

Real-World Architectures

This demo is inspired by:

  • โ€”MuZero (DeepMind): Learned world models that mastered Go, chess, and Atari without knowing the rules
  • โ€”Dreamer (Hafner et al.): World models for continuous control from pixels
  • โ€”IRIS (Micheli et al.): Transformer-based world models for Atari
  • โ€”Genie (DeepMind): Generative world models from video

Try It Yourself

  1. 1.Click "Run World Model" to watch the full planning cycle
  2. 2.Use Step Mode to see each phase individually
  3. 3.Adjust grid size and obstacles to see how planning adapts
  4. 4.Watch the Imagined Futures panel to see the agent's "thoughts"

Created by [Anthony Maio](https://huggingface.co/anthonym21) as an educational resource for AI safety research