A language for mental models
memo is a new probabilistic programming language for expressing computational cognitive models involving sophisticated recursive reasoning, and for performing fast enumerative inference on such models. memo inherits from the tradition of WebPPL-based Bayesian modeling (see probmods, agentmodels, and problang), but aims to make models easier to write and run by taking advantage of modern programming language techniques and hardware capabilities (including GPUs!). As a result, models are often significantly simpler to express (we've seen codebases shrink by a factor of 3x or more), and dramatically faster to execute and fit to data (we've seen speedups of 3,000x or more).
memo stands for: mental modeling, memoized matrix operations, model-expressed-model-optimized, and metacognitive memos.
[!NOTE] memo is currently in "public beta". Though we have many active users, there may be some sharp edges and the language may occasionally change in backward-incompatible ways. We are on track to offer a first stable release of memo in February 2025. For updates on memo's development, we encourage you to subscribe to our low-traffic monthly announcements mailing list here.
python --version
. (As of writing, Python 3.12 is the latest version of Python, and memo depends on several of its powerful new features.)pip install jax
should be enough. Otherwise, please consult the JAX website for installation instructions. You can check if JAX is installed by running import jax
in Python.pip install memo-lang
. You can check if memo is installed by running from memo import memo
in Python.[!WARNING] Make sure to install
memo-lang
, notmemo
. The latter is a different package, unrelated to this project!
Once you have installed memo, take a look at the Memonomicon for a tour of the language, and an example of how to build a model and fit it to data by parallel grid search and/or gradient descent.
This repository also includes several classical examples of recursive reasoning models implemented in memo:
When should I use memo rather than Gen or WebPPL?
memo's core competence is fast tabular/enumerative inference on models with recursive reasoning. That covers a wide range of common models: from RSA, to POMDP planning (value iteration = tabular operations), to inverse planning. In general, if you are making nested queries, we recommend using memo.
There are however two particular cases where you may prefer another PPL:
The aforementioned cases are explicitly out of scope for memo. The upshot is that by specializing memo to a particular commonly-used class of models and inference strategies, we are able to produce extremely fast code that is difficult for general-purpose PPLs to produce.
Okay, so how does memo produce such fast code?
memo compiles enumerative inference to JAX array programs, which can be run extremely fast. The reason for this is that array programs are inherently very easy to execute in parallel (by performing operations on each element of the array independently), and modern hardware is particularly good at parallel processing.
What exactly is JAX?
JAX is a library developed by Google that takes Python array programs (similar to NumPy) and compiles them to very fast code that can run on CPUs and GPUs, taking advantage of modern hardware functionality. JAX supports a lot of Google's deep learning, because neural networks involve a lot of array operations. memo compiles your probabilistic models into JAX array programs, and JAX further compiles those array programs into machine code.
Note that JAX has some unintuitive behaviors. We recommend reading this guide to get a sense of its "sharp edges."
I installed memo but importing memo gives an error.
Did you accidentally pip-install the (unrelated) package memo instead of memo-lang?
Can I run memo on Apple's "metal" platform?
Yes! See this issue for details: https://github.com/kach/memo/issues/66