Gumbel Counterfactual Generation From Language Models

Shauli Ravfogel, Anej Svete, V'esteinn Snaebjarnarson, Ryan Cotterell
2/12/2026

No official code found. Best implementation: shauli-ravfogel/lm-counterfactuals (11 stars, last commit 2025-03-31).

Abstract

Understanding and manipulating the causal generation mechanisms in language models is essential for controlling their behavior. Previous work has primarily relied on techniques such as representation surgery -- e.g., model ablations or manipulation of linear subspaces tied to specific concepts -- to \emph{intervene} on these models. To understand the impact of interventions precisely, it is useful to examine \emph{counterfactuals} -- e.g., how a given sentence would have appeared had it been generated by the model following a specific intervention. We highlight that counterfactual reasoning is conceptually distinct from interventions, as articulated in Pearl's causal hierarchy. Based on this observation, we propose a framework for generating true string counterfactuals by reformulating language models as a structural equation model using the Gumbel-max trick, which we called Gumbel counterfactual generation. This reformulation allows us to model the joint distribution over original strings and their counterfactuals resulting from the same instantiation of the sampling noise. We develop an algorithm based on hindsight Gumbel sampling that allows us to infer the latent noise variables and generate counterfactuals of observed strings. Our experiments demonstrate that the approach produces meaningful counterfactuals while at the same time showing that commonly used intervention techniques have considerable undesired side effects.

View on arXivView PDF

Code Implementations(1)

113Python, Jupyter NotebookApr 14, 20241 years ago

Similar Papers

Cite this paper

@article{ravfogel2026gumbel,
  title  = {Gumbel Counterfactual Generation From Language Models},
  author = {Shauli Ravfogel and Anej Svete and V'esteinn Snaebjarnarson and Ryan Cotterell},
  year   = {2026},
  eprint = {2411.07180},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2411.07180},
  journal = {ICLR 2024 2024}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2411.07180.svg)](https://codeofpaper.com/paper/2411.07180)

Discussion