# Compositional Risk Minimization

Compositional risk minimization handles attribute combinations never seen in training

Divyat Mahajan, Mohammad Pezeshki, Charles Arnal, Ioannis Mitliagkas, Kartik Ahuja, Pascal Vincent · arXiv · 2024-10-8

- **Problem** Standard empirical risk minimization gives any attribute combination missing from training zero probability. So the classifier cannot match a test distribution that contains those new combinations.
- **Method** CRM first trains one classifier that predicts all attributes jointly, using additive energy terms. At test time it swaps in the test prior and extrapolates a bias for unseen groups, instead of using the learned bias.
- **Results** CRM keeps worst-group accuracy high when groups are dropped from training. On CelebA with five attributes it scored 63.2, compared to 34.3 for LC.

![Figure 1: The additive energy classifier trained in CRM computes the logits for each groupz = (y, a) by adding the energy components of each attribute via bora…](https://refivu.com/papers/7f0b2d82-eb6c-417e-a42e-8b6899343b6c/figures/figure-2c86b69070b51d97515f0d04af9246e9.png?thumb=512)

**Figure 1** The additive energy classifier trained in CRM computes the logits for each groupz = (y, a) by adding the energy components of each attribute via boradcasting. For the train logits, we add the log of the prior probabilities and a learned biasB(y, a) for the groups present in train data. At test time, the log prior term is replaced with the log of the test prior (if available, otherwise assumed to be uniform), and the biases for novel test groups,B⋆(y, a), are extrapolated using Eq.11. Finally, we obtainp(y, a\|x) by applying softmax function on the adjusted logits. This adaptation from train to test is possible because of the additive energy distributionp(x\|y, a), which allows the model to factorize the distribution into distinct components associated with each attribute.

[Original paper](https://arxiv.org/abs/2410.06303v3) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Divyat Mahajan, Mohammad Pezeshki, Charles Arnal, Ioannis Mitliagkas, Kartik Ahuja, Pascal Vincent · Compositional Risk Minimization · Original paper figure · Extracted the figure area from page 2 of the original PDF.

## Why standard training stalls on unseen combinations

Compositional shift means training inputs cover only some attribute combinations, while test inputs bring combinations never seen during training. Standard ERM fits the training prior, so any combination missing from training receives zero probability. Because the learned distribution puts no mass on those combinations, the classifier cannot match the test distribution q(z\|x).

The authors note that q(z\|x) differs from the training p(z\|x), which ERM estimates with cross-entropy loss.

The shift is narrow by design: conditioned on the attributes, the input distribution stays the same, and only the attribute priors change. Test groups must be new mixtures of attribute values already seen separately, because a completely new individual attribute falls outside the setting. The authors remark that this notion resembles Cartesian Product Extrapolation from Lachapelle et al.

(2024), where a model succeeds when test support equals the full Cartesian product.

Under that assumption each attribute combination maps to a single observation, which the authors find too restrictive. Additive energy distributions instead let the authors model stochastic decoders, so inputs can be a conjunction of characteristics. Theory for methods such as IRM and LC assumes a large diversity of training environments.

The authors instead use inductive biases from additive energy distributions to reach provable generalization with limited environment diversity.

## Additive energy distributions as the modelling choice

An additive energy distribution gives each attribute its own energy term, so the score of a full combination is built by adding those terms. Each attribute value is encoded as a one-hot vector, and the m one-hot vectors are concatenated into a sparse vector σ(z) with m ones. The likelihood becomes p(x\|z) = (1/Z(z)) exp(−⟨σ(z), E(x)⟩), where E(x) stacks the energy terms of every attribute value.

The partition function Z(z) only has to be finite for the density to normalize, so the authors leave the energies largely unrestricted. The support of p(x\|z) is assumed to be Rn for every z in the Cartesian product of training supports.

This form suits inputs that must satisfy a conjunction of characteristics, such as a natural image of a landbird AND having a water background. The authors justify the choice with two lines of work, the first being generative compositionality. From the causal machine learning view, they read the energy of each attribute as an independent mechanism, where independence is algorithmic rather than statistical.

The authors contrast this with provable compositional generalization work, which assumes deterministic labeling functions or decoders that are additive over individual features.

## Training once, then adjusting logits for test priors

CRM starts by training one classifier that predicts all attributes jointly, using a pretrained backbone followed by a linear layer. For each group z = (y, a), the logit adds the energy components of its attributes, obtained by broadcasting over the attribute values. For groups seen in training, the logit also adds the log of the training prior and a learned bias B(y, a).

The energy components come from the additive energy form, which lets the model factorize p(x\|y, a) into one component per attribute.

At test time, CRM swaps the training log prior for the test log prior. When the test prior is unknown, CRM assumes it is uniform. Groups absent from training have no learned bias, so CRM extrapolates a bias B⋆(y, a) for them. A softmax over the adjusted logits gives p(y, a\|x). The single-attribute probabilities then follow by marginalizing over the other attribute, as in the Waterbirds example.

The extrapolation rule follows from the theory, which the authors say is sharp and limited to the discrete affine hull. Their bias ablation replaces the extrapolated bias with the learned bias, and worst group accuracy drops sharply on every benchmark. For example, Waterbirds falls from 78.7 to 55.7 WGA when the learned bias is used. Adjusting logits for the prior alone is not enough, according to the same ablation.

## What extrapolation the theory covers

Their characterization of extrapolation is sharp, so they show it is not possible to generalize beyond the discrete affine hull. Under the additive energy distribution, each attribute gets its own energy term, which is what lets the model factorize the distribution across attributes.

So a modest set of training combinations can cover many attribute combinations at test time. In the conclusion, CRM extrapolates to novel combinations inside the affine hull of the training support, without modelling high-dimensional p(x\|z) or estimating its partition function. The affine hull grows quickly with the training groups until it covers the Cartesian product of the training support.

The extrapolation rests on a test log prior and an extrapolated bias B⋆ for novel test groups, which the classifier adds to its logits. Without a test prior, the authors assume a uniform one, so the adjustment only needs the training-time energies. The authors note that their proof techniques differ from existing work on distribution shifts.

They frame the theory as possibly of independent interest, beyond the CRM method itself.

The authors also flag a limitation: the approach depends on labeled attributes, which may not be available in practice. They only offer a tractable CRM approach for the discriminative task, not the generative one. The experiments on image and text benchmarks then test whether this extrapolation holds in practice.

## Turning benchmarks into compositional shifts

Standard splits of these benchmarks put every group in both train and test, so they don't test compositional generalization. The authors discard samples from one group in the training and validation sets, while the test set stays unchanged. Each dropped group produces its own variant, so a benchmark yields one compositional shift scenario per dropped group.

NICO++ needs less work, because its validation set already contains every group and only that set gets trimmed.

Six benchmarks are used: Waterbirds, CelebA, MetaShift, MultiNLI, CivilComments and NICO++. Some benchmarks have binary attributes, such as Waterbirds, CelebA and MetaShift, while others have non-binary attributes, such as MultiNLI, CivilComments and NICO++.

The baselines are ERM, GroupDRO, LC, sLA, IRM, VREx and Mixup, each built on a pretrained network followed by a linear layer. The backbone is ResNet-50 for the vision datasets and BERT for the text datasets. Representation network and linear classifier share the same learning rate, and the representation network gets no special fine-tuning.

Hyperparameters are picked by group balanced accuracy on the validation set, with 5 randomly drawn settings per method.

Average accuracy can look high while one group fails, because majority groups dominate that number. The main comparisons therefore use worst group accuracy, which takes the minimum accuracy over all test groups. Results are averaged over the dropped-group scenarios, and per-scenario tables sit in Appendix G.2.

## Worst-group gains under dropped groups

CRM keeps its worst-group accuracy high when groups are dropped from training, and the averages are where it looks strongest. On Waterbirds, CRM scored 78.7 WGA, compared to 77.3 for sLA. On CelebA the gap is larger: CRM scored 81.8, compared to 67.8 for G-DRO, the strongest baseline on that metric. Because averages can hide weak scenarios, the authors also looked at the worst single scenario for each method.

![Table 1: Robustness under compositional shift. We compare the proposed CRM method to baseline ERM classifier training with no group information, and to robust…](https://refivu.com/papers/7f0b2d82-eb6c-417e-a42e-8b6899343b6c/figures/figure-6c65e1e7069592cc898535cb95fa2251.png?thumb=512)

**Table 1** Robustness under compositional shift. We compare the proposed CRM method to baseline ERM classifier training with no group information, and to robust methods that leverage group labels: G-DRO, LC, and sLA. We report test Average Accuracy and Worst Group Accuracy (WGA) (mean over 3 random seeds), averaged as a group is dropped from training and validation sets. Last column is WGA under the dataset’s standard subpopulation shift benchmark, i.e. with no group dropped. All methods have a harder time to generalize when groups are absent from training, but CRM appears consistently more robust. Full results with balanced group accuracy, and baselines IRM, VREx, and Mixup are provided in Table 5, Appendix G.1.

[Original paper](https://arxiv.org/abs/2410.06303v3) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)

Averages hide the worst scenario, and there the logit adjustment baselines fall further behind. On Waterbirds, LC scored 69.0 WGA in its worst scenario, dropping the group (0, 1), compared to 73.0 for CRM. On MultiNLI, sLA dropped to 19.7 in its worst scenario, dropping the group (0, 0), compared to 31.0 for CRM. The authors report these worst-case numbers in their detailed tables rather than in the main averages.

ERM and GroupDRO are the most sensitive to dropped groups, and the logit adjustment methods fall sharply on CelebA. Comparing each method's WGA with its standard-benchmark WGA shows how much it loses when groups are dropped. CRM stays more robust in this comparison, which is the paper's central claim for this setting.

With five attributes on CelebA, the baselines treat the spurious attributes as one meta attribute with 16 values. CRM models each attribute with its own energy component, so it doesn't collapse them into one variable. CRM scored 63.2 WGA, compared to 34.3 for LC, the best baseline on that column.

## Does extrapolating the bias matter?

The bias ablation swaps the extrapolated bias B⋆ for the learned bias B̂ in CRM, leaving the rest of the method unchanged. On Waterbirds, worst-group accuracy drops from 78.7 with the extrapolated bias to 55.7 with the learned bias. On CelebA, the same swap takes worst-group accuracy from 81.8 down to 58.9. MetaShift falls from 73.4 to 58.7, and MultiNLI falls from 58.7 to 30.4 under the learned bias.

The authors read this consistent gap as evidence that the extrapolation step drives robustness under compositional shifts.

A second ablation keeps the extrapolated bias and replaces the uniform test prior with empirical group counts from the test set. On Waterbirds, this empirical prior raises average accuracy from 87.1 to 91.6. In the same setting, worst-group accuracy drops from 78.7 to 75.2. The empirical prior assumes the test group frequencies are known, so the authors expected it to help average accuracy rather than worst-group accuracy.

Pairing the learned bias with the empirical prior gives 51.3 worst-group accuracy on Waterbirds.

Across the ablations in Table 13, CRM reaches the best worst-group accuracy on each benchmark it reports. On CelebA, the empirical prior with the extrapolated bias reaches 34.1 worst-group accuracy, far below the 58.9 of the learned bias with the uniform prior. The authors conclude that changing logits with group prior shifts alone isn't enough for compositional generalization.

## Limitations of CRM's assumptions and tested scope

CRM depends on labeled attributes, and the authors note that such labels may not always be available in practice. Pezeshki et al. (2023) and Tsirigotis et al. (2024) first infer spurious attributes, then apply domain generalization methods to subpopulation shifts. The authors see extending those methods to the compositional shift setting, and combining them with CRM, as a promising direction.

The guarantees built on additive energy distributions apply to both discriminative and generative tasks. However, the authors offer a tractable approach using CRM only for the discriminative task. Extending these ideas to the generative counterpart, starting from equation 12, remains future work.

The experiments adapt Waterbirds, CelebA, MetaShift, MultiNLI and CivilComments, and also run NICO++ with the validation set reduced. For multiple spurious attributes, the authors augmented CelebA with three more attributes, giving five attributes in total. The authors note that separate non-linear heads could replace the linear layer that produces the energy components.

The compositional shift setting assumes that p(x\|z) stays the same from train to test, and only the group priors change. The paper reports results only on these benchmarks, so its empirical evidence is limited to them.

## Paper info

- **Authors**: Divyat Mahajan, Mohammad Pezeshki, Charles Arnal, Ioannis Mitliagkas, Kartik Ahuja, Pascal Vincent
- **Venue**: arXiv · Preprint
- **First published**: 2024-10-8
- **Added**: 2026-10-31
- **Updated**: 2025-7-10
- **Version**: v3
- **arXiv**: 2410.06303
- **Category**: cs.LG · cs.AI
- **Original paper terms**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **What we show**: Paper info, commentary and permitted figures from the original paper

[Original paper ↗](https://arxiv.org/abs/2410.06303v3) · [PDF ↗](https://arxiv.org/pdf/2410.06303v3)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Abstract

Compositional generalization is a crucial step towards developing data-efficient intelligent machines that generalize in human-like ways. In this work, we tackle a challenging form of distribution shift, termed compositional shift, where some attribute combinations are completely absent at training but present in the test distribution. This shift tests the model's ability to generalize compositionally to novel attribute combinations in discriminative tasks. We model the data with flexible additive energy distributions, where each energy term represents an attribute, and derive a simple alternative to empirical risk minimization termed compositional risk minimization (CRM). We first train an additive energy classifier to predict the multiple attributes and then adjust this classifier to tackle compositional shifts. We provide an extensive theoretical analysis of CRM, where we show that our proposal extrapolates to special affine hulls of seen attribute combinations. Empirical evaluations on benchmark datasets confirms the improved robustness of CRM compared to other methods from the literature designed to tackle various forms of subpopulation shifts.

## Quote from the paper

Divyat Mahajan, Mohammad Pezeshki, Charles Arnal, Ioannis Mitliagkas, Kartik Ahuja, Pascal Vincent (2024). Compositional Risk Minimization. arXiv:2410.06303v3. https://arxiv.org/abs/2410.06303v3

**BibTeX**

```
@misc{mahajan2024compositional,
  title = {{Compositional Risk Minimization}},
  author = {Divyat Mahajan and Mohammad Pezeshki and Charles Arnal and Ioannis Mitliagkas and Kartik Ahuja and Pascal Vincent},
  year = {2024},
  eprint = {2410.06303},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.06303v3}
}
```

## Related papers

- [Machine learning for lattice QCD](https://refivu.com/en/papers/14a4512c-e395-4867-b986-a1aae0142dc4-machine-learning-for-lattice-qcd.md)
- [Subgroups Matter for Robust Bias Mitigation](https://refivu.com/en/papers/2a39c8a2-c675-4178-942e-a231ced5722f-subgroups-matter-for-robust-bias-mitigation.md)
- [Holistic Evaluation of Language Models](https://refivu.com/en/papers/88eac8fe-87f0-44a8-9be8-34c00f101de4-holistic-evaluation-of-language-models.md)
- [When to Trust a PFN: Detecting Harmful Shift in Tabular Foundation Models](https://refivu.com/en/papers/f72c16f8-edc3-4f30-bb5a-814b2eb7dc46-when-to-trust-a-pfn-detecting-harmful-shift.md)
- [Invariant Risk Minimization](https://refivu.com/en/papers/7f6a0d34-8d04-4205-b5c5-1e73e1c91b62-invariant-risk-minimization.md)
- [Model Cards for Model Reporting](https://refivu.com/en/papers/9ad193b1-a348-4853-9835-2faeecfe0dc1-model-cards-for-model-reporting.md)

## Other paper commentary

- [Learning-Order Autoregressive Models with Application to Molecular Graph Generation](https://refivu.com/en/papers/504d6ec4-8539-4bc7-b02b-fe990e79896e-learning-order-autoregressive-models-with-application-to.md)
- [Stochastic Encodings for Active Feature Acquisition](https://refivu.com/en/papers/dafe6547-b3c0-4ca9-a7fe-82ee925a0c88-stochastic-encodings-for-active-feature-acquisition.md)
- [Scalable Gaussian Processes with Latent Kronecker Structure](https://refivu.com/en/papers/1d5b6ab1-f72e-49ab-842e-cf71b44106cd-scalable-gaussian-processes-with-latent-kronecker-structure.md)
- [On the Computational Complexity of Performative Prediction](https://refivu.com/en/papers/7a4b721a-31e6-4690-bc6d-b8f8286675f0-on-the-computational-complexity-of-performative-prediction.md)
- [Learning to Discover at Test Time](https://refivu.com/en/papers/16b1e431-51ac-4e6b-a951-6aa5a5c017bb-learning-to-discover-at-test-time.md)
- [Feature Learning beyond the Lazy-Rich Dichotomy: Insights from Representational Geometry](https://refivu.com/en/papers/145cac59-29af-46bd-915b-28b2501ff19d-feature-learning-beyond-the-lazy-rich-dichotomy-insights.md)
- [Lower Bounds for Chain-of-Thought Reasoning in Hard-Attention Transformers](https://refivu.com/en/papers/d0ed8609-fa25-4225-88a2-81bbc32dbac9-lower-bounds-for-chain-of-thought-reasoning-in.md)
- [DataDecide: How to Predict Best Pretraining Data with Small Experiments](https://refivu.com/en/papers/b2e5b927-f525-4063-8956-246603aff1fb-datadecide-how-to-predict-best-pretraining-data-with.md)
- [From Generative to Episodic: Sample-Efficient Replicable Reinforcement Learning](https://refivu.com/en/papers/b78b13e6-6d29-4338-85d7-9e0fdb6ad862-from-generative-to-episodic-sample-efficient-replicable.md)
- [Improving Transformer World Models for Data-Efficient RL](https://refivu.com/en/papers/bf0a569b-7476-4cd0-91b8-a28e0935c805-improving-transformer-world-models-for-data-efficient-rl.md)
- [Geometry-Informed Neural Networks](https://refivu.com/en/papers/da0a16b6-9d7a-4d46-a972-fe3929ea063a-geometry-informed-neural-networks.md)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/7f0b2d82-eb6c-417e-a42e-8b6899343b6c-compositional-risk-minimization)
