Reproduce “Executable Counterfactuals: Improving LLMs' Causal Reasoning Through Code” on OpenResearch

Turn your favorite coding agents into research agents that review literature, develop hypotheses, and run experiments.

Universal app for Apple silicon and Intel. Requires macOS 11 or later.

About this paper

Aniket Vashishtha, Qirun Dai, Hongyuan Mei, Amit Sharma, Chenhao Tan, Hao Peng

The framework tests counterfactual reasoning by requiring models to infer hidden conditions from observations, change an input while holding those conditions fixed, and predict the result. On a while-code task, Claude-4-Sonnet scores 46.9% exact match on counterfactual questions versus 89.8% when hidden variables are revealed. Code-trained RLVR reaches 46.3% on constructed counterfactual math, versus 39.0% for the base model.

Key insights

  • The inability to perform the "abduction" step (inferring latent variables from observations) is the primary reason LLMs fail at true counterfactual reasoning, leading to a substantial accuracy gap compared to interventional tasks.
  • Reinforcement Learning from Verifiable Rewards (RLVR) proves to be a more effective and generalizable training paradigm for instilling complex cognitive skills like counterfactual reasoning, allowing models to internalize reasoning strategies.
  • Supervised Finetuning (SFT) leads to limited generalization, as models tend to memorize shallow patterns rather than learning fundamental causal reasoning, performing poorly on out-of-distribution tasks.

Summary by alphaXiv.

Tip: change arxiv.org to autoarxiv.org in any arXiv abstract link to open the paper here.