Abstract
The human ability to think about thinking ("theory of mind") is a fundamental object of study in many disciplines. In recent decades, researchers across these disciplines have converged on a rich computational paradigm for modeling theory of mind, grounded in recursive probabilistic reasoning. However, practitioners often find programming in this paradigm extremely challenging: first, because thinking-about-thinking is confusing for programmers, and second, because models are extremely slow to run. This paper presents memo, a new domain-specific probabilistic programming language that overcomes these challenges: first, by providing specialized syntax and semantics for theory of mind, and second, by taking a unique approach to inference that scales well on modern hardware via array programming. memo enables practitioners to write dramatically faster models with much less code, and has already been adopted by several research groups.
Introduction
Cognitive scientists and economists frequently employ the "Recursive Rationality" (RR) paradigm to model agent interactions. In this framework, an agent (e.g., Alice) reasons about the internal states and intentions of another agent (e.g., Bob). For instance, if Bob says "green," Alice must infer which green object he refers to by considering what Bob thinks she knows.
While conceptually elegant, implementing these models is fraught with difficulties. First, general-purpose probabilistic programming languages (PPLs) often suffer from "perpetration confusion," where a programmer inadvertently allows an agent to access information (like the "true" state of the world) that should be hidden from them. Second, recursive reasoning leads to a combinatorial explosion of the state space. Traditional Monte Carlo sampling methods struggle with the deep, nested loops required, often resulting in models that take days to execute.
Methods: The memo Language
The authors introduce memo, a PPL embedded in Python that treats "agency" as a first-class citizen. It addresses the aforementioned challenges through two primary innovations:
Frames of Mind
memo utilizes a system of "frames of mind"—nested data structures that explicitly define the knowledge and uncertainties of each agent. The compiler statically tracks these frames, allowing it to detect and prevent "mind-reading" bugs at compile-time, thereby ensuring the logical integrity of multi-agent models.
Inference as Array Programming
Rather than relying on sampling, memo leverages the fact that many RR models operate on discrete distributions with manageable cardinality. The language compiles nested inference queries into a sequence of high-performance array operations, such as tensor contractions and normalizations. By targeting JAX, memo models are end-to-end differentiable and can be executed on GPUs. This enables the use of standard deep learning optimizers, like Adam, to fit model parameters to experimental data in seconds.
Evaluation and Results
The performance of memo was evaluated across a variety of benchmarks, including Rational Speech Acts (RSA), Schelling coordination games, and complex MDP/POMDP planning tasks. It was also tested on "in-the-wild" research models previously implemented in languages like Gen and R.
The results demonstrate significant improvements in both speed and conciseness:
- Speedups:
memoachieved a 2,000,000x speedup over a Gen-based "Lying" model and was 200x faster than a WebPPL implementation of a Schelling game. On a GPU, large-scale MDP planning was completed in 0.377s, compared to 79s for a CPU-based WebPPL version. - Code Efficiency: The "Lying" model's implementation was reduced from 220 lines of code to just 50.
- Resource Rationality: By utilizing JAX,
memocan calculate the exact number of floating-point operations (FLOPs) for a computation, facilitating the development of "resource-rational" models where agents adjust their depth of thought based on computational cost.
Conclusion and Future Work
memo represents a significant step forward in modeling theory of mind by transforming inference into a structured array programming problem. While currently optimized for discrete random variables, future work aims to extend support to continuous variables and hybrid inference backends. Additionally, the authors envision memo serving as a "language of thought" to enhance the theory-of-mind capabilities of Large Language Models (LLMs).
Summary updated