Environment-Robust Representation Learning with Empirical Bayes

Yuli Slavutsky, Matthew Shen, Bohan Wu, David BleiNeurIPS 2026

TL;DR

Machine learning models notoriously stumble when deployed in new environments—like a clinical model trained in Boston suddenly failing in Seattle. Instead of trying to brute-force "invariant" features by erasing environmental differences, this paper introduces EmBER, a probabilistic method that models how environments shift underlying hidden states. By learning to recognize which past environments a new data point resembles most, EmBER adapts on the fly and outperforms popular out-of-distribution generalization methods across astronomy, microbiome, and ICU datasets.

What Problem Does This Paper Address?

Imagine you are classifying celestial objects across different patches of the night sky, or predicting sepsis across different hospitals. The underlying laws of physics and human biology don't change from place to place. What does change is the local prevalence of hidden states—one hospital might see far more elderly trauma patients, while one region of the sky might be dense with stars rather than quasars.

Figure 1: Probabilistic graphical model of the multi- environment data generative process. Observed vari- ables shown in gray. The top dot encodes shared distribution across environments.

In this setup, an environment ($e$) shifts the distribution of an unobserved latent variable ($z$), while the mechanisms generating your measurements ($x$) and outcomes ($y$) from $z$ remain rock-solid. When handed a new observation $x$ from a brand-new, unseen environment, you can't know that environment's specific quirks. Standard out-of-distribution (OOD) methods try to solve this by slapping hand-crafted penalties onto the loss function to force representations to look identical across training environments. The authors ask: instead of inventing ad-hoc penalties, what happens if we just write down the Bayesian math for this exact causal graph and solve for the optimal marginal prediction $p(y \mid x)$?

Methods

To predict $y$ from $x$ in an unseen environment, the authors introduce EmBER (Empirical-Bayes Environment-Robust learning). Because $z$ and the new environment are unobserved, EmBER marginalizes over the training environments using an amortized variational approach—meaning neural networks are trained to output probability distributions rather than point estimates.

What is standard here is using a variational lower bound (similar to a VAE's ELBO) with Gaussian reparameterization. What is novel is how the pieces fit together:

  1. Empirical Bayes Prior: Instead of assuming a generic prior (like a standard normal distribution) for the latent state $z$, EmBER estimates the prior $p(z \mid x, e)$ directly from the data by averaging an environment-specific variational posterior $q(z; x, y, e)$ over a learned auxiliary label predictor $\hat{p}(y \mid x, e)$.
  2. Adaptive Environment Weighting: A dedicated neural network $\hat{p}(e \mid x)$ looks at an input $x$ and estimates how plausible each training environment is for that specific observation.
  3. Lightweight Latents: Because the goal is predicting a scalar outcome $y$ rather than reconstructing high-dimensional inputs $x$, the latent variable $z$ doesn't need to be huge—in fact, the authors set $z$ to a single dimension across all experiments.

At test time, EmBER evaluates what each training environment thinks about the new $x$, and takes a weighted average using $\hat{p}(e \mid x)$.

Datasets

The authors test EmBER on two synthetic benchmarks and three real-world scientific datasets where environments occur naturally:

  • Parametric Simulation: A synthetic 2D phase-and-branch task where environments shift latent cluster centers.
  • Colored MNIST Variant: A newly constructed variant of the classic benchmark where environments only alter the mixture of four latent "prototypes" (which govern digit, color, and label tendencies), reversing color-label associations at test time.
  • Sloan Digital Sky Survey (Quasar-Star): Predicting quasars vs. stars from photometric color features across sky regions (binned by Galactic latitude).
  • MicrobiomeHD: Detecting colorectal cancer from gut bacteria profiles across different clinical study cohorts.
  • PhysioNet 2019 Challenge (ICU Sepsis): Predicting late-stay sepsis from early vital signs and labs, using hospital/ICU-unit combinations as distinct environments.

Key Insights and Ideas

  • Environment-balancing emerges naturally from probability: You don't need to invent an arbitrary cross-environment penalty. The authors prove (Theorem 1) that EmBER's variational objective mathematically decomposes into per-environment losses plus a specific cross-environment KL-divergence balancing term—comparing local vs. global posteriors against local vs. global priors.
  • Uniform averaging is a trap: You might think, "For a new environment, why not just average predictions equally across all training environments?" The authors prove that uniform weights converge to a biased limit. Why? Because $x$ itself contains clues about $z$, which in turn tells you which training environments are relevant. Modeling $\hat{p}(e \mid x)$ lets the model dynamically upweight training environments that actually resemble the test point.
Convergence plot showing adaptive environment weights converging at a 1/sqrt(m) rate while uniform weights plateau at a biased error limit.

Key Results

Across all five experiments, EmBER consistently outperforms Empirical Risk Minimization (ERM) and leading environment-balancing baselines (IRM, VREx, and Fishr) on held-out environments:

  • Near-Oracle Synthetic Performance: In the parametric simulation, EmBER hits 92.8% accuracy (nearly matching the theoretical Bayes-optimal ceiling of 93.4%), while ERM, IRM, VREx, and Fishr all hover around 57–58%. On Colored MNIST, EmBER reaches 78.7% accuracy, beating IRM (74.7%) and ERM (65.0%).
  • Real-World Gains: In Quasar-Star classification, EmBER achieves 92.1% accuracy and slashes negative log-likelihood (NLL) to 0.221 (compared to ~0.38–0.39 for all baselines). In ICU sepsis prediction, it achieves the top AUROC (0.740 vs. ERM's 0.692) and AUPRC (0.179 vs. ERM's 0.153). In Microbiome detection, it leads in both accuracy (59.1%) and NLL (0.850).
  • Sensible Extrapolation: In the astronomy task, EmBER automatically assigned 100% of held-out test points the highest weight for the exact training sky-region whose brightness distribution most closely matched the test set.

Limitations and Future Work

  • Untestable Causal Assumptions: EmBER assumes $p(x \mid z)$ and $p(y \mid z)$ never change across environments. Because $z$ is unobserved, you can't verify this directly from data before training—you only find out if it holds by checking predictive performance on held-out environments.
  • Computational Overhead: Computing the empirical-Bayes priors requires summing over all training environments for every data point in a minibatch. If you have thousands of environments, training slows down. For future work, the authors suggest approximating this sum using a smaller set of learned "pseudo-observations" (inspired by VampPrior).

Summary updated

Abstract

We consider multi-environment prediction problems. We assume the environments change the distribution of a latent variable, while the mechanisms generating observed covariates and targets remain stable conditional on that variable. For example, hospitals or clinical cohorts may differ in the prevalence of latent patient states, even though the relationships between those states, physiological measurements, and outcomes remain unchanged. Given a dataset from multiple environments, we formulate a Bayesian model for such problems and derive the corresponding variational objective. We show that this objective decomposes into per-environment terms and an additional cross-environment balancing term induced by the model's structure. We use an empirical Bayes method to set the prior and incorporate it into the objective. Based on this objective, we develop an amortized variational algorithm for posterior approximation, and use the resulting learned latent variables to form predictions in new environments. We study our approach through simulations and real-world studies of astronomical source identification, microbiome-based disease detection, and ICU sepsis prediction. Across these settings, our method outperforms previous approaches for prediction in new environments.
BibTeX
@inproceedings{slavutsky2026environment,
  author = {Yuli Slavutsky and Matthew Shen and Bohan Wu and David Blei},
  title = {{Environment-Robust Representation Learning with Empirical Bayes}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=dcFIgr2nN2},
}
Figure