Compositional Risk Minimization

## Abstract

Abstract In this work, we tackle a challenging and extreme form of subpopulation shift, which is termed compositional shift . Under compositional shifts, some combinations of attributes are totally absent from the training distribution but present in the test distribution. 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.

## 1 Introduction

The ability to make sense of the rich complexity of the sensory world by decomposing it into sets of elementary factors and recomposing these factors in new ways is a hallmark of human intelligence. This capability is typically grouped under the umbrella term compositionality (Fodor and Pylyshyn, ; Montague, ). Compositionality underlies both semantic understanding and the imaginative prowess of humans, enabling robust generalization and extrapolation. For instance, human language allows us to imagine situations we have never seen before, such as “a blue elephant riding a bicycle on the Moon.” While most works on compositionality have focused on its generative aspect, i.e., imagination, as seen in diffusion models (Yang et al., ), compositionality is equally important in discriminative tasks. In these tasks, the goal is to make predictions in novel circumstances that are best described as combinations of circumstances seen before. In this work, we dive into this less-explored realm of compositionality in discriminative tasks.

We work with multi-attribute data, where each input (e.g., an image) is associated with multiple categorical attributes, and the task is to predict an attribute or multiple attributes. During training, we observe inputs from only a subset of all possible combinations of individual attributes, and during test we will see novel combinations of attributes never seen at training. Following, Liu et al. (), we refer to this distribution shift as *compositional shift*. These distribution shifts can also be viewed as an extreme case of subpopulation shift (Yang et al., ). Towards the goal of tackling these compositional shifts, we develop an adaptation of naive discriminative Empirical Risk Minimization (ERM) tailored for multi-attribute data under compositional shifts. We term our approach Compositional Risk Minimization (CRM). The foundations of CRM are built on additive energy distributions that are studied in generative compositionality (Liu et al., ), where each energy term represents one attribute. In CRM, we first train an additive energy classifier to predict all the attributes jointly, and then we adjust this classifier for compositional shifts.

Our main contributions are as follows:

- •
*Theory of discriminative compositional shifts:* For the family of additive energy distributions, we prove that additive energy classifiers generalize compositionally to novel combinations of attributes represented by a special mathematical object, which we call *discrete affine hull*. Our characterization of extrapolation is sharp, i.e., we show that it is not possible to generalize beyond *discrete affine hull*. We show that the volume of *discrete affine hull* grows fast in the number of training attribute combinations thus generalizing to many attribute combinations. The proofs developed in this work are quite different from existing works on distribution shifts and hence may be of independent interest.
- •
*A practical method:* CRM is a simple algorithm for training classifiers, which first trains an additive energy classifier and then adjusts the trained classifier for tackling compositional shifts. We empirically validate the superiority of the CRM algorithm to other algorithms previously proposed for robustness to various forms of subpopulation shifts.

Figure: Figure 1: The additive energy classifier trained in CRM computes the logits for each group $z=(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 bias $B(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^{\star}(y,a)$, are extrapolated using Eq.10. Finally, we obtain $p(y,a|x)$ by applying softmax function on the adjusted logits. This adaptation from train to test is possible because of the additive energy distribution $p(x|y,a)$, which allows the model to factorize the distribution into distinct components associated with each attribute.
Refer to caption: x1.png

## 2 Related Works

#### Compositional Generalization

Compositionality has long been seen as an essential capability (Fodor and Pylyshyn, ; Hinton, ; Plate et al., ; Montague, ) on the path to building human-level intelligence.
The history of compositionality being too long to cover in detail here, we refer the reader to these surveys (Lin et al., ; Sinha et al., ).
Most prior works have focused on generative aspect of compositionality, where the model needs to recombine individual distinct factors/concepts and generate the final output in the form of text (Gordon et al., ; Lake and Baroni, ) or image. For image generation in particular, a fruitful line of work is rooted in additive energy based models (Du et al., , ; Liu et al., ; Nie et al., ),
which translates naturally to additive diffusion models (Liu et al., ; Su et al., ).
Our present work also leverages an additive energy form, but our focus is on learning classifiers robust under compositional shifts, rather than generative models.

On the theoretical side, recently, there has been a growing interest in building provable approaches for compositional generalization (Dong and Ma, ; Wiedemer et al., , ; Brady et al., ; Lachapelle et al., ). These works study models where the labeling function or the decoder is additive over individual features, and prove generalization guarantees over the Cartesian product of the support of individual features. While these works take promising and insightful first steps for provable compositional guarantees, the assumption of additive deterministic decoders may come as quite restrictive. In particular a given attribute combination can then only correspond to a *unique* observation, produced by a very limited interaction between generative factors, not to a rich distribution of observations. By contrast an additive energy model can associate an almost arbitrary distribution over observations to a given set of attributes.
Based on this more realistic assumption of additive energy, our goal is to develop an approach that provably enables *zero-shot compositional generalization in discriminative tasks*, where the model needs to robustly predict never seen before factor combinations that the input is composed of.

#### Domain Generalization

Generalization under subpopulation shifts, where certain groups or combinations of attributes are underrepresented in the training data, is a well-known challenge in machine learning. Group Distributionally Robust Optimization (GroupDRO) (Sagawa et al., ) is a prominent method that minimizes the worst-case group loss to improve robustness across groups. Invariant Risk Minimization (IRM) (Arjovsky et al., ) encourages the model to learn invariant representations that perform well across multiple environments. Perhaps the simplest methods are SUBG and RWG (Idrissi et al., ), which focus on constructing a balanced subset or reweighting examples to minimize or eliminate spurious correlations. There are many other interesting approaches that were proposed, see the survey (Zhou et al., ) for details.
The theoretical guarantees developed for these approaches (Rosenfeld et al., ; Arjovsky et al., ; Ahuja et al., ) require a large diversity in terms of the environments seen at the training time. In our setting, we incorporate inductive biases based on additive energy distributions that help us arrive at provable generalization with limited diversity in the environments.

Closely related to our proposed method are the logit adjustment methods Kang et al. (); Menon et al. (); Ren et al. () used in robust classification.
Kang et al. () introduced Label-Distribution-Aware Margin (LDAM) loss for long-tail learning, proposing a method that adjusts the logits of a classifier based on the class frequencies in the training set to counteract bias towards majority classes.
Closest to our work are the Logit Correction (LC) (Liu et al., ) and Supervised Logit Adjustment (sLA) (Tsirigotis et al., ) methods that use logit adjustment for group robustness.
LC adjusts logits based on the joint distribution of environment and class label, reducing reliance on spurious features in imbalanced training sets.
Supervised Logit Adjustment (sLA) adjusts logits according to the conditional distribution of classes given the environment.

## 3 Problem Setting

### 3.1 Generalizing under Compositional Distribution Shift

In compositional generalization, we aim to build a classifier that performs well in new contexts that are best described as a novel combination of seen contexts. Consider an input $x$ (e.g., image), this input belongs to a group that is characterized by an attribute vector $z=(z_{1},\ldots,z_{m})$ (e.g., class label, background label), where
$z_{i}$ corresponds to the value of $i^{th}$ attribute. There are $m$ attributes and each attribute $z_{i}$ can take $d$ possible values. So $z\in\mathcal{Z}$ with $\mathcal{Z}=\{1,\ldots,d\}^{m}$.

We use the Waterbirds dataset as the running example (Sagawa et al., ). Each image $x$ has two attributes summarized in the attribute vector $z=(y,a)$, where $y$ tells the class of the bird – Waterbird (WB) or Landbird (LB), and $a$ tells the type of the background – Water (W) or Land (L). Our training distribution consists of data from three groups – ($\text{WB},\text{W}$), ($\text{LB},\text{L}$), ($\text{LB},\text{W}$). Our test distribution also consists of points from the remaining group $(\text{WB},\text{L})$ as well. We seek to build class predictors that perform well on such test distributions that contain new groups. This problem setting differs from the standard problem studied in (Sagawa et al., ; Kirichenko et al., ), where we observe data from all the groups but some groups present much more data than the others.

Formally, let $p(x,z)=p(z)p(x|z)$ denote the train distribution, and $q(x,z)=q(z)q(x|z)$
the test distribution.
We denote the support of each attribute component $z_{i}$ under training distribution as $\mathcal{Z}_{i}^{\mathsf{train}}$ and the support of $z$ under training distribution as $\mathcal{Z}^{\mathsf{train}}$. The corresponding supports for the test distribution are denoted as $\mathcal{Z}_{i}^{\mathsf{test}}$ and $\mathcal{Z}^{\mathsf{test}}$.
We define the Cartesian product of marginal support under training as ${\mathcal{Z}^{\times}}\coloneq\mathcal{Z}_{1}^{\mathsf{train}}\times\mathcal{Z
}_{2}^{\mathsf{train}}\times\cdots\mathcal{Z}_{m}^{\mathsf{train}}$.

In this work, we study *compositional shifts* that are characterized by:

- 1.
$p(x|z)=q(x|z),\forall z\in{\mathcal{Z}^{\times}}.$
- 2.
$\mathcal{Z}^{\mathsf{test}}\not\subseteq\mathcal{Z}^{\mathsf{train}}$ but
$\mathcal{Z}^{\mathsf{test}}\subseteq{\mathcal{Z}^{\times}}$.

The first point states that the conditional density of inputs conditioned on attributes remains invariant from train to test, which can be understood as the data generation mechanism from attributes to the inputs remains invariant. What changes between train and test is thus due to only shifting prior probabilities of attributes from $p(z)$ to $q(z)$. The second point specifies how these differ in their support: at test we observe novel combinations of individual attributes but not a completely new individual attribute. The task of compositional generalization is then to build classifiers that are robust to such compositional distribution shifts. Also, we remark that the above notion should remind the reader of the notion of Cartesian Product Extrapolation (CPE) from Lachapelle et al. (). Specifically, if a model succeeds on test distributions $q(z)$ that have a support equal to the full Cartesian product, i.e., $\mathcal{Z}^{\mathsf{test}}={\mathcal{Z}^{\times}}$, then it is said to achieve CPE.

### 3.2 Additive Energy Distribution

We assume that $p(x|z)$ is of the form of an *additive energy distribution* (AED):

$$ $p(x|z)=\frac{1}{\mathbb{Z}(z)}\exp\Big{(}-\sum_{i=1}^{m}E_{i}(x,z_{i})\Big{)}$ (1) $$

where
$\mathbb{Z}(z)\coloneq\bigintsss\exp\Big{(}-\sum_{i=1}^{m}E_{i}(x,z_{i})\Big{)}dx$ is the partition function that ensures that the probability density $p(x|z)$ integrates to one. Also, the support of $p(x|z)$ is assumed to be $\mathbb{R}^{n}$, $\forall z\in{\mathcal{Z}^{\times}}$.

We thus have one energy term $E_{i}$ associated to each attribute $z_{i}$.
Note that we do not make assumptions on $E_{i}$ except $\mathbb{Z}(z)<\infty$, leaving the resulting $p(x|z)$ very flexible. This form is a natural choice to model inputs that must satisfy a *conjunction* of characteristics (such as being a natural image of a landbird *AND* having a water background), corresponding to our attributes.

There are two lines of work that inspire the choice of additive energy distributions. Firstly, these distributions have been used to enhance compositionality in generative tasks  (Du et al., , ; Liu et al., )
but they have not been used in discriminative compositionality. Secondly, for readers from the causal machine learning community, it may be useful to think of additive energy distributions from the perspective of the independent mechanisms principle (Janzing and Schölkopf, ; Parascandolo et al., ). The principle states that the data distribution is composed of independent data generation modules, where the notion of independence refers to algorithmic independence and not statistical independence. In these distributions, we think of energy functions of different attributes as independent functions.

Recall $z=(z_{1},\ldots,z_{m})$ is a vector of $m$ categorical attributes that can each take $d$ possible values. We will denote as $\sigma(z)$ the representation of this attribute vector as a concatenation of $m$ one-hot vectors, i.e.

$$ $\sigma(z)=[\mathrm{onehot}(z_{1}),\ldots,\mathrm{onehot}(z_{m})]^{\top}$ $$

Thus $\sigma(z)$ will be a sparse vector of length $md$ containing $m$ ones.

We also define a vector valued map
$E(x)=[E_{1}(x,1),\ldots,E_{1}(x,d),\ldots,E_{m}(x,1),\ldots,E_{m}(x,d)]^{\top}$ where $E_{i}(x,z_{i})$ is the energy term for $i^{th}$ attribute taking the value $z_{i}$.

This allows us to reexpress equation 1 using a simple dot product, denoted $\braket{\cdot,\cdot}$:

$$ $p(x|z)=\frac{1}{\mathbb{Z}(z)}\exp\Big{(}-\braket{\sigma(z),E(x)}\Big{)},$ (2) $$

where $\mathbb{Z}(z)=\bigintsss\exp\Big{(}-\braket{\sigma(z),E(x)}\Big{)}dx$ is the partition function.

## 4 Provable Compositional Generalization

Our goal is to learn a distribution $\hat{q}(z|x)$ that matches the test distribution $q(z|x)$ and predict the attributes at test time in a Bayes optimal manner. If we successfully learn the distribution $q(z|x)$, then we can also predict the individual attributes $q(z_{i}|x)$, e.g., the bird class in Waterbirds dataset, by marginalizing over the rest of the attributes, e.g., the background in Waterbirds dataset. Observe that $q(z|x)$ differs from the training $p(z|x)$, which can be estimated through standard ERM with cross-entropy loss. Since some attributes $z$ observed at test time are never observed at train time, the distribution learned via ERM assigns a zero probability to these attributes and thus it cannot match the test distribution $q(z|x)$.

In what follows, we first introduce a novel mathematical object termed *Discrete Affine Hull* over the set of attributes. We then describe a generative approach for classification that requires us to learn $p(x|z)$ including the partition function, which is not practical. Next, we describe a purely discriminative approach that circumvents the issue of learning $\hat{p}(x|z)$ and achieves the same extrapolation guarantees. We present the generative approach as it allows to understand the results more easily. Building generative models based on our theory is out of scope of this work but is an exciting future work.

### 4.1 Discrete Affine Hull

We define the *discrete affine hull* of a set of attribute vectors $\mathcal{A}=\{z^{(1)},\ldots,z^{(k)}\}$ where $z^{(i)}\in\mathcal{Z}$, as:

$$ $\mathsf{DAff}(\mathcal{A})=\Big{\{}z\in\mathcal{Z}\;|\;\exists\;\alpha\in \mathbb{R}^{k},\sigma(z)=\sum_{i=1}^{k}\alpha_{i}\sigma\big{(}z^{(i)}\big{)}, \sum_{i=1}^{k}\alpha_{i}=1\Big{\}}$ $$

In other words, the discrete affine hull of $\mathcal{A}$ is the set of all possible attribute vectors whose one-hot encoding is in the (regular) affine hull of the one-hot encodings of the attribute vectors of $\mathcal{A}$.
This construct will be used to characterize what new combinations of attributes we can extrapolate to. We now give a simple example to illustrate discrete affine hull.

Let us revisit the Waterbirds dataset. Suppose we observe data from three out of the four groups. In one-hot encoding, we represent WB as $[1,0]$ and LB as $[0,1]$. We represent Water as $[1,0]$ and Land as $[0,1]$. Below we show that the attribute vector WB on L represented as $[1\;0\;0\;1]$ can be expressed as an affine combination of the remaining three attribute vectors. Based on this, we can conclude that the discrete affine hull of three one-hot concatenated vectors contains all the four possible one-hot concatenations.

$$ $(+1)\cdot\begin{bmatrix}0\\ 1\\ 0\\ 1\end{bmatrix}\;\;+\;\;(-1)\cdot\begin{bmatrix}0\\ 1\\ 1\\ 0\end{bmatrix}\;\;+\;\;(+1)\cdot\begin{bmatrix}1\\ 0\\ 1\\ 0\end{bmatrix}=\begin{bmatrix}1\\ 0\\ 0\\ 1\end{bmatrix}$ (3) $$

In Section 9.4, we generalize the above finding and develop a mathematical characterization of discrete affine hulls that leads to an easy recipe to visualize these sets. In the remainder whenever we use affine hull it means discrete affine hull.

### 4.2 Extrapolation of Conditional Density

We learn a set of conditional probability densities $\hat{p}(x|z)=\frac{1}{\hat{\mathbb{Z}}(z)}\exp\Big{(}-\braket{\sigma(z),\hat{E
}(x)}\Big{)},\forall z\in\mathcal{Z}^{\mathsf{train}}$ by maximizing the likelihood over the training distribution, where $\hat{E}$ denotes the estimated energy components and $\hat{\mathbb{Z}}$ denotes the estimated partition function. Under perfect maximum likelihood maximization $\hat{p}(x|z)=p(x|z)$ for all the training groups $z\in\mathcal{Z}^{\mathsf{train}}$. We can define $\hat{p}(x|z)$ for all $z\in{\mathcal{Z}^{\times}}$ beyond $\mathcal{Z}^{\mathsf{train}}$ in a natural way as follows. For each $z\in{\mathcal{Z}^{\times}}$, we have estimated the energy for every individual component $z_{i}$ denoted $\hat{E}_{i}(x,z_{i})$. We set $\hat{\mathbb{Z}}(z)=\bigintsss\exp\Big{(}-\braket{\sigma(z),\hat{E}(x)}\Big{)}dx$ and the density for each $z\in{\mathcal{Z}^{\times}}$, $\hat{p}(x|z)=\frac{1}{\hat{\mathbb{Z}}(z)}\exp\Big{(}-\braket{\sigma(z),\hat{E
}(x)}\Big{)}$.

###### Theorem 1 .

If the true and learned distribution ($p(\cdot|z)$ and $\hat{p}(\cdot|z)$) are additive energy distributions,
then $\hat{p}(\cdot|z)=p(\cdot|z),\forall z\in\mathcal{Z}^{\mathsf{train}}\implies
\hat{p}(\cdot|z^{\prime})=p(\cdot|z^{\prime}),\forall z^{\prime}\in\mathsf{
DAff}(\mathcal{Z}^{\mathsf{train}})$.

The result above argues that so long as the group $z^{\prime}$ is in the discrete affine hull of $\mathcal{Z}^{\mathsf{train}}$, the estimated density extrapolates to it.

*Proof sketch:* Under perfect maximum likelihood maximization $\hat{p}(x|z)=p(x|z),\forall z\in\mathcal{Z}^{\mathsf{train}}$. Replacing these densities by their expressions and taking their $\log$ we obtain

$$ $\braket{\sigma(z),\hat{E}(x)}=\braket{\sigma(z),E(x)}+C(z),\forall z\in \mathcal{Z}^{\mathsf{train}}$ (4) $$

where $C(z)=\log\big{(}\mathbb{Z}(z)/\hat{\mathbb{Z}}(z)\big{)}$.

For any $z^{\prime}\in\mathsf{DAff}(\mathcal{Z}^{\mathsf{train}})$, by definition there exists $\alpha$ such that $\sigma(z^{\prime})=\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\sigma(z)$.
Thus $\braket{\sigma(z^{\prime}),\hat{E}(x)}=\sum_{z\in\mathcal{Z}^{\mathsf{train}}}
\alpha_{z}\braket{\sigma(z),\hat{E}(x)}$, by linearity of the dot product.
Substituting the expression for $\braket{\sigma(z),\hat{E}(x)}$ from equation 4, this becomes

$$ $\begin{split}\braket{\sigma(z^{\prime}),\hat{E}(x)}=\sum_{z\in\mathcal{Z}^{ \mathsf{train}}}\alpha_{z}\Big{(}\braket{\sigma(z),E(x)}+C(z)\Big{)}=\braket{ \sigma(z^{\prime}),E(x)}+\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}C(z) ,\end{split}$ (5) $$

From equation 5, we can conclude that $\braket{\sigma(z^{\prime}),\hat{E}(x)}$ estimates $\braket{\sigma(z^{\prime}),E(x)}$ perfectly up to a constant error that does not depend on $x$. This difference of constant is absorbed by the partition function and hence the conditional densities match: $\hat{p}(x|z^{\prime})=p(x|z^{\prime})$.

###### Theorem 1 .

#### Using extrapolation of conditional density for compositional generalization of classification.

If, on data from training distribution $p$, we were able to train a good conditional density estimate $\hat{p}(x|z),\forall z\in\mathcal{Z}^{\mathsf{train}}$, then Theorem 1 implies that
$\hat{p}(x|z^{\prime})$ will also be a good estimate of $p(x|z^{\prime})$ for *new unseen* attributes $z^{\prime}\in\mathsf{DAff}(\mathcal{Z}^{\mathsf{train}})$.
Provided $\mathcal{Z}^{\mathsf{test}}\subseteq\mathsf{DAff}(\mathcal{Z}^{\mathsf{train}})$, it is then straightforward to obtain a classifier that generalizes to compositionally-shifted test distribution $q$. Indeed, we have

$$ $q(z^{\prime}|x)=\frac{q(x|z^{\prime})q(z^{\prime})}{\sum_{z^{\prime\prime}\in \mathcal{Z}^{\mathsf{test}}}q(x|z^{\prime\prime})q(z^{\prime\prime})}=\frac{p( x|z^{\prime})q(z^{\prime})}{\sum_{z^{\prime\prime}\in\mathcal{Z}^{\mathsf{test }}}p(x|z^{\prime\prime})q(z^{\prime\prime})}\approx\frac{\hat{p}(x|z^{\prime}) q(z^{\prime})}{\sum_{z^{\prime\prime}\in\mathcal{Z}^{\mathsf{test}}}\hat{p}(x| z^{\prime\prime})q(z^{\prime\prime})}$ $$

where we used the property of compositional shifts $q(x|z)=p(x|z)$. If we know test group prior $q(z^{\prime})$ (or e.g. assume it to be uniform), we can directly use the expression in RHS to correctly compute the test group probabilities $q(z|x)$, even those for attribute combinations never seen at training.

### 4.3 Extrapolation of Discriminative Model

In Section 4.2, we saw how we could, in principle, obtain a classifier that generalizes under compositional shift, by first training conditional probability density models $\hat{p}(x|z)$. But high dimensional probability density modeling remains very challenging, and involves dealing with intractable partition functions. It is typically deemed much simpler to learn a discriminative classifier.

Can we achieve the same extrapolation without having to estimate the entire distribution of $x$ conditional on $z$? This question brings us to our method, which we refer to as Compositional Risk Minimization (CRM).

Observe that if we apply Bayes rule to the AED $p(x|z)$ in equation 2, we get

$$ $p(z|x)=\frac{p(x|z)p(z)}{\sum_{z^{\prime}\in\mathcal{Z}^{\mathsf{train}}}p(x|z ^{\prime})p(z^{\prime})}=\frac{\exp\Big{(}-\braket{\sigma(z),E(x)}+\log p(z)- \log\mathbb{Z}(z)\Big{)}}{\sum_{z^{\prime}\in\mathcal{Z}^{\mathsf{train}}}\exp \Big{(}-\braket{\sigma(z^{\prime}),E(x)}+\log p(z^{\prime})-\log\mathbb{Z}(z^{ \prime})\Big{)}}$ $$

We thus define our *additive energy classifier* as follows.
To guarantee that we can model this $p(z|x)$, we use a model with the same *form*. For each $z\in\mathcal{Z}^{\mathsf{train}}$

$$ $\tilde{p}(z|x)=\frac{\exp\bigg{(}-\braket{\sigma(z),\tilde{E}(x)}+\log\hat{p}( z)-\tilde{B}(z)\bigg{)}}{\sum_{z^{\prime}\in\mathcal{Z}^{\mathsf{train}}}\exp \bigg{(}-\braket{\sigma(z^{\prime}),\tilde{E}(x)}+\log\hat{p}(z^{\prime})- \tilde{B}(z^{\prime})\bigg{)}},$ (6) $$

where $\hat{p}(z)$ is the empirical estimate of the prior over $z$, i.e., $p(z)$, $\tilde{E}:\mathbb{R}^{n}\rightarrow\mathbb{R}^{md}$ is a function to be learned, bias $\tilde{B}$ is a lookup table containing a learnable offset for each combination of attribute. Given a data point $(x,z)$, loss $\ell(z,\tilde{p}(\cdot|x))=-\log\tilde{p}(z|x)$ measures the prediction performance of $\tilde{p}(\cdot|x)$. The risk is defined as the expected loss as follows

$$ $R(\tilde{p})=\mathbb{E}_{(x,z)\sim p}\Big{[}\ell(z,\tilde{p}(\cdot|x))\Big{]}= \mathbb{E}_{(x,z)\sim p}\Big{[}-\log\tilde{p}(z|x)\Big{]}.$ (7) $$

In the first step of CRM, we minimize the risk $R$.

$$ $\hat{E},\hat{B}\in\operatorname*{arg\,min}_{\tilde{E},\tilde{B}}R(\tilde{p}).$ (8) $$

If the minimization is over arbitrary functions, then $\hat{p}(\cdot|x)=p(\cdot|x),\forall x\in\mathbb{R}^{n}$. In the second step of CRM, we compute our final predictor $\hat{q}(z|x)$ as follows. Let $\hat{q}(z)$ be an estimate of the marginal distribution over the attributes $q(z)$ with support $\hat{\mathcal{Z}}^{\mathsf{test}}$.
We define, for each $z\in\mathcal{Z}^{\mathsf{test}}$,

$$ $\hat{q}(z|x)=\frac{\exp\bigg{(}-\braket{\sigma(z),\hat{E}(x)}+\log\hat{q}(z)-B ^{\star}(z)\bigg{)}}{\sum_{z^{\prime}\in\hat{\mathcal{Z}}^{\mathsf{test}}}\exp \bigg{(}-\braket{\sigma(z^{\prime}),\hat{E}(x)}+\log\hat{q}(z^{\prime})-B^{ \star}(z^{\prime})\bigg{)}},$ (9) $$

where, $B^{\star}$ is the *extrapolated bias* defined as

$$ $B^{\star}(z)=\log\Bigg{(}\mathbb{E}_{x\sim p(x)}\Bigg{[}\frac{\exp\Big{(}- \braket{\sigma(z),\hat{E}(x)}\Big{)}}{\sum_{\tilde{z}\in\mathcal{Z}^{\mathsf{ train}}}\exp\Big{(}-\braket{\sigma(\tilde{z}),\hat{E}(x)}+\log p(\tilde{z})- \hat{B}(\tilde{z})\Big{)}}\Bigg{]}\Bigg{)}$ (10) $$

where $\hat{E}$, $\hat{B}$ are the solutions from optimization equation 8.
Each of these steps is easy to operationalize. We explain the process and provide pseudocode in Section 5
.

###### Theorem 2 .

Consider the setting where $p(.|z)$ follows AED $\forall z\in{\mathcal{Z}^{\times}}$, the test distribution $q$ satisfies compositional shift characterization and
$\mathcal{Z}^{\mathsf{test}}\subseteq\mathsf{DAff}(\mathcal{Z}^{\mathsf{train}})$. If $\hat{p}(z|x)=p(z|x),\forall z\in\mathcal{Z}^{\mathsf{train}},\forall x\in
\mathbb{R}^{n}$ and $\hat{q}(z)=q(z),\forall z\in\mathcal{Z}^{\mathsf{test}}$, then the output of CRM (equation 9) matches the test distribution, i.e., $\hat{q}(z|x)=q(z|x),\forall z\in\mathcal{Z}^{\mathsf{test}},\forall x\in
\mathbb{R}^{n}$.

A complete proof is provided in the Appendix. Observe that $\hat{p}(\cdot|x)=p(\cdot|x)$ is a condition that even a model trained via ERM can satisfy (with sufficient capacity and data) but it cannot match the true $q(\cdot|x)$. In contrast, CRM optimally adjusts the additive-energy classifier for the compositional shifts.
CRM requires the knowledge of $q(\cdot)$ but the choice of uniform distribution over all possible groups is a safe one to make in the absence of knowledge of $q(\cdot)$.
Notice how learned bias $\hat{B}(z)$ can only be fitted for $z\in\mathcal{Z}^{\mathrm{train}}$, remaining undefined for $z^{\prime}\notin\mathcal{Z}^{\mathrm{train}}$. But we can compute the extrapolated bias $B^{\star}(z^{\prime})$, $\forall z^{\prime}\in\mathcal{Z}^{\mathrm{test}}$, *based remarkably on only data from the training distribution*.

In the discussion so far, we have relied on a crucial assumption that the attribute combinations in the test distribution are in the affine hull. Is this also a *necessary* condition? Can we generalize to attributes outside the affine hull? We consider the task of learning $p(\cdot|z)$ from Theorem 1 and the task of learning $q(\cdot|x)$ from Theorem 2. In Section 9.5 in the Appendix, we show that the restriction to affine hulls is indeed necessary.

Under the assumption of compositional shifts, we know that the support of $q(z)$, $\mathcal{Z}^{\mathsf{test}}$ is only restricted to be a subset of the Cartesian product set ${\mathcal{Z}^{\times}}$, but our results so far have required us to restrict the support further by confining it to the affine hull, i.e., $\mathcal{Z}^{\mathsf{test}}\subseteq\mathsf{DAff}(\mathcal{Z}^{\mathsf{train}}
)\subseteq{\mathcal{Z}^{\times}}$. This leads us to a natural question. If the training groups that form $\mathcal{Z}^{\mathsf{train}}$ are drawn at random, then how many groups do we need such that the affine hull captures ${\mathcal{Z}^{\times}}$, i.e., $\mathsf{DAff}(\mathcal{Z}^{\mathsf{train}})={\mathcal{Z}^{\times}}$, at which point CRM can achieve Cartesian Product Extrapolation. Another way to think about this is to say, how fast does the affine hull grow and capture the Cartesian product set ${\mathcal{Z}^{\times}}$?

Consider the the setting with $m=2$ attribute dimensions, where each attribute takes $d$ possible values. In such a case, we have $d^{2}$ possible attribute combinations. Suppose we sample $s$ attribute vectors $z$ that comprise the support $\mathcal{Z}^{\mathsf{train}}$ uniformly at random (with replacement) from these $d^{2}$ possibilites. In the next theorem, we show that if the number of sampled attribute vectors exceeds $8cd\log(d)$, then the affine hull of $\mathcal{Z}^{\mathsf{train}}$ contains all the possible $d^{2}$ combinations with a high probability and as a result CRM achieves CPE.

###### Theorem 3 .

Consider the setting where $p(.|z)$ follows AED $\forall z\in{\mathcal{Z}^{\times}}$, $\mathcal{Z}^{\mathsf{train}}$ comprises of $s$ attribute vectors $z$ drawn uniformly at random from ${\mathcal{Z}^{\times}}$, and the test distribution $q$ satisfies compositional shift characterization. If $s\geq 8cd\log(d/2)$, where $d$ is sufficiently large, $\hat{p}(z|x)=p(z|x),\forall z\in\mathcal{Z}^{\mathsf{train}},\forall x\in
\mathbb{R}^{n}$, $\hat{q}(z)=q(z),\forall z\in\mathcal{Z}^{\mathsf{test}}$, then the output of CRM (equation 9) matches the test distribution, i.e., $\hat{q}(z|x)=q(z|x)$, $\forall z\in\mathcal{Z}^{\mathsf{test}},\forall x\in\mathbb{R}^{n}$, with probability greater than $1-\frac{1}{c}$.

For the more general setting of $m$ attributes, we conjecture that a polynomial growth in $md$, i.e., $\mathcal{O}(\mathsf{poly}(md))$, groups suffice to generalize to distributions whose support span $d^{m}$ groups. To support this conjecture, we conduct numerical experiments (described in the Appendix), where we show that a random $z^{\prime}\in{\mathcal{Z}^{\times}}$ is in the affine span of a random set of $\mathcal{O}(md)$ training groups $z$ with a high probability. To summarize, these results point to a surprising fact that, we need to see data from a much smaller number of groups to achieve extrapolation to an exponentially large set.

###### Theorem 2 .

###### Theorem 3 .

## 5 Algorithm for Compositional Risk Minimization (CRM)

In a nutshell, CRM consists of: a) training a model of the form of equation 6 by maximum likelihood (equation 8) for trainset group prediction; b) compute extrapolated biases (equation 10); c) infer group probabilities on compositionally shifted test distribution using equation 9. For the case where we have 2 attributes $z=(y,a)$, Figure 1 illustrates a basic architecture using a deep network backbone $\phi(x;\theta)$ followed by a linear mapping (matrix $W$), and Algorithm 1 provides the associated pseudo-code.(^1^11The figure’s architecture computes the logits $F_{L,B}(x)$ as implemented in the pseudocode. Alternatively to a single linear head whose output we split, we could use separate arbitrary (non-linear) heads to obtain the components for each attribute. Architecture and code can easily be generalized to handle more than 2 attributes.)

Figure: Algorithm 1 Compositional Risk Minimization (CRM)

## 6 Experiments

### 6.1 Setup

We evaluate CRM on widely recognized benchmarks for subpopulation shifts (Yang et al., ), that have 2 attributes $z=(y,a)$, where $y$ denotes the class label and $a$ denotes the spurious attribute ($y$ and $a$ are correlated). However, the standard split between train and test data mandated in these benchmarks does not actually evaluate robustness to compositional shifts, because both train and test datasets contain all the groups ($\mathcal{Z}^{\mathsf{train}}=\mathcal{Z}^{\mathsf{test}}={\mathcal{Z}^{\times}}$). Therefore, we repurpose these benchmarks for compositional shifts by discarding samples from one of the groups ($z$) in the train (and validation) dataset; but we don’t change the test dataset, i.e., $z\not\in\mathcal{Z}^{\mathsf{train}}$ but $z\in\mathcal{Z}^{\mathsf{test}}$.
Let us denote the data splits from the standard benchmarks as $({\mathcal{D}}_{\mathsf{train}},{\mathcal{D}}_{\mathsf{val}},{\mathcal{D}}_{
\mathsf{test}})$. Then we generate multiple variants of compositional shifts $\{({\mathcal{D}}_{\mathsf{train}}^{\neg z},{\mathcal{D}}_{\mathsf{val}}^{\neg z
},{\mathcal{D}}_{\mathsf{test}})\;|\;z\in{\mathcal{Z}^{\times}}\}$, where ${\mathcal{D}}_{\mathsf{train}}^{\neg z}$ and ${\mathcal{D}}_{\mathsf{val}}^{\neg z}$ are generated by discarding samples from ${\mathcal{D}}_{\mathsf{train}}$ and ${\mathcal{D}}_{\mathsf{val}}$ that belong to the group $z$.

Following this procedure, we adapted Waterbirds (Wah et al., ), CelebA (Liu et al., ), MetaShift (Liang and Zou, ), MultiNLI (Williams et al., ), and CivilComments Borkan et al. () for experiments. We also experiment with the NICO++ dataset (Zhang et al., ), where we already have $\mathcal{Z}^{\mathsf{train}}\subsetneq\mathcal{Z}^{\mathsf{test}}={\mathcal{Z}
^{\times}}$ as some groups were not present in the train dataset.
However, these groups are still present in the validation dataset ($\mathcal{Z}^{\mathsf{val}}={\mathcal{Z}^{\times}}$). Hence, the only transformation we apply to NICO++ is to drop samples from the validation dataset such that $\mathcal{Z}^{\mathsf{train}}=\mathcal{Z}^{\mathsf{val}}$.

For baselines, we train classifiers via Empirical Risk Minimization (ERM), GroupDRO (Sagawa et al., ), Logit Correction (LC) (Liu et al., ), and supervised logit adjustment (sLA) (Tsirigotis et al., ). In all cases we employ a pretrained architecture as the representation network $\phi$, followed by a linear layer $W$ to get class predictions, and fine-tune them jointly (see Section 10.3 for details).
For evaluation metrics, we report the average accuracy, group balanced accuracy, and worst-group accuracy on the test dataset. Due to imbalances in group distribution, a method can obtain good average accuracy despite having bad worst-group accuracy. Therefore, the worst-group accuracy is a more indicative metric of robustness to spurious correlations (more details in Section 10.2).

### 6.2 Results

Table 1 shows the results of our experiment. For each dataset, we report the *average* accuracy over its various compositional shift scenarios $\{({\mathcal{D}}_{\mathsf{train}}^{\neg z},{\mathcal{D}}_{\mathsf{val}}^{\neg z
},{\mathcal{D}}_{\mathsf{test}})\;|\;z\in{\mathcal{Z}^{\times}}\}$ (detailed results for all scenarios are in Section 11.1). In all cases, CRM either outperforms or is competitive with the baselines in terms of worst group accuracy (WGA). Further, for Waterbirds and MultiNLI, while the logit adjustment baselines appear competitive with CRM on average, if we look more closely at the worst case compositional shift scenario, we find that logit adjustment baselines fare much worse than CRM. For Waterbirds, LC obtains $69.0\%$ worst group accuracy while CRM obtains $73.0\%$ worst group accuracy for the worst case scenario of dropping the group $(0,1)$ (Table 5). Similarly, for the MultiNLI benchmark, sLA obtains $19.7\%$ worst group accuracy while CRM obtains $31.0\%$ worst group accuracy for the worst case scenario of dropping the group $(0,0)$ (Table 8).

We also report the worst group accuracy (other metrics in Table 11) for the original benchmark $({\mathcal{D}}_{\mathsf{train}},{\mathcal{D}}_{\mathsf{val}},{\mathcal{D}}_{
\mathsf{train}})$ which was not transformed for compositional shifts, denoted WGA (No Groups Dropped). WGA (No Groups Dropped) can be interpreted as the “oracle” performance for that benchmark, and we can compare methods based on the performance drop in WGA due to discarding groups in compositional shifts. ERM and GroupDRO appear the most sensitive to compositional shifts, and the logit adjustment baselines also show a sharp drop for the CelebA benchmark; while CRM is more robust to compositional shifts.

#### Importance of extrapolating the bias.

We conduct an ablation study for CRM where we test a variant that uses the learned bias $\hat{B}$ (e.q. 8) instead of the extrapolated bias $B^{\star}$ (e.q. 10). Results are presented in Table 2. They show a significant drop in worst-group accuracy if we use the learned bias instead of the extrapolated one. Hence, our theoretically grounded bias extrapolation step is crucial to generalize under compositional shifts. In Section 11.1 (Table 10) we conduct further ablation studies, showing the impact of different choices of the test log prior.

## 7 Conclusion

We provide a novel approach based on flexible additive energy models for compositionality in discriminative tasks. Our proposed CRM approach can provably extrapolate to novel attribute combinations within the discrete affine hull of the training support, where the affine hull grows quickly with the training groups to cover the Cartesian product extension of the training support. Our empirical results demonstrate that the additive energy assumption is sufficiently flexible to yield good classifiers for high-dimensional images, and that the proposed CRM estimator is able to extrapolate to novel combinations in $\mathsf{DAff}(\mathcal{Z}^{\mathsf{train}})$, without having to model high-dimensional $p(x|z)$ nor having to estimate their partition function. CRM is a simple and efficient algorithm that empirically proved consistently more robust to compositional shifts than approaches based on other logit-shifting schemes and GroupDRO.

**Table 1: Robustness under compositional shift. We compare the proposed Compositional Risk Minimization (CRM) method to baseline Expected Risk Minimization (ERM) classifier training with no group information, and to robust methods that leverage group labels: Group-DRO (G-DRO) (Sagawa et al., ), Logit Correction (LC) (Liu et al., ) and Supervised Logit Adjustment (sLA) (Tsirigotis et al., ). We report test Average Accuracy and Worst Group Accuracy (WGA), 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 (standard error based on 3 random seeds).**
| Dataset | Method | Average Acc | WGA | WGA<br>(No Groups Dropped) |
| --- | --- | --- | --- | --- |
| Waterbirds | ERM | $77.9$ $(0.1)$ | $43.0$ $(0.1)$ | $62.3$ $(1.2)$ |
| G-DRO | $77.9$ $(0.6)$ | $42.3$ $(2.5)$ | $87.3$ $(0.3$ |  |
| LC | $88.3$ $(0.7)$ | $75.5$ $(0.8)$ | $88.7$ $(0.3)$ |  |
| sLA | $89.3$ $(0.4)$ | $77.3$ $(0.5)$ | $89.7$ $(0.3)$ |  |
| CRM | $87.1$ $(0.7)$ | $78.7$ $(1.6)$ | $86.0$ $(0.6)$ |  |
| CelebA | ERM | $85.8$ $(0.3)$ | $39.0$ $(0.6)$ | $52.0$ $(1.0)$ |
| G-DRO | $89.2$ $(0.5)$ | $67.7$ $(1.3)$ | $91.0$ $(0.6)$ |  |
| LC | $91.1$ $(0.2)$ | $57.4$ $(0.6)$ | $90.0$ $(0.6)$ |  |
| sLA | $90.9$ $(0.1)$ | $57.4$ $(0.3)$ | $86.7$ $(1.9)$ |  |
| CRM | $91.1$ $(0.2)$ | $81.8$ $(1.2)$ | $89.0$ $(0.6)$ |  |
| MetaShift | ERM | $85.7$ $(0.4)$ | $60.5$ $(0.6)$ | $63.0$ $(0.0)$ |
| G-DRO | $86.0$ $(0.4)$ | $63.8$ $(0.6)$ | $80.7$ $(1.3)$ |  |
| LC | $88.5$ $(0.0)$ | $68.2$ $(0.5)$ | $80.0$ $(1.2)$ |  |
| sLA | $88.4$ $(0.1)$ | $63.0$ $(0.5)$ | $80.0$ $(1.2)$ |  |
| CRM | $87.6$ $(0.2)$ | $73.4$ $(0.7)$ | $74.7$ $(1.5)$ |  |
| MultiNLI | ERM | $69.1$ $(0.7)$ | $7.2$ $(0.6)$ | $68.0$ $(1.7)$ |
| G-DRO | $70.4$ $(0.1)$ | $34.3$ $(0.5)$ | $57.0$ $(2.3)$ |  |
| LC | $75.9$ $(0.1)$ | $54.3$ $(0.5)$ | $74.3$ $(1.2)$ |  |
| sLA | $76.4$ $(0.5)$ | $55.0$ $(1.8)$ | $71.7$ $(0.3)$ |  |
| CRM | $74.6$ $(0.5)$ | $57.7$ $(3.0)$ | $74.7$ $(1.3)$ |  |
| CivilComments | ERM | $80.4$ $(0.1)$ | $55.8$ $(0.4)$ | $61.0$ $(2.5)$ |
| G-DRO | $80.1$ $(0.2)$ | $61.6$ $(0.4)$ | $64.7$ $(1.5)$ |  |
| LC | $80.7$ $(0.1)$ | $65.7$ $(0.5)$ | $67.3$ $(0.3)$ |  |
| sLA | $80.6$ $(0.1)$ | $65.6$ $(0.1)$ | $66.3$ $(0.9)$ |  |
| CRM | $83.7$ $(0.1)$ | $68.1$ $(0.5)$ | $70.0$ $(0.6)$ |  |
| NICO++ | ERM | $85.0$ $(0.0)$ | $35.3$ $(2.3)$ | $35.3$ $(2.3)$ |
| G-DRO | $84.0$ $(0.0)$ | $36.7$ $(0.7)$ | $33.7$ $(1.2)$ |  |
| LC | $85.0$ $(0.0)$ | $35.3$ $(2.3)$ | $35.3$ $(2.3)$ |  |
| sLA | $85.0$ $(0.0)$ | $33.0$ $(0.0)$ | $35.3$ $(2.3)$ |  |
| CRM | $84.7$ $(0.3)$ | $40.3$ $(4.3)$ | $39.0$ $(3.2)$ |  |

**Table 2: Importance of bias extrapolation. We report Worst Group Accuracy, averaged as a group is dropped from training and validation (standard error based on 3 random seeds). CRM $(\hat{B})$ is an ablated version of CRM where we use the trained bias $\hat{B}$ instead of the extrapolated bias $B^{\star}$ mandated by our theory. The extrapolation step appears crucial for robust compositional generalization. Merely adjusting logits based on shifting group prior probabilities does not suffice.**
| Method | Waterbirds | CelebA | MetaShift | MulitNLI | CivilComments | NICO++ |
| --- | --- | --- | --- | --- | --- | --- |
| CRM ($\hat{B}$) | $55.7$ $(1.0)$ | $58.9$ $(0.4)$ | $58.7$ $(0.6)$ | $29.2$ $(2.1)$ | $51.9$ $(1.0)$ | $31.0$ $(1.0)$ |
| CRM | $78.7$ $(1.6)$ | $81.8$ $(1.2)$ | $73.4$ $0.7)$ | $57.7$ $(3.0)$ | $68.1$ $(0.5)$ | $40.3$ $(4.3)$ |

## Acknowledgements

We thank Yash Sharma for his contribution to early exploration of compositional generalization from a generative perspective, and Vinayak Tantia for having many years ago helped shed light on the challenges posed by compositionality in discriminative training.
This research was entirely funded by Meta, in the context of Meta’s AI Mentorship program with Mila.
Ioannis Mitliagkas in his role as Divyat Mahajan’s academic advisor, acknowledges support by an NSERC Discovery grant (RGPIN-2019-06512), and a Canada CIFAR AI chair. Pascal Vincent is a CIFAR Associate Fellow in the Learning in Machines & Brains program. Divyat Mahajan acknowledges support via FRQNT doctoral training scholarship for his graduate studies.

## 8 Further Discussion on Related Works

In this section, we provide a more detailed discussion on the related works.

#### Compositional Generalization

Compositionality has long been seen as an important capability on the path to building (Fodor and Pylyshyn, ; Hinton, ; Plate et al., ; Montague, ) human-level intelligence.
The history of compositionality is very long to cover in detail here, refer to these surveys (Lin et al., ; Sinha et al., ) for more detail. Compositionality is associated with many different aspects, namely systematicity, productivity, substitutivity, localism, and overgeneralization (Hupkes et al., ). In this work, we are primarily concerned with systematicity, which evaluates a model’s capability to understand known parts or rules and combine them in new contexts. Over the years, several popular benchmarks have been proposed to evaluate this systematicity aspect of compositionality, Lake and Baroni () proposed the SCAN dataset, Kim and Linzen () proposed the COGS dataset. These works led to development of several insightful approaches to tackle the challenge of compositionality (Lake and Baroni, ; Gordon et al., ). Most of these works on systematicity have largely focused on generative tasks,  (Liu et al., ; Lake and Baroni, ; Gordon et al., ; Wang et al., ), i.e., where the model needs to recombine individual distinct factors/concepts and generate the final output in the form of image or text. There has been lesser work on discriminative tasks (Nikolaus et al., ), i.e., where the model is given an input composed of a novel combination of factors and it has to predict the underlying novel combination. In this work, our focus is to build an approach that can provably solve these discriminative tasks.

On the theoretical side, recently, there has been a growing interest to build provable approaches for compositional generalization (Wiedemer et al., , ; Brady et al., ; Dong and Ma, ; Lachapelle et al., ). These works study models where the labeling function or the decoder is additive over individual features, and prove generalization guarantees over the Cartesian product of the support of individual features. The ability of a model to generalize to Cartesian products of the individual features is an important form of compositionality, which checks the model’s capability to correctly predict in novel circumstances described as combination of contexts seen before. Dong and Ma () developed results for additive models, i.e., labeling function is additive over individual features. While in Wiedemer et al. (), the authors considered a more general model class in comparison to Dong and Ma (). The labeling function/decoder in (Wiedemer et al., ) takes the form $f(x_{1},\cdots,x_{n})=C(\psi_{1}(x_{1}),\cdots,\psi_{n}(x_{n}))$. However, they require a strong assumption, where the learner needs to know the function $C$ that is used to generate the data. Lachapelle et al. (); Brady et al. () extended the results from Dong and Ma () to the unsupervised setting. Lachapelle et al. (); Brady et al. () are inspired by the success of object-centric models and show additive decoders enable generative models (autoencoders) to achieve Cartesian product extrapolation. While these works take promising and insightful first steps for provable compositional guarantees, the assumption of additive deterministic decoders (labeling functions) may come as quite restrictive. In particular a given attribute combination can then only correspond to a *unique* observation, produced by a very limited interaction between generative factors, not to a rich distribution of observations. By contrast an additive energy model can associate an almost arbitrary distribution over observations to a given set of attributes. Hence, we take inspiration independent mechanisms principle (Janzing and Schölkopf, ; Parascandolo et al., ) for our setting based on additive energy models. In the spirit of this principle, we think of each factor impacting the final distribution through an independent function, where independence is in the algorithmic sense and not the statistical sense.
Based on this more realistic assumption of additive energy, our goal is to develop an approach that provably enables *zero-shot compositional generalization in discriminative tasks*, where the model needs to robustly predict never seen before factor combinations that the input is composed of. These additive energy distributions have also been used in generative compositionality (Liu et al., ) but not in discriminative compositionality.

Finally, in another line of work (Schug et al., ), the authors consider compositionality in the task space and develop an approach that achieves provable compositional guarantees over this task space and empirically outperforms meta-learning approaches such as MAML and ANIL. Specifically, they operate in a student-teacher framework, where each task has a latent code that specifies the weights for different modules that are active for that task.

#### Domain Generalization

Generalization under subpopulation shifts, where certain groups or combinations of attributes are underrepresented in the training data, is a well-known challenge in machine learning. Group Distributionally Robust Optimization (GroupDRO) (Sagawa et al., ) is a prominent method that minimizes the worst-case group loss to improve robustness across groups. Invariant Risk Minimization (IRM) Arjovsky et al. () encourages the model to learn invariant representations that perform well across multiple environments. Perhaps the simplest methods are SUBG and RWG Idrissi et al. (), which focus on constructing a balanced subset or reweighting examples to minimize or eliminate spurious correlations. There are many other interesting approaches that were proposed, see the survey for details Zhou et al. ().
The theoretical guarantees developed for these approaches (Rosenfeld et al., ; Arjovsky et al., ; Ahuja et al., ) require a large diversity in terms of the environments seen at the training time. In our setting, we incorporate inductive biases based on additive energy distributions that help us arrive at provable generalization with limited diversity in the environments.

Closely related to our proposed method are the logit adjustment methods Kang et al. (); Menon et al. (); Ren et al. () used in robust classification.
Kang et al. () introduced Label-Distribution-Aware Margin (LDAM) loss for long-tail learning, proposing a method that adjusts the logits of a classifier based on the class frequencies in the training set to counteract bias towards majority classes.
Similarly, Menon et al. () and Ren et al. () (Balanced Softmax), modify the standard softmax cross-entropy loss to account for class imbalance by shifting the logits according to the prior distribution over the classes.
Closest to our work are the Logit Correction (LC) (Liu et al., ) and Supervised Logit Adjustment (sLA) (Tsirigotis et al., ) methods that use logit adjustment for group robustness.
LC adjusts logits based on the joint distribution of environment and class label, reducing reliance on spurious features in imbalanced training sets. When environment annotations are unknown, a second network infers them.
Supervised Logit Adjustment (sLA) adjusts logits according to the conditional distribution of classes given the environment. In the absence of environment annotations, Unsupervised Logit Adjustment (uLA) uses self-supervised learning (SSL) to pre-train a model for general feature representations, then derives a biased network from this pre-trained model to infer the missing environment annotations.

## 9 Proofs

#### Remark on proofs

We want to emphasize that the proofs developed here are quite different from related works on compositionality (Dong and Ma, ; Wiedemer et al., ). The foundation of proofs is built on a new mathematical object, discrete affine hull. The proof of Theorem 2 cleverly exploits properties of softmax and discrete affine hulls to show how we can learn the correct distribution without involving the intractable partition function in learning. The proof of Theorem 3, uses fundamental ideas from randomized algorithms to arrive at the probabilistic extrapolation guarantees.

We start with a basic lemma.

###### Lemma 1 .

If $z^{\prime}\in\mathsf{DAff}(\mathcal{Z}^{\mathsf{train}})$, i.e., $\sigma(z^{\prime})=\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\sigma(z)$, where $\braket{1,\alpha_{z}}=1$, then $\braket{\sigma(z^{\prime}),E(x)}=\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha
_{z}\braket{\sigma(z),E(x)}$.

###### Proof.

$\braket{\sigma(z^{\prime}),E(x)}=\braket{\sum_{z\in\mathcal{Z}^{\mathsf{train}
}}\alpha_{z}\sigma(z),E(x)}=\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}
\braket{\sigma(z),E(x)}.$

∎

###### Lemma 1 .

###### Proof.

### 9.1 Proof for Theorem 1 : Extrapolation of Conditional Density

See 1

###### Proof.

We start by expanding the expressions for true and estimated log densities below

$$ $\begin{split}-\log\Big{[}p(x|z)\Big{]}=\braket{\sigma(z),\mathbb{E}(x)}+\log( \mathbb{Z}(z)),\\ -\log\Big{[}\hat{p}(x|z)\Big{]}=\braket{\sigma(z),\hat{E}(x)}+\log(\hat{ \mathbb{Z}}(z)).\end{split}$ (11) $$

We equate these densities for the training attributes $z\in\mathcal{Z}^{\mathsf{train}}$. For a fixed $z\in\mathcal{Z}^{\mathsf{train}}$, we obtain that for all $x\in\mathbb{R}^{n}$

$$ $\braket{\sigma(z),\hat{E}(x)}=\braket{\sigma(z),E(x)}+C(z),$ (12) $$

where $C(z)=\log\big{(}\mathbb{Z}(z)/\hat{\mathbb{Z}}(z)\big{)}$. Since $z^{\prime}\in\mathsf{DAff}(\mathcal{Z}^{\mathsf{train}})$, we can write $z^{\prime}=\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}z$, $\braket{1,\alpha_{z}}=1$. From Lemma 1, we know that $\braket{\sigma(z^{\prime}),E(x)}=\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha
_{z}\braket{\sigma(z),\hat{E}(x)}$.

We use this decomposition and equation 12 to arrive at the key identity below. For all $x\in\mathbb{R}^{n}$

$$ $\begin{split}\braket{\sigma(z^{\prime}),\hat{E}(x)}&=\sum_{z\in\mathcal{Z}^{ \mathsf{train}}}\alpha_{z}\braket{\sigma(z),\hat{E}(x)}\\ &=\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}(\braket{\sigma(z),E(x)}+C( z))\\ &=\Big{(}\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}(\braket{\sigma(z),E (x)}\Big{)}+\Big{(}\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}C(z)\Big{) }\\ &=\braket{\sigma(z^{\prime}),E(x)}+\sum_{z\in\mathcal{Z}^{\mathsf{train}}} \alpha_{z}C(z)\\ \end{split}$ (13) $$

From this we can infer that

$$ $\begin{split}\hat{p}(x|z^{\prime})&=\frac{1}{\hat{\mathbb{Z}}(z^{\prime})}\exp \Big{(}-\braket{\sigma(z^{\prime}),\hat{E}(x)}\Big{)}\\ &=\frac{1}{\hat{\mathbb{Z}}(z^{\prime})}\exp\Big{(}-\braket{\sigma(z^{\prime}) ,E(x)}-\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}C(z)\Big{)}\end{split}$ (14) $$

We now use the fact that density integrates to one for continuous random variables (or alternatively the probability sums to one for discrete random variables).
Thus

$$ $\displaystyle\int\hat{p}(x|z^{\prime})dx$ $\displaystyle=1$ $\displaystyle\int\frac{1}{\hat{\mathbb{Z}}(z^{\prime})}\exp\Big{(}-\braket{ \sigma(z^{\prime}),E(x)}-\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}C(z) \Big{)}dx$ $\displaystyle=1$ $\displaystyle\frac{1}{\hat{\mathbb{Z}}(z^{\prime})}\exp\Big{(}-\sum_{z\in \mathcal{Z}^{\mathsf{train}}}\alpha_{z}C(z)\Big{)}\int\exp\Big{(}-\braket{ \sigma(z^{\prime}),E(x)}\Big{)}dx$ $\displaystyle=1$ $\displaystyle\frac{1}{\hat{\mathbb{Z}}(z^{\prime})}\exp\Big{(}-\sum_{z\in \mathcal{Z}^{\mathsf{train}}}\alpha_{z}C(z)\Big{)}\mathbb{Z}(z^{\prime})$ $\displaystyle=1$ $\displaystyle\frac{1}{\hat{\mathbb{Z}}(z^{\prime})}\exp\Big{(}-\sum_{z\in \mathcal{Z}^{\mathsf{train}}}\alpha_{z}C(z)\Big{)}$ $\displaystyle=\frac{1}{\mathbb{Z}(z^{\prime})}$ (15) $$

We substitute equation 15 into equation 14 to obtain

$$ $\hat{p}(x|z^{\prime})=\frac{1}{\mathbb{Z}(z^{\prime})}\exp\Big{(}-\braket{ \sigma(z^{\prime}),E(x)}\Big{)}=p(x|z^{\prime}),\forall x\in\mathbb{R}^{n}$ (16) $$

∎

###### Proof.

### 9.2 Proof for Theorem 2 : Extrapolation of CRM

See 2

###### Proof.

Since $q$ follows compositional shifts,

$$ $\log q(x|z)=\log p(x|z)=-\braket{\sigma(z),E(x)}-\log\mathbb{Z}(z)$ (17) $$

We can write it as $-\braket{\sigma(z),E(x)}=\log p(x|z)+\log\mathbb{Z}(z)$.

Consider $z^{\prime}\in\mathsf{DAff}(\mathcal{Z}^{\mathsf{train}})$. We can express $z^{\prime}$ as $\sigma(z^{\prime})=\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\sigma(z)$, where $\braket{1,\alpha_{z}}=1$.

We use equation 17 and show that the partition function at $z^{\prime}$ can be expressed as affine combination of partition of the individual points and a correction term. We obtain the following condition. $\forall z^{\prime}\in\mathcal{Z}^{\mathsf{test}}$, where recall $\mathcal{Z}^{\mathsf{test}}\subseteq\mathsf{DAff}(\mathcal{Z}^{\mathsf{train}})$,

$$ $\begin{split}\log\big{(}\mathbb{Z}(z^{\prime})\big{)}&=\log\Big{(}\mathbb{E}_{ x}\Big{[}\exp\big{(}-\braket{\sigma(z^{\prime}),E(x)}\big{)}\Big{]}\Big{)},\\ &=\log\Big{(}\mathbb{E}_{x}\Big{[}\exp\Big{(}-\sum_{z\in\mathcal{Z}^{\mathsf{ train}}}\alpha_{z}\braket{\sigma(z),E(x)}\Big{)}\Big{]}\Big{)},\\ &=\log\Big{(}\mathbb{E}_{x}\Big{[}\exp\Big{(}\sum_{z\in\mathcal{Z}^{\mathsf{ train}}}\alpha_{z}\big{(}\log p(x|z)+\log\mathbb{Z}(z)\big{)}\Big{)}\Big{]} \Big{)}\\ &=\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\log\mathbb{Z}(z)+\log\Bigg {(}\mathbb{E}_{x}\Big{[}\exp\Big{(}\sum_{z\in\mathcal{Z}^{\mathsf{train}}} \alpha_{z}\log p(x|z)\Big{)}\Big{]}\Bigg{)},\\ \end{split}$ (18) $$

where $\mathbb{E}_{x}[f]=\int_{\tilde{x}\in\mathbb{R}^{n}}f(\tilde{x})d\tilde{x}$.

Denote the latter term in the above expression as

$$ $R(\{\alpha_{z}\}_{z\in\mathcal{Z}^{\mathsf{train}}})=\log\Big{(}\mathbb{E}_{x} \Big{[}\exp\Big{(}\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\log p(x|z) \Big{)}\Big{]}\Big{)}$ (19) $$

We now simplify $\log\big{(}q(x|z^{\prime})\big{)}$ using the property of partition function from equation 18 below. $\forall z^{\prime}\in\mathcal{Z}^{\mathsf{test}},$

$$ $\begin{split}&\log\big{(}q(x|z^{\prime})\big{)}=-\braket{\sigma(z^{\prime}),E( x)}-\log\mathbb{Z}(z^{\prime})\\ &=\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\Big{(}\log p(x|z)+\log \mathbb{Z}(z)\Big{)}-\log\mathbb{Z}(z^{\prime})\\ &=\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\log p(x|z)+\sum_{z\in \mathcal{Z}^{\mathsf{train}}}\alpha_{z}\log\mathbb{Z}(z)-\sum_{z\in\mathcal{Z} ^{\mathsf{train}}}\alpha_{z}\log\mathbb{Z}(z)-R\big{(}\{\alpha_{z}\}_{z\in \mathcal{Z}^{\mathsf{train}}}\big{)}\\ &=\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\log p(x|z)-R\big{(}\{ \alpha_{z}\}_{z\in\mathcal{Z}^{\mathsf{train}}}\big{)}\end{split}$ (20) $$

We now simplify the first term in the above expression, i.e., $\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\log p(x|z)$, in terms of $p(z|x)$.

$$ $\begin{split}\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\big{(}\log\big{ (}p(x|z)\big{)}&=\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\log\Bigg{(} \frac{p(z|x)p(x)}{p(z)}\Bigg{)}\\ &=\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\Big{(}\log p(z|x)-\log p(z )\Big{)}+\log p(x)\end{split}$ (21) $$

Similarly, $R(\{\alpha_{z}\}_{z\in\mathcal{Z}^{\mathsf{train}}})$ can be phrased in terms of $p(z|x)$ as follows.

$$ $\begin{split}R\big{(}\{\alpha_{z}\}_{z\in\mathcal{Z}^{\mathsf{train}}}\big{)}& =\log\Big{(}\mathbb{E}_{x}\Big{[}\exp\Big{(}\sum_{z\in\mathcal{Z}^{\mathsf{ train}}}\alpha_{z}\log p(x|z)\Big{)}\Big{]}\Big{)}\\ &=-\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\log p(z)+\log\Big{(} \mathbb{E}_{x\sim p(x)}\Big{[}\exp\Big{(}\sum_{z\in\mathcal{Z}^{\mathsf{train} }}\alpha_{z}\log p(z|x)\Big{)}\Big{]}\Big{)}\\ &=-\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\log p(z)+S\big{(}\{\alpha _{z}\}_{z\in\mathcal{Z}^{\mathsf{train}}}\big{)},\end{split}$ (22) $$

where $S\big{(}\{\alpha_{z}\}_{z\in\mathcal{Z}^{\mathsf{train}}}\big{)}=\log\Big{(}
\mathbb{E}_{x\sim p(x)}\Big{[}\exp\Big{(}\sum_{z\in\mathcal{Z}^{\mathsf{train}
}}\alpha_{z}\log p(z|x)\Big{)}\Big{]}\Big{)}$ and $\mathbb{E}_{x\sim p(x)}$ is the expectation w.r.t distribution $p(x)$.
We use equation 21, equation 22 to simplify equation 20 as follows.$\forall z^{\prime}\in\mathcal{Z}^{\mathsf{test}},$

$$ $\begin{split}&\log q(x|z^{\prime})=\sum_{z\in\mathcal{Z}^{\mathsf{train}}} \alpha_{z}\log p(z|x)-S\big{(}\{\alpha_{z}\}_{z\in\mathcal{Z}^{\mathsf{train}} }\big{)}+\log p(x)\\ &\log\Big{(}\frac{q(z^{\prime}|x)q(x)}{q(z^{\prime})}\Big{)}=\sum_{z\in \mathcal{Z}^{\mathsf{train}}}\alpha_{z}\log p(z|x)-S\big{(}\{\alpha_{z}\}_{z \in\mathcal{Z}^{\mathsf{train}}}\big{)}+\log p(x)\\ &\log\big{(}q(z^{\prime}|x)\big{)}=\sum_{z\in\mathcal{Z}^{\mathsf{train}}} \alpha_{z}\Big{(}q(z^{\prime})+\log p(z|x)\Big{)}-S\big{(}\{\alpha_{z}\}_{z\in \mathcal{Z}^{\mathsf{train}}}\big{)}+\log\Big{(}\frac{p(x)}{q(x)}\Big{)}\\ \end{split}$ (23) $$

We use translation invariance of softmax to obtain

$$ $\begin{split}&q(z^{\prime}|x)=\mathsf{Softmax}\Big{(}\log q(z^{\prime})+\sum_{ z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\log p(z|x)-S\big{(}\{\alpha_{z}\}_ {z\in\mathcal{Z}^{\mathsf{train}}}\big{)}\Big{)}\\ &q(z^{\prime}|x)=\mathsf{Softmax}\Big{(}\log q(z^{\prime})+\sum_{z\in\mathcal{ Z}^{\mathsf{train}}}\alpha_{z}\log p(z|x)-\log\Big{(}\mathbb{E}_{x\sim p(x)} \Big{[}\exp\Big{(}\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\log p(z|x) \Big{)}\Big{]}\Big{)}\Big{)}\end{split}$ (24) $$

To avoid cumbersome notation, we took the liberty to show only one input to softmax, other inputs bear the same parametrization, they are computed at other $z$’s. From the above equation it is clear that if the learner knows the marginal distribution over the groups at test time, i.e., $q(z)$ and estimates $p(z|x)$ for all $z$’s in the training distribution’s support, i.e., $\mathcal{Z}^{\mathsf{train}}$, then the learner can successfully extrapolate to $q(z^{\prime}|x)$.

Let us now use the *additive energy classifier*
of the form we defined in equation 6 and whose energy $\hat{E}$ and bias $\hat{B}$ we optimized (equation 8) to match $p(z|x)$, so that:

$$ ${p}(z|x)=\frac{\exp\bigg{(}-\braket{\sigma(z),\hat{E}(x)}+\log\hat{p}(z)-\hat{ B}(z)\bigg{)}}{\sum_{\tilde{z}\in\mathcal{Z}^{\mathsf{train}}}\exp\bigg{(}- \braket{\sigma(\tilde{z}),\hat{E}(x)}+\log\hat{p}(\tilde{z})-\hat{B}(\tilde{z} )\bigg{)}},$ $$

Consequently

$$ $\begin{split}&\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\log p(z|x)\\ &=\left(\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\Big{(}-\braket{ \sigma(z),\hat{E}(x)}+\log p(z)-\hat{B}(z)\Big{)}\right)-\log\Big{(}\sum_{ \tilde{z}\in\mathcal{Z}^{\mathsf{train}}}\exp\Big{(}-\braket{\sigma(\tilde{z}) ,\hat{E}(x)}+\log p(\tilde{z})-\hat{B}(\tilde{z})\Big{)}\Big{)}\end{split}$ (25) $$

where we used the property that $\braket{1,\alpha_{z}}=1$.

Let us use this to simplify the last term of equation 24:

$$ $\begin{split}&\log\left(\mathbb{E}_{x\sim p(x)}\Big{[}\exp\Big{(}\sum_{z\in \mathcal{Z}^{\mathsf{train}}}\alpha_{z}\log p(z|x)\Big{)}\Big{]}\right)\\ &=\log\left(\mathbb{E}_{x\sim p(x)}\Bigg{[}\frac{\exp\Big{(}\sum_{z\in\mathcal {Z}^{\mathsf{train}}}\alpha_{z}\Big{(}-\braket{\sigma(z),\hat{E}(x)}+\log p(z) -\hat{B}(z)\Big{)}\Big{)}}{\Big{(}\sum_{\tilde{z}\in\mathcal{Z}^{\mathsf{train }}}\exp\Big{(}-\braket{\sigma(\tilde{z}),\hat{E}(x)}+\log p(\tilde{z})-\hat{B} (\tilde{z})\Big{)}}\Bigg{]}\right)\\ &=\log\left(\mathbb{E}_{x\sim p(x)}\Bigg{[}\frac{\exp\Big{(}\sum_{z\in\mathcal {Z}^{\mathsf{train}}}\alpha_{z}\Big{(}-\braket{\sigma(z),\hat{E}(x)}\Big{)}}{ \Big{(}\sum_{\tilde{z}\in\mathcal{Z}^{\mathsf{train}}}\exp\Big{(}-\braket{ \sigma(\tilde{z}),\hat{E}(x)}+\log p(\tilde{z})-\hat{B}(\tilde{z})\Big{)}} \Bigg{]}\exp\Big{(}\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\Big{(} \log p(z)-\hat{B}(z)\Big{)}\Big{)}\right)\\ &=\log\left(\mathbb{E}_{x\sim p(x)}\Bigg{[}\frac{\exp\Big{(}\sum_{z\in\mathcal {Z}^{\mathsf{train}}}\alpha_{z}\Big{(}-\braket{\sigma(z),\hat{E}(x)}\Big{)}}{ \Big{(}\sum_{\tilde{z}\in\mathcal{Z}^{\mathsf{train}}}\exp\Big{(}-\braket{ \sigma(\tilde{z}),\hat{E}(x)}+\log p(\tilde{z})-\hat{B}(\tilde{z})\Big{)}} \Bigg{]}\right)+\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\Big{(}\log p (z)-\hat{B}(z)\Big{)}\\ &=\log\left(\mathbb{E}_{x\sim p(x)}\Bigg{[}\frac{\exp\Big{(}-\braket{\sigma(z^ {\prime}),\hat{E}(x)}\Big{)}}{\Big{(}\sum_{\tilde{z}\in\mathcal{Z}^{\mathsf{ train}}}\exp\Big{(}-\braket{\sigma(\tilde{z}),\hat{E}(x)}+\log p(\tilde{z})- \hat{B}(\tilde{z})\Big{)}}\Bigg{]}\right)+\sum_{z\in\mathcal{Z}^{\mathsf{train }}}\alpha_{z}\Big{(}\log p(z)-\hat{B}(z)\Big{)}\\ &=B^{\star}(z^{\prime})+\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\Big{ (}\log p(z)-\hat{B}(z)\Big{)}\end{split}$ (26) $$

where we used Lemma 1, and $B^{\star}$ is as defined in equation 10.

Let us also define
$c(x)=\log\Big{(}\sum_{\tilde{z}\in\mathcal{Z}^{\mathsf{train}}}\exp\Big{(}-
\braket{\sigma(\tilde{z}),\hat{E}(x)}+\log p(\tilde{z})-\hat{B}(\tilde{z})\Big
{)}\Big{)}$ so that we can
reexpress equation 25 as:

$$ $\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\log p(z|x)\\ =\left(\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\Big{(}-\braket{\sigma (z),\hat{E}(x)}+\log p(z)-\hat{B}(z)\Big{)}\right)-c(x)$ (27) $$

Subtracting equation 26 from equation 27 we get:

$$ $\displaystyle\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\log p(z|x)-\log \left(\mathbb{E}_{x\sim p(x)}\Big{[}\exp\Big{(}\sum_{z\in\mathcal{Z}^{\mathsf{ train}}}\alpha_{z}\log p(z|x)\Big{)}\Big{]}\right)$ $\displaystyle=$ $\displaystyle\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\Big{(}-\braket{ \sigma(z),\hat{E}(x)}+\log p(z)-\hat{B}(z)\Big{)}-c(x)$ $\displaystyle-B^{\star}(z^{\prime})-\sum_{z\in\mathcal{Z}^{\mathsf{train}}} \alpha_{z}\Big{(}\log p(z)-\hat{B}(z)\Big{)}$ $\displaystyle=$ $\displaystyle\sum_{z\in\mathcal{Z}^{\mathsf{train}}}\alpha_{z}\Big{(}-\braket{ \sigma(z),\hat{E}(x)}\Big{)}-c(x)-B^{\star}(z^{\prime})$ $\displaystyle=$ $\displaystyle-\braket{\sigma(z^{\prime}),\hat{E}(x)}-c(x)-B^{\star}(z^{\prime})$ (28) $$

Substituting this inside equation 24 yields

$$ $\begin{split}q(z^{\prime}|x)&=\mathsf{Softmax}\Big{(}\log q(z^{\prime})- \braket{\sigma(z^{\prime}),\hat{E}(x)}-c(x)-B^{\star}(z^{\prime})\Big{)}\\ &=\mathsf{Softmax}\Big{(}-\braket{\sigma(z^{\prime}),\hat{E}(x)}+\log q(z^{ \prime})-B^{\star}(z^{\prime})\Big{)}\end{split}$ (29) $$

where we removed the $c(x)$ term as softmax is invariant to addition of terms that do not depend on $z^{\prime}$.

If $\hat{q}(z^{\prime})=q(z^{\prime}),\forall z^{\prime}\in\mathcal{Z}^{\mathsf{
test}}$, then the expression in RHS corresponds to $\hat{q}(z^{\prime}|x)$, as we had defined it in equation 9, before stating our theorem.
Thus $q(z^{\prime}|x)=\hat{q}(z^{\prime}|x)$. This completes the proof.

∎

###### Proof.

### 9.3 Proof for Theorem 3 : Extrapolation from a Small Set of Attribute Combinations to All Attribute Combinations

In order to prove Theorem 3 we first establish some basic lemmas. In the first lemma below, we consider a setting with two attributes, where each attribute takes two possible values, i.e., $m=2$ and $d=2$. In this setting there are four possible one-hot vectors $z^{1},z^{2},z^{3},z^{4}$. We first show that each $z^{i}$ can be expressed as an affine combination of the remaining three.

###### Lemma 2 .

If $m=2,d=2$, then there are four possible concatenated one-hot vectors $z$ denoted $z^{1},z^{2},z^{3},z^{4}$. Each $z^{i}$ can be expressed as an affine combination of the remaining.

###### Proof.

Below we explicitly show how each $z^{i}$ can be expressed in terms of other $z^{j}$’s.

$$ $(+1)\cdot\begin{bmatrix}0\\ 1\\ 0\\ 1\end{bmatrix}\;\;+\;\;(-1)\cdot\begin{bmatrix}0\\ 1\\ 1\\ 0\end{bmatrix}\;\;+\;\;(+1)\cdot\begin{bmatrix}1\\ 0\\ 1\\ 0\end{bmatrix}=\begin{bmatrix}1\\ 0\\ 0\\ 1\end{bmatrix}$ (30) $$

$$ $(-1)\cdot\begin{bmatrix}0\\ 1\\ 0\\ 1\end{bmatrix}\;\;+\;\;(+1)\cdot\begin{bmatrix}0\\ 1\\ 1\\ 0\end{bmatrix}\;\;+\;\;(+1)\cdot\begin{bmatrix}1\\ 0\\ 0\\ 1\end{bmatrix}=\begin{bmatrix}1\\ 0\\ 1\\ 0\end{bmatrix}$ (31) $$

$$ $(+1)\cdot\begin{bmatrix}1\\ 0\\ 1\\ 0\end{bmatrix}\;\;+\;\;(+1)\cdot\begin{bmatrix}0\\ 1\\ 0\\ 1\end{bmatrix}\;\;+\;\;(-1)\cdot\begin{bmatrix}1\\ 0\\ 0\\ 1\end{bmatrix}=\begin{bmatrix}0\\ 1\\ 1\\ 0\end{bmatrix}$ (32) $$

$$ $(-1)\cdot\begin{bmatrix}1\\ 0\\ 1\\ 0\end{bmatrix}\;\;+\;\;(+1)\cdot\begin{bmatrix}0\\ 1\\ 1\\ 0\end{bmatrix}\;\;+\;\;(+1)\cdot\begin{bmatrix}1\\ 0\\ 0\\ 1\end{bmatrix}=\begin{bmatrix}0\\ 1\\ 0\\ 1\end{bmatrix}$ (33) $$

∎

Figure: Figure 2: Setting of two attributes and two possible values per attribute. Illustration of extrapolation from three groups to the remaining fourth group. Three dark colored groups indicate the observed groups and the light colored shaded group indicates the group that is the affine combination of the three observed groups.
Refer to caption: x2.png

We illustrate the setting of Lemma 2 in Figure 2.
We now understand an implication of Lemma 2. Let us consider the setting where $m=2$ and $d>2$. Consider a subset of four groups $\{(i,j),(i^{\prime},j),(i,j^{\prime}),(i^{\prime},j^{\prime})\}$. Under one-hot concatenations these groups are denoted as $z^{1}=[\underbrace{0,\cdots,1_{i},\cdots 0}_{\text{first attribute}},
\underbrace{0,\cdots,1_{j},\cdots 0}_{\text{second attribute}}]$, $z^{2}=[0,\cdots,1_{i^{\prime}},\cdots 0,0,\cdots,1_{j},\cdots 0]$, $z^{3}=[0,\cdots,1_{i},\cdots 0,0,\cdots,1_{j^{\prime}},\cdots 0]$, and $z^{4}=[0,\cdots,1_{i^{\prime}},\cdots 0,0,\cdots,1_{j^{\prime}},\cdots 0]$. Observe that using Lemma 2, we get $z^{4}=z^{2}+z^{3}-z^{1}$. Similarly, we can express every other $z^{i}$ in terms of rest of $z^{j}$’s in the the set $\{(i,j),(i^{\prime},j),(i,j^{\prime}),(i^{\prime},j^{\prime})\}$.

In the setting when $m=2$ and $d\geq 2$, the total number of possible values $z$ takes is $d^{2}$. Each group recall is associated with attribute vector $z=[z_{1},z_{2}]$, where $z_{1}\in\{1,\cdots,d\}$ and $z_{2}\in\{1,\cdots d\}$. The set of all possible values of $z$ be visualized as $d\times d$ grid in this notation. We call this $d\times d$ grid as $G$. We will first describe a specific approach of selecting observed groups $z$ for training, which shows that with just $2d-1$ it is possible to affine span all the possible $d^{2}$ groups in the grid $G$. We leverage the insights from this approach and show that with a randomized approach of selecting groups, we can continue to affine span $d^{2}$ groups with $\mathcal{O}(d\log(d))$ groups.

Denote the set of observed groups as $N$. Suppose that their affine hull contains all the points in a subgrid $S\subseteq G$ of size $m\times n$.
Let the subgrid $S=\{x_{1},\cdots,x_{m}\}\times\{y_{1},\cdots,y_{n}\}$. Without loss of generality, we can permute the points and make the subgrid contiguous as follows $S=\{1,\cdots,m\}\times\{1,\cdots,n\}$. Next, we add a new point $g=(g_{x},g_{y})\in G$ but $g\not\in S$. We argue that if $g_{x}\in\{1,\cdots,m\}$, then the affine hull of $N\cup\{g\}$ contains a larger subgrid of size $m\times(n+1)$.
Similarly, we want to argue that if $g_{y}\in\{1,\cdots,n\}$, then the affine hull of $N\cup\{g\}$ contains a larger subgrid of size $(m+1)\times n$. Define $C_{x}$ as the Cartesian product of $\{g_{x}\}$ with $\{1,\cdots,n\}$, i.e., $C_{x}=\{(g_{x},1),(g_{x},2),\cdots,(g_{x},n)\}$. Define $C_{y}$ as the Cartesian product of $\{1,\cdots,m\}$ with $\{g_{y}\}$, i.e., $C_{y}=\{(1,g_{y}),(2,g_{y}),\cdots,(m,g_{y})\}$.

###### Theorem 4 .

Suppose the affine hull of the observed set $N$ contains a subgrid $S$ of size $m\times n$. If the new point $g=(g_{x},g_{y})$ shares the $x$-coordinate with a point in $S$, and $g\not\in S$, then the the affine hull of $N\cup\{g\}$ contains $S\cup C_{y}$.

###### Proof.

We write the set of observed groups $N$ as $N=\{z^{\theta_{j}}\}_{j}$. The affine hull of $N$ contains $S=\{1,\cdots,m\}\times\{1,\cdots,n\}$. We observe a new group $g\not\in S$, which shares its $x$ coordinate with one of the points in $S$. Without loss of generality let this point be $g=(1,n+1)$ (if this were not the case, then we can always permute the columns and rows to achieve such a configuration). Consider the triplet – $(z^{1},z^{2},z^{3})=\big{(}(1,n),(2,n),(1,n+1)\big{)}$. Observe that $z^{1},z^{2},z^{3},z^{4}$ form a $2\times 2$ subgrid, where $z^{4}=(2,n+1)$. We use Lemma 2 to infer that the fourth point $z^{4}=(2,n+1)$ on this $2\times 2$ subgrid can be obtained as an affine combination of this triplet, i.e., $z^{4}=\alpha z^{1}+\beta z^{2}+\gamma z^{3}$. Since $z^{1},z^{2}$ are in the affine hull of $N$, they can be written as an affine combination of seen points in $N$ as follows $z^{1}=\sum_{k\in N}a_{k}z^{\theta_{k}}$, $z^{2}=\sum_{k\in N}b_{k}z^{\theta_{k}}$. As a result, we obtain

$$ $\begin{split}&z^{4}=\alpha z^{1}+\beta z^{2}+\gamma z^{3}=\alpha\Big{(}\sum a_ {k}z^{\theta_{k}}\Big{)}+\beta\Big{(}\sum b_{k}z^{\theta_{k}}\Big{)}+\gamma z^ {3}\\ &=\sum_{k\in N}\Big{(}\alpha a_{k}+\beta b_{k}\Big{)}z^{\theta_{k}}+\gamma z^{ 3}\end{split}$ (34) $$

Observe that $\sum_{k}(\alpha a_{k}+\beta b_{k})=(\alpha\sum_{k}a_{k}+\beta\sum_{k}b_{k})=
\alpha+\beta$. Since $\alpha+\beta+\gamma=1$, $z^{4}$ is an affine combination of points in $N\cup\{g\}$. Thus we have shown the claim for the point $(2,n+1)$. We can repeat this claim for point $(3,n+1)$ and so on until we reach $(m,n+1)$ beyond which there would be no points in $S$ that are expressed as affine combination of $N$. We can make this argument formal through induction. We have already shown the base case above. Suppose all the points $(j,n+1)$ in $j\leq i<m$ are in the affine hull of $N\cup\{g\}$. Consider the point $z^{4}=(i+1,n+1)$. Construct the triplet $(z^{1},z^{2},z^{3})=\big{(}(i,n),(i,n+1),(i+1,n)\big{)}$. Again from Lemma 2, it follows that $z^{4}=\alpha z^{1}+\beta z^{2}+\gamma z^{3}$. We substitute $z^{1},z^{2}$ and $z^{3}$ with their corresponding affine combinations. $z^{4}=\alpha\sum_{k\in N\cup\{g\}}a_{k}z^{\theta_{k}}+\beta\sum_{k\in N\cup\{g
\}}b_{k}z^{\theta_{k}}+\gamma\sum_{k\in N\cup\{g\}}c_{k}z^{\theta_{k}}$. Since $\sum_{k\in N\cup\{g\}}\alpha a_{k}+\beta b_{k}+\gamma c_{k}=1$, it follows that $z^{4}$ is an affine combination of $z^{1},z^{2}$ and $z^{3}$. This completes the proof.

∎

We now describe a simple deterministic procedure that helps us understand how many groups we need to see before we are guaranteed that the affine hull of seen points span the whole grid $G=\{1,\cdots,d\}\times\{1,\cdots,d\}$.

- •
We start with a base set of three points – $B=\{(1,1),(1,2),(2,1)\}$. From Lemma 2, the affine hull contains $(2,2)$.
- •
For each $i\in\{2,\cdots,d-1\}$ add the points $(1,i+1),(i+1,1)$ to the set $B$. From Theorem 4, it follows that affine hull of $B\cup\{(1,i+1)\}\cup\{(i+1,1)\}$ contains $(i+1\times i+1)$ subgrid $\{1,\cdots,i+1\}\times\{1,\cdots,i+1\}$ (here we apply Theorem 4 in two steps once for the addition of $(1,i+1)$ and then for the addition of $(i+1,1)$.

At the end of the above procedure $B$ contains $2d-1$ points and its affine hull contains the grid $G$. We illustrate this procedure in Figure 3.

Figure: (a) Step 1

We now discuss a randomized procedure that also allows us to span the entire grid $G$ with $\mathcal{O}(d\log(d))$ groups. The idea of the procedure is to start with a base set of groups and construct their affine hull $S$. Then we wait to sample a group $g$ that is outside this affine hull. If this sampled group shares the $x$ coordinate with affine hull of $B$ denoted as $S$, then we expand the subgrid by one along with $y$ coordinate. Similarly, we also wait for a point that shares a $y$ coordinate and then we expand the subgrid by one along the $x$ coordinate.

We use $S_{x}$ to denote the distinct set of $x$-coordinates that appear in $S$ and same goes for $S_{y}$. We write $g=(g_{x},g_{y})$. The procedure goes as follows.

Set $S=\emptyset,B=\emptyset$ and $\mathsf{Flag}=x$.

- •
Sample a group $g$ from $G$ uniform at random. Update $B=B\cup\{g\},S=S\cup\{g\}$.
- •
While $S\not=G$, sample a group $g$ from $G$ uniform at random.
–
If $\mathsf{Flag}==x$, $g_{x}\in S_{x}$, $g\not\in S$, then update $B=B\cup\{g\}$, $S=S\cup(S_{x}\times\{g_{y}\})$ and $\mathsf{Flag}=y$.
–
If $\mathsf{Flag}==y$, $g_{y}\in S_{y}$, $g\not\in S$, then update $B=B\cup\{g\}$, $S=S\cup(\{g_{x}\}\times S_{y})$ and $\mathsf{Flag}=x$.

In the above procedure, in every step in the while loop a group $g$ is sampled. Whenever the $\mathsf{Flag}$ flips from $x$ to $y$, then following Theorem 4, the updated set $S$ belongs to the affine hull of $B$. We can say the same when $\mathsf{Flag}$ flips from $y$ to $x$.
In the next theorem, we will show that the while loop terminates after $8cd\log(d)$ steps with a high probability and the affine hull of $B$ contains the entire grid $G$. We follow this strategy. We count the time it takes for $\mathsf{Flag}$ to flip from $x$ to $y$ (from $y$ to $x$) as it grows the size of $S$ from a $k\times k$ subgrid to $k\times(k+1)$ ($k\times(k+1)$ subgrid to $(k+1)\times(k+1)$) subgrid.

###### Theorem 5 .

Suppose we sample the groups based on the randomized procedure described above. If the number of sampled groups is greater than $8cd\log(d)$, then $G\subseteq\mathsf{DAff}(B)$ with a probability greater than equal to $1-\frac{1}{c}$.

###### Proof.

We take the first group $g$ that is sampled. Without loss of generality, we say this group is $(1,1)$.

Suppose the $\mathsf{Flag}$ is set to $x$. Define an event $A_{1}^{k}$: newly sampled $g=(g_{x},g_{y})$ shares $x$-coordinate with a point in $S$ (size $k\times k$), $g\not\in S$. Under these conditions $\mathsf{Flag}$ flips from $x$ to $y$. To compute the probability of this event let us count the number of scenarios in which this happens. If $g_{x}$ takes one of the $k$ values in $S_{x}$ and $g_{y}$ takes one of the remaining $(d-k)$, then the event happens. As a result, the probability of this event is $P(A_{1}^{k})=\frac{(k)(d-k)}{d^{2}}$.

Suppose the $\mathsf{Flag}$ is set to $y$. Define an event $A_{2}^{k}$: newly sampled $g=(g_{x},g_{y})$ shares $y$-coordinate with a point in $S$ (size $k\times(k+1)$) and $g\not\in S$. Under these conditions $\mathsf{Flag}$ flips from $y$ to $x$. The probability of this event is$P(A_{2}^{k})=\frac{(k+1)(d-k)}{d^{2}}$.

Define $T_{1}^{k}$ as the number of groups that need to be sampled before $A_{1}^{k}$ occurs. Define $T_{2}^{k}$ as the number of groups that need to be sampled before $A_{2}^{k}$ occurs.
Observe that after $T_{1}^{k}+T_{2}^{k}$ number of sampled groups the size of the current subgrid $S$, which is in the affine hull of $B$, grows to $(k+1)\times(k+1)$.

Define $T_{\mathsf{sum}}=\sum_{k=1}^{d-1}(T_{1}^{k}+T_{2}^{k})$. $T_{\mathsf{sum}}$ is the total number of groups sampled before the affine span of the observed groups $B$ contains the grid $G$.

We compute

$$ $\begin{split}&\mathbb{E}[T_{\mathsf{sum}}]=\sum_{k=1}^{d-1}(\mathbb{E}[T_{1}^{ k}]+\mathbb{E}[T_{2}^{k}])\\ &\sum_{k=1}^{d}\mathbb{E}[T_{1}^{k}]=\sum_{k=1}^{d-1}d^{2}/(k(d-k))=2\sum_{k=1 }^{(d-1)/2}d^{2}/(k(d-k))\\ &2\sum_{k=1}^{(d-1)/2}d^{2}/(k(d-k))=2d\sum_{k=1}^{(d-1)/2}\Big{[}\frac{1}{k}+ \frac{1}{d-k}\Big{]}\approx 4d\log((d-1)/2)\end{split}$ (35) $$

Similarly, we obtain a similar bound for $\sum_{k=1}^{d-1}\mathbb{E}[T_{2}^{k}]$.

$$ $\begin{split}&\sum_{k=1}^{d}(\mathbb{E}[T_{2}^{k}]=\sum_{k=1}^{d-1}d^{2}/((k+1 )(d-k))=2\sum_{k=1}^{(d-1)/2}d^{2}/((k+1)(d-k))\\ &2\sum_{k=1}^{(d-1)/2}d^{2}/((k+1)(d-k))\leq 2d\sum_{k=1}^{(d-1)/2}\Big{[} \frac{1}{k+1}+\frac{1}{d-k}\Big{]}\approx 4d\log((d-1)/2)\end{split}$ (36) $$

Overall $\mathbb{E}[T_{\mathsf{sum}}]\approx 8d\log(d/2)$.
From Markov inequality, it immediately follows that $P(T_{\mathsf{sum}}\leq 8cd\log(d/2))\geq 1-\frac{1}{c}$.
In the above approximations, we use $\sum_{i=1}^{d}\frac{1}{i}\approx\log d+\gamma$, where $\gamma$ is Euler’s constant. We drop $\gamma$ as its a constant, which can always be absorbed by adapting the constant $c$.

∎

See 3

###### Proof.

Suppose the support of training distribution $p(z)$ contains $s$ groups. We know that these $s$ groups are drawn uniformly at random. From Theorem 5, it is clear that if $s$ grows as $\mathcal{O}(d\log d)$, then with a high probability the entire grid of $d^{2}$ combinations is contained in the affine span of these observed groups. This can be equivalently stated as ${\mathcal{Z}^{\times}}\subseteq\mathsf{DAff}(\mathcal{Z}^{\mathsf{train}})$ with a probability greater than equal to $1-\frac{1}{c}$. If ${\mathcal{Z}^{\times}}\subseteq\mathsf{DAff}(\mathcal{Z}^{\mathsf{train}})$, then from the assumption of compositional shifts, it follows that $\mathcal{Z}^{\mathsf{test}}\subseteq\mathsf{DAff}(\mathcal{Z}^{\mathsf{train}})$. We can now use Theorem 2 and arrive at our result. This completes the proof.
∎

###### Lemma 2 .

###### Proof.

###### Theorem 4 .

###### Proof.

###### Theorem 5 .

###### Proof.

###### Proof.

### 9.4 Discrete Affine Hull: A Closer Look

In the next result, we aim to give a characterization of discrete affine hull that helps us give a two-dimensional visualization of $\mathsf{DAff}(\mathcal{Z}^{\mathsf{train}})$. Before we even state the result, we illustrate discrete affine hull of a $6\times 6$ grid. Consider the $6\times 6$ grid shown in Figure 4. The attribute combinations corresponding to the observed groups are shown as solid colored cells (blue and yellow). The light shaded elements (blue and yellow) denote the set of groups that belong to the affine hull of the solid colored groups. We now build the characterization that helps explain this visualization.

Figure: Figure 4: Illustration of the discrete affine hull. Each cell in the $6\times 6$ grid represents an attribute combination, where observed combinations are solid-colored. The elements in blue form one connected component, $C_{1}$, and the elements in yellow form another connected component, $C_{2}$. Extrapolation is possible for unobserved combinations, represented by the crosshatched cells, as long as the test distribution samples from the Cartesian products of the connected components. The steps for completing the Cartesian product visually shows the intuition behind the extrapolation process.
Refer to caption: x3.png

We introduce a graph on the attribute vectors observed. Each vertex corresponds to the attribute vector, i.e., $[z_{1},z_{2}]$. There is an edge between two vertices if the Hamming distance between the attribute vectors is one. A connected component is a subgraph in which all vertices are connected, i.e., between every pair in the subgraph there exists a path. Let us start by making an observation about the connected components in this graph.

We consider a partition of observed groups into $K$ maximally connected components, $\{C_{1},\cdots,C_{K}\}$. Define $C_{ij}$ as the set of values the $j^{th}$ component takes in the $i^{th}$ connected component. Observe that $C_{ij}\cap C_{lj}=\emptyset$ for $i\not=l$. Suppose this was not that case and $C_{ij}\cap C_{lj}\not=\emptyset$. In such a case, there exists a point in $C_{i}$ and another point in $C_{l}$ that share the $j^{th}$ component. As a result, the two points are connected by an edge and hence that would connect $C_{i}$ and $C_{j}$. This contradicts the fact that $C_{i}$ and $C_{j}$ are maximally connected, i.e., we cannot add another vertex to the graph while maintaining that there is a path between any two points in the component. In what follows, we will show that the afine hull of $C_{j}$ is $C_{j1}\times C_{j2}$, which is the Cartesian product extension of set $C_{j}$. Next, we give some definitions and make a simple observation that allows us to think of sets $C_{j1}\times C_{j2}$ as subgrids, which are easier to visualize.

###### Definition 1 .

Contiguous connected component: For each coordinate $j\in\{1,2\}$, consider the smallest value and the largest value assumed by it in the connected component $C$ and call it $\min_{j}$ and $\max_{j}$. We say that the connected component $C$ is contigous if each value in the set $\{\min_{j},\min_{j}+1,\cdots,\max_{j}-1,\max_{j}\}$ is assumed by some point in $C$ for all $j\in\{1,2\}$.

Smallest subgrid containing a contigous connected component $C$: The range of values assumed by $j^{th}$ coordinate in $C$, where $j\in\{1,2\}$, are $\{\min_{j},\cdots,\max_{j}\}$. The subgrid $\{\min_{1},\cdots\max_{1}\}\times\{\min_{2},\cdots\max_{2}\}$ is the smallest subgrid containing $C$. Observe that this subgrid is the smallest grid containing $C$ because if we drop any column or row, then some point taking that value in $C$ will not be in the subgrid anymore.

The groups observed at training time can be divided into $K$ maximally connected components $\{C_{1},\cdots,C_{K}\}$. We argue that without any loss of generality each of these components are contiguous. Suppose some of the components in $\{C_{1},\cdots,C_{K}\}$ are not contiguous. We relabel the first coordinate as $\pi(c_{i1}^{r})=\sum_{j<i}|C_{j1}|+r$, where $c_{i1}^{r}$ is the $r^{th}$ point in $C_{i1}$. We can similarly relabel the second coordinate as well. Under the relabeled coordinates, each component is maximally connected and contiguous. Also, under this relabeling the Cartesian products $C_{j1}\times C_{j2}$ correspond to the smallest subgrid containing $C_{j}$. Let us go back to the setting of Figure 4. The sets of observed groups shown in solid blue and solid yellow form two connected components $C_{1}$ and $C_{2}$ respectively. Their Cartesian product extensions are shown as well in the Figure 4. Since the connected components were contiguous the Cartesian product extensions correspond to smallest subgrids containing the respective connected component.

###### Theorem 6 .

Given the partition of training support as $\mathcal{Z}^{\mathsf{train}}=\{C_{1},\cdots,C_{K}\}$, we have:

- •
The affine span of a contiguous connected component $C$ is the smallest subgrid that contains that connected component $C$.
- •
The affine span of the union over disjoint contiguous connected components is the union of the smallest subgrids that contain the respective connected components.

###### Proof.

$C$ denotes the connected component under consideration and the smallest subgrid containing it is $S$. Denote the affine span of $C$ as $A$. We first show that the subgrid $S\subseteq A$.

We start with a target point $t=(t_{1},t_{2})$ inside $S$. We want show that the one-hot concatention of this point $t$ can be expressed as an affine combination of the points in $C$.

Firstly, if $t$ is already in $C$, then the point is trivially in the affine span. If that is not the case, then let us proceed to more involved cases. Consider the shortest path joining a point of the form $(t_{1},s_{2})\in C$, where $s_{2}\not=t_{2}$, and a point of the form $(s_{1},t_{2})\in C$, where $s_{1}\not=t_{1}$. If such points do not exist, then $t$ cannot be in $S$, which is a contradiction.

We assign a weight of $(+1)$ to the concatenation of one-hot encodings of the point $(t_{1},s_{2})$. We then traverse the path until we encounter a point where $s_{2}$ changes, note that such a point has to occur because of existence of $(s_{1},t_{2})$ on the path. We call this point $v=(\tilde{s}_{1}^{{}^{\prime}},s_{2}^{{}^{\prime}})$. The point before $v$ on the path is $w=(\tilde{s}_{1}^{{}^{\prime}},s_{2})$. We assign a weight of $(-1)$ to $w$. We summarize the path seen so far below. We also write the weights assigned to the points

$$ $\begin{split}s&=(t_{1},s_{2})\hskip 85.35826pt{\color[rgb]{0,0,1}\definecolor[ named]{pgfstrokecolor}{rgb}{0,0,1}(+1)}\\ u&=(s_{1}^{{}^{\prime}},s_{2})\\ &\vdots\\ w&=(\tilde{s}_{1}^{{}^{\prime}},s_{2})\hskip 85.35826pt{\color[rgb]{0,0,1} \definecolor[named]{pgfstrokecolor}{rgb}{0,0,1}(-1)}\\ v&=(\tilde{s}_{1}^{{}^{\prime}},s_{2}^{{}^{\prime}})\end{split}$ (37) $$

After $w$, we have a weight of $+1$ assigned to $t_{1}$, $-1$ assigned to $\tilde{s}_{1}^{{}^{\prime}}$ (note that $\tilde{s}_{1}^{{}^{\prime}}$ cannot be $t_{1}$, this follows from the fact that we are on shortest path between points of the form $(t_{1},s_{2})$ and $(s_{1},t_{2})$). We call this state $S_{1}$. After $w$, we wait for a point on the path where $\tilde{s}_{1}^{{}^{\prime}}$ changes or we reach the terminal state $(s_{1},t_{2})$. The latter can happen if $\tilde{s}_{1}^{{}^{\prime}}=s_{1}$. In the latter case, we assign a weight $(+1)$ to the terminal state and thus the final weights are $(+1)$ for $t_{1}$ and $t_{2}$ and zero for everything else. This leads to the desired affine combination. We call this state $T_{1}$, corresponding to terminal state.

Now suppose we were in a situation where we reach a point $q=(s_{1}^{+},\tilde{s}_{2}^{{}^{\prime}})$. The point before $q$ is $r=(\tilde{s}_{1}^{{}^{\prime}},\tilde{s}_{2}^{{}^{\prime}})$. We assign a weight of $(+1)$ to $r$. We summarize the path seen after encountering $w$ below.

$$ $\begin{split}v&=(\tilde{s}_{1}^{{}^{\prime}},s_{2}^{{}^{\prime}})\\ &\vdots\\ r&=(\tilde{s}_{1}^{{}^{\prime}},\tilde{s}_{2}^{{}^{\prime}})\hskip 85.35826pt{ \color[rgb]{0,0,1}\definecolor[named]{pgfstrokecolor}{rgb}{0,0,1}(+1)}\\ q&=(s_{1}^{+},\tilde{s}_{2}^{{}^{\prime}})\end{split}$ (38) $$

After $r$, we have a weight of $+1$ assigned to $t_{1}$ and a weight of $+1$ assigned to $\tilde{s}_{2}^{{}^{\prime}}$. We call this state $S_{2}$. After $r$, we wait for a point where $\tilde{s}_{2}^{{}^{\prime}}$ changes. It could be that $\tilde{s}_{2}^{{}^{\prime}}$ changes to $t_{2}$. The state before it is say $u=(s_{1},\tilde{s}_{2}^{{}^{\prime}})$ and last state $e=(s_{1},t_{2})$. Assign a weight of $-1$ to $u$ and assign
a weight of $+1$ to $e$. Thus we achieve the target as affine combination of points on the path. We call this state $T_{2}$, corresponding to the terminal state.

Now let us consider the other possibility that the terminal state has not been reached. We call such a point $m=(\tilde{s}_{1}^{+},\tilde{s}_{2}^{+})$. The point that occurs before this point is $l=(\tilde{s}_{1}^{+},\tilde{s}_{2}^{{}^{\prime}})$. We assign a weight of $(-1)$ to $l$. We summarize the path taken below.

$$ $\begin{split}q&=(s_{1}^{+},\tilde{s}_{2}^{{}^{\prime}})\\ &\vdots\\ l&=(\tilde{s}_{1}^{+},\tilde{s}_{2}^{{}^{\prime}})\hskip 85.35826pt{\color[rgb ]{0,0,1}\definecolor[named]{pgfstrokecolor}{rgb}{0,0,1}(-1)}\\ m&=(\tilde{s}_{1}^{+},\tilde{s}_{2}^{+})\end{split}$ (39) $$

After $l$, $t_{1}$ is assigned a weight of $+1$ and $\tilde{s}_{1}^{+}$ is assigned a weight of $-1$. We reach the state $S_{1}$ again. From this point on, the same steps repeat. We keep cycling between $S_{1}$ and $S_{2}$ until we reach the terminal state from either $S_{1}$ or $S_{2}$ at which point we achieve the desired affine combination. The cycling of states only goes on for a finite number of steps as the entire path we are concerned with has a finite length. We show the process in Figure 5. Thus $S\subseteq A$.

We now make an observation about the set $A$, which is the affine hull of set $C$. Suppose the first coordinate takes values between $\{\min_{1},\cdots,\max_{1}\}$. The corresponding one-hot encodings of the first coordinate are written as $\{\mathrm{onehot}(\min_{1}),\cdots,\mathrm{onehot}(\max_{1})\}$. Now consider a value $c$ which is not in $\{\min_{1},\cdots,\max_{1}\}$. We claim that no affine combination of vectors in $\{\mathrm{onehot}(\min_{1}),\cdots,\mathrm{onehot}(\max_{1})\}$ can lead to $\mathrm{onehot}(c)$. We justify this claim as follows. Observe that no vector in $\{\mathrm{onehot}(\min_{1}),\cdots,\mathrm{onehot}(\max_{1})\}$ has a non-zero entry in the same coordinate where $\mathrm{onehot}(c)$ is also non-zero. Hence, any affine combination of vectors in $\{\mathrm{onehot}(\min_{1}),\cdots,\mathrm{onehot}(\max_{1})\}$ will always have a zero weight in the entry where $\mathrm{onehot}(c)$ is non-zero. It is now clear that the first component of affine hull of $A$ is always between $\{\min_{1},\cdots,\max_{1}\}$. Similarly, the second component of affine hull of $A$ is always between $\{\min_{2},\cdots,\max_{2}\}$. Therefore, $A\subseteq S$. As a result, $A=S$. Another way to say this is that $\mathsf{DAff}(C_{j})=C_{j1}\times C_{j2}$.

We now move to the second part of the theorem. We have already shown that $\mathsf{DAff}(C_{j})=C_{j1}\times C_{j2}$. We now want to show that

$$ $\mathsf{DAff}\big{(}\bigcup_{j=1}^{K}C_{j}\big{)}=\bigcup_{j=1}^{K}\Big{(}C_{j 1}\times C_{j2}\Big{)}$ $$

Observe that $\mathsf{DAff}(A)\subseteq\mathsf{DAff}(A\cup B)$ and $\mathsf{DAff}(B)\subseteq\mathsf{DAff}(A\cup B)$, which implies $\mathsf{DAff}(A)\cup\mathsf{DAff}(B)\subseteq\mathsf{DAff}(A\cup B)$. Therefore, from the first part and this observation it follows that $\bigcup_{j=1}^{K}\Big{(}C_{j1}\times C_{j2}\Big{)}\subseteq\mathsf{DAff}\big{(
}\bigcup_{j=1}^{K}C_{j}\big{)}$. We now show $\mathsf{DAff}\big{(}\bigcup_{j=1}^{K}C_{j}\big{)}\subseteq\bigcup_{j=1}^{K}
\Big{(}C_{j1}\times C_{j2}\Big{)}$.

Take the $K$ maximally connected components $\{C_{1},\cdots,C_{K}\}$ and let the set of respective smallest subgrids containing them be $\{S_{1},\cdots,S_{K}\}$. Define a point $z^{\prime}$ as the affine combination of points across these components as $z^{\prime}=\sum_{i=1}^{K}\sum_{j=1}^{N_{i}}\alpha_{ij}z_{ij}$, where $z_{ij}$ is the $j^{th}$ point in $C_{i}$, which contains $N_{i}$ points. We can also write $z^{\prime}$ as $z^{\prime}=\sum_{i=1}^{K}\Big{(}\sum_{j=1}^{N_{i}}\alpha_{ij}\Big{)}\sum_{j=1}
^{N_{i}}\frac{\alpha_{ij}}{\sum_{j=1}^{N_{i}}\alpha_{ij}}z_{ij}$. Define $z^{\prime}_{i}=\sum_{j=1}^{N_{i}}\frac{\alpha_{ij}}{\sum_{j=1}^{N_{i}}\alpha_{
ij}}z_{ij}$. Observe that $z^{\prime}_{i}$ is in the affine combination of points in $C_{i}$ and hence $z^{\prime}_{i}$ is a point in $S_{i}$. Let $\tilde{\alpha}_{i}=\sum_{j=1}^{N_{i}}\alpha_{ij}$. In this notation, we can see $z^{\prime}$ is an affine combination of $z^{\prime}_{i}$’s denoted as $\sum_{i=1}^{K}\tilde{\alpha}_{i}z^{\prime}_{i}$. In this representation, there is at most one point per $S_{i}$ in the affine combination. There are two cases to consider. In the first case, exactly one component $\tilde{\alpha}_{i}$ is non-zero and rest all components are zero. In the second case, at least two components $\tilde{\alpha}_{i}$’s are non-zero. In this setting, we can only keep the non-zero $\tilde{\alpha}_{i}$’s in the sum denoted as $\sum_{i}\tilde{\alpha}_{i}z^{\prime}_{i}$. Suppose $z^{\prime}_{i}=(e_{p},e_{q})$ (without loss of generality), where $e_{p}$ is one-hot vector that is one on the $p^{th}$ coordinate. Observe that no other point in the sum $\sum_{i}\tilde{\alpha}_{i}z^{\prime}_{i}$ will have a non-zero contribution on the $p^{th}$ coordinate. As a result, in the final vector the $p^{th}$ coordinate of the first attribute will take the value $0<\tilde{\alpha}_{i}<1$. This point is not a valid point in the set of all possible one-hot concatenations $\mathcal{Z}$ and hence it does not belong to the affine hull $\mathsf{DAff}\big{(}\bigcup_{j=1}^{K}C_{j}\big{)}$. Thus we are left with the first case. Observe that in the first case, we will always generate a point in one of the $\mathsf{DAff}(C_{j})$, where $j\in\{1,\cdots,K\}$. Thus $\mathsf{DAff}\big{(}\bigcup_{j=1}^{K}C_{j}\big{)}\subseteq\bigcup_{j=1}^{K}
\mathsf{DAff}(C_{j})$, which implies $\mathsf{DAff}\big{(}\bigcup_{j=1}^{K}C_{j}\big{)}\subseteq\bigcup_{j=1}^{K}C_{
j1}\times C_{j2}$. This completes the proof.

∎

Figure: Figure 5: Illustration of state transition in proof of Theorem 6.
Refer to caption: x4.png

###### Definition 1 .

###### Theorem 6 .

###### Proof.

### 9.5 No Extrapolation beyond Discrete Affine Hull: Proof for Theorem 7

In this section, we rely on the characterization of discrete affine hulls shown in the previous section in Theorem 6. Suppose we learn an additive energy model to estimate $\hat{p}(x|z)$ and estimate the density $p(x|z)$ for all training groups using maximum likelihood. In this case, we know that $\hat{p}(x|z)=p(x|z)$ for all $z\in\mathsf{DAff}(\mathcal{Z}^{\mathsf{train}})$. In the next theorem, we show that such densities that satisfy $\hat{p}(x|z)=p(x|z)$ for all $z\in\mathsf{DAff}(\mathcal{Z}^{\mathsf{train}})$ may not match the true density outside the affine hull. In the next result, we assume that $\forall z\in{\mathcal{Z}^{\times}},p(\cdot|z)$ is not uniform.

###### Theorem 7 .

Suppose we learn an additive energy model to estimate $\hat{p}(x|z)$ and estimate the density $p(x|z)$ for all training groups. There exist densities that maximize likelihood and exactly match the training distributions but do not extrapolate to distributions outside the affine hull of $\mathcal{Z}^{\mathsf{train}}$, i.e., $\exists z\in\mathcal{Z}^{\times}$, where $\hat{p}(\cdot|z)\not=p(\cdot|z)$.

###### Proof.

We first take $\mathcal{Z}^{\mathsf{train}}$ and partition the groups into $K$ maximally connected components denoted $\{C_{1},\cdots,C_{K}\}$. From Theorem 6, we know that the affine hull of $\mathcal{Z}^{\mathsf{train}}$ is the union of subgrids $\{S_{1},\cdots,S_{K}\}$, where each subgrid $S_{j}$ is the Cartesian product $C_{j1}\times C_{j2}$.

Let us consider all points $(\tilde{z}_{1},\tilde{z}_{2})$ in some subgrid $S_{k}$. For each such $(\tilde{z}_{1},\tilde{z}_{2})\in S_{k}$, define $\hat{E}_{1}(x,\tilde{z}_{1})=E_{1}(x,\tilde{z}_{1})+\alpha_{k}(x),$ $\hat{E}_{2}(x,\tilde{z}_{2})=E(x,\tilde{z}_{2})-\alpha_{k}(x)$. Note that regardless of choice of $\alpha_{k}$ the density, $\hat{p}(x|z)=\frac{1}{\mathbb{Z}(z)}e^{-\braket{\sigma(z),\hat{E}(x)}}$ matches the true density $p(x|z)$ for all groups $z$ in $\bigcup_{i=1}^{K}S_{i}$.

Select any group $z_{\mathsf{ref}}=(z_{1},z_{2})$ that is not in the union of subgrids. From the definition of $\mathcal{Z}^{\times}$, it follows that there are points of the form $(z_{1},z_{2}^{\prime})$ in one of the subgrid $S_{j}$ and points of the form $(z_{1}^{\prime},z_{2})$ are in some subgrid $S_{r}$. Let $\alpha_{j}(x)=-\frac{E_{1}(x,z_{1})+E_{2}(x,z_{2})}{2}$ and $\alpha_{r}(x)=\frac{E_{1}(x,z_{1})+E_{2}(x,z_{2})}{2}$. Observe that $\hat{E}_{1}(x,z_{1})+\hat{E}_{2}(x,z_{2})=E_{1}(x,z_{1})+E_{2}(x,z_{2})+\alpha
_{j}(x)-\alpha_{r}(x)=0$. Thus this choice of $\alpha_{j}(x)-\alpha_{r}(x)$ ensures that $\hat{p}(x|z_{1},z_{2})$ is uniform and hence cannot match the true $p(x|z_{1},z_{2})$.

This completes the proof.

∎

Based on the above proof, we now argue that there exist solutions to CRM that do not extrapolate outside the affine hull. Let us consider solutions to CRM denoted $\hat{E},\hat{B}$, which satisfies the property that $\braket{\sigma(z),\hat{E}(x)}=\braket{\sigma(z),E(x)},\hat{B}(z)=B(z)\forall z
\in\mathcal{Z}^{\mathsf{train}}$. Following the proof above, we can choose $\hat{E}^{\prime}s$ in such a way that the sum of energies at a certain reference point outside the affine hull is zero and at all points inside the affine hull the sum of energies achieve a perfect match. For the group $z_{\mathsf{ref}}=(z_{1},z_{2})$ not in the affine hull of $\mathcal{Z}^{\mathsf{train}}$, we set $\hat{E}_{1}(x,z_{1})+\hat{E}_{2}(x,z_{2})=\braket{\sigma(z),\hat{E}(x)}=0$.

Suppose $\hat{q}(z|x)=q(z|x),\forall z\in\mathsf{DAff}(\mathcal{Z}^{\mathsf{train}})
\bigcup\{z_{\mathsf{ref}}\}$. We now compute the likelihood ratio at $z_{\mathsf{ref}}$ and a point $z\in\mathcal{Z}^{\mathsf{train}}$. We obtain

$$ $\begin{split}&\frac{\hat{q}(z_{\mathsf{ref}}|x)}{\hat{q}(z|x)}=\frac{q(z_{ \mathsf{ref}}|x)}{q(z|x)}\implies\\ &-\log\Big{(}\frac{\hat{q}(z_{\mathsf{ref}}|x)}{\hat{q}(z|x)}\Big{)}=-\log\Big {(}\frac{q(z_{\mathsf{ref}}|x)}{q(z|x)}\Big{)}\implies\\ &\braket{\sigma(z_{\mathsf{ref}}),\hat{E}(x)}-\braket{\sigma(z),\hat{E}(x)}= \braket{\sigma(z_{\mathsf{ref}}),E(x)}-\braket{\sigma(z),E(x)}-(\theta(z)- \theta(z_{\mathsf{ref}}))\\ \end{split}$ (40) $$

where $\theta(z)$ corresponds to collection of all terms that only depend on $z$. We already know that $\braket{\sigma(z),\hat{E}(x)}=\braket{\sigma(z),E(x)}$ and $\braket{\sigma(z_{\mathsf{ref}}),\hat{E}(x)}=0$. Substituting these into the above expression we obtain

$$ $\braket{\sigma(z_{\mathsf{ref}}),E(x)}=\theta(z)-\theta(z_{\mathsf{ref}})$ (41) $$

From the above condition, it follows that $q(x|z_{\mathsf{ref}})$ is uniform. This implies that $p(x|z_{\mathsf{ref}})$ is also uniform, which contradicts the condition that $p(x|z_{\mathsf{ref}})$ is not uniform. Therefore, $\hat{q}(z|x)=q(z|x),\forall z\in\mathcal{Z}^{\mathsf{train}}\bigcup\{z_{
\mathsf{ref}}\}$ cannot be true.

###### Theorem 7 .

###### Proof.

## 10 Experiments Setup

### 10.1 Dataset Details

Waterbirds (Wah et al., ). The task is to classify land birds ($y=0$) from water birds ($y=1$), where the spurious attributes are land background ($a=0$) and water background ($a=1$). Hence, we have a total of 4 groups $z=(y,a)$ in the dataset.
CelebA (Liu et al., ). The task is to classify blond hair ($y=1$) from non-blond hair ($y=0$), where the spurious attribute is gender, female ($a=0$) and male ($a=1$). Hence, we have a total of 4 groups $z=(y,a)$ in the dataset.
MetaShift (Liang and Zou, ). The task is to classify cats ($y=0$) from dogs ($y=1$), where the spurious attribute is background, indoor ($a=0$) and outdoor ($a=1$). Hence, we have a total of 4 groups $z=(y,a)$ in the dataset.
MultiNLI (Williams et al., ). The task is to classify the relationship between the premise and hypothesis in a text document into one of the 3 classes: netural ($y=0$), contradiction ($y=1$), and entailment ($y=2$). The spurious attribute are words like negation (binary attribute $a$), which are correlated with the contradiction class. Hence, we have a total of 6 groups $z=(y,a)$ in the dataset.
CivilComments (Borkan et al., ). The task is to classify whether a text document contains toxic language ($y=0$) versus it doesn’t contain toxic language ($y=1$), where the spurious attribute $a$ corresponds to $8$ different demographic identities (Male, Female, LGBTQ, Christian, Muslim, Other Religions, Black, and White). Hence, we have a total of 16 groups $z=(y,a)$ in the dataset.
NICO++ (Zhang et al., ). This is a a large scale (60 classes with 6 spurious attributes) domain generalization benchmark, and we follow the procedure in Yang et al. () where all the groups with less than 75 samples were dropped from training. This leaves us with $337$ groups during training, however, the validation set still has samples from all the $360$ groups. Hence, we additionally discard these groups from the validation set as well to design the compositional shift version.

**Table 3: Statitics for the different benchmarks used in our experiments.**
| Dataset | Total Classes | Total Groups | Train Size | Val Size | Test Size |
| --- | --- | --- | --- | --- | --- |
| Waterbirds | 2 | 4 | 4795 | 1199 | 5794 |
| CelebA | 2 | 4 | 162770 | 19867 | 19962 |
| MetaShift | 2 | 4 | 2276 | 349 | 874 |
| MultiNLI | 3 | 6 | 206175 | 82462 | 123712 |
| CivilComments | 2 | 16 | 148304 | 24278 | 71854 |
| NICO++ | 60 | 360 | 62657 | 8726 | 17483 |

### 10.2 Metric Details

Given the test distributions $z=(y,a)\sim q(z)$ and $x\sim q(x|z)$, lets denote the corresponding class predictions as $\hat{y}=\hat{M}(x)$ as per the method $\hat{M}$ . Then average accuracy is defined as follows:

$$ $\text{Average Acc}:=\mathbb{E}_{(y,a)}\mathbb{E}_{x\sim q(x|z)}\big{[}\mathds{ 1}[y==\hat{M}(x)]\big{]}$ $$

Hence, this denotes the mean accuracy with groups drawn as per the test distribution $q(z)$. However, if certain (majority) groups have a higher probability of being sampled than others (minority groups) as per the distribution $q(z|x)$, then the average accuracy metric is more sensitive to mis-classifications in majority groups as compared to the minority groups. Hence, a method can achieve high average accuracy even though its accuracy for the minority groups might be low.
Therefore, we use the worst group accuracy metric, defined as follows.

$$ $\text{Worst Group Acc}:=min_{(y,a)\in\mathcal{Z}^{\mathsf{test}}}\mathbb{E}_{x \sim q(x|z)}\big{[}\mathds{1}[y==\hat{M}(x)]\big{]}$ $$

Essentially we compute the accuracy for each group $(y,a)\sim q(z)$ as $\mathbb{E}_{x\sim q(x|z)}\big{[}\mathds{1}[y==\hat{M}(x)]|\big{]}$ and then report the worst performance over all the groups. This metrics has been widely used for evaluating methods for subpopulation shifts (Sagawa et al., ; Yang et al., ).
Similarly, we define the group balanced accuracy (Tsirigotis et al., ) as follows, where we compute the average of all per-group accuracy $\mathbb{E}_{x\sim q(x|z)}\big{[}\mathds{1}[y==\hat{M}(x)]\big{]}$.

$$ $\text{Group Balanced Acc}:=\frac{1}{|\mathcal{Z}^{\mathsf{test}}|}\sum_{(y,a) \in\mathcal{Z}^{\mathsf{test}}}\mathbb{E}_{x\sim q(x|z)}\big{[}\mathds{1}[y== \hat{M}(x)]\big{]}$ $$

### 10.3 Method Details

For all the methods we have a *pre-trained* representation network backbone with linear classifier heads. We use ResNet-50 (He et al., ) for the vision datasets (Waterbirds, CelebA, MetaShift, NICO++) and BERT (Devlin et al., ) for the text datasets (MultiNLI, CivilComments). The parameters of both the representation network and linear classifier are updated with the same learning rate, and do not employ any special fine-tuning strategy for the representation network. For vision datasets we use the SGD optimizer (default values for momemtum 0.9), while for the text datasets we use the AdamW optimizer (Paszke et al., ) (default values for beta (0.9, 0.999) ).

#### Hyperparameter Selection.

We rely on the group balanced accuracy on the validation set to determine the optimal hyperparameters. We specify the grids for each hyperparameter in Table 4, and train each method with 5 randomly drawn hyperparameters. The grid sizes for hyperparameter selection were designed following Pezeshki et al. ().

**Table 4: Details about the grids for hyperparameter selection. The choices for grid sizes were taken from Pezeshki et al. ().**
| Dataset | Learning Rate | Weight Decay | Batch Size | Total Epochs |
| --- | --- | --- | --- | --- |
| Waterbirds | $10^{\text{Uniform}(-5,-3)}$ | $10^{\text{Uniform}(-6,-3)}$ | $2^{\text{Uniform}(5,7)}$ | 5000 |
| CelebA | $10^{\text{Uniform}(-5,-3)}$ | $10^{\text{Uniform}(-6,-3)}$ | $2^{\text{Uniform}(5,7)}$ | 10000 |
| MetaShift | $10^{\text{Uniform}(-5,-3)}$ | $10^{\text{Uniform}(-6,-3)}$ | $2^{\text{Uniform}(5,7)}$ | 5000 |
| MulitNLI | $10^{\text{Uniform}(-6,-4)}$ | $10^{\text{Uniform}(-6,-3)}$ | $2^{\text{Uniform}(4,6)}$ | 10000 |
| CivilComments | $10^{\text{Uniform}(-6,-4)}$ | $10^{\text{Uniform}(-6,-3)}$ | $2^{\text{Uniform}(4,6)}$ | 10000 |
| NICO++ | $10^{\text{Uniform}(-5,-3)}$ | $10^{\text{Uniform}(-6,-3)}$ | $2^{\text{Uniform}(5,7)}$ | 10000 |

## 11 Additional Results

### 11.1 Results for all the Compositional Shift Scenarios

Table 5, Table 6,  Table 7,  Table 8, and  Table 9 present the results for the Waterbirds, CelebA, MetaShift, MultiNLI, and CivilComments benchmark respectively. Here we do not aggregate over the multiple compositional shift scenarios of a benchmark, and provide a more detailed analysis with results for each scenario. For each method, we further highlight the worst case scenario for it, i.e, the scenario with the lowest worst group accuracy amongst all the compositional shift scenarios. This helps us easily compare the performance of methods for the respective worst case compositional shift scenario, as opposed to the average over all scenarios in Table 1. An interesting finding is that CRM outperforms all the baselines in the respective worst case compositional shift scenarios.

**Table 5: Results for the various compositional shift scenarios for the Waterbirds benchmark. For each metric, report the mean (standard error) over 3 random seeds on the test dataset. We highlight the worst case compositional shift scenario for each method, i.e, the scenario with the lowest worst group accuracy amongst all the compositional shift scenarios. CRM outperforms all the baselines in the respective worst case compositional shift scenarios.**
| Discarded Group ($y,a$) | Method | Average Acc | Balanced Acc | Worst Group Acc |
| --- | --- | --- | --- | --- |
| $(0,0)$ | ERM | $74.0$ $(0.0)$ | $82.3$ $(0.3)$ | $67.0$ $(0.0)$ |
| G-DRO | $77.3$ $(0.7)$ | $83.0$ $(0.6)$ | $59.7$ $(1.9)$ |  |
| LC | $85.7$ $(0.3)$ | $88.7$ $(0.3)$ | $82.0$ $(0.6)$ |  |
| sLA | $86.0$ $(0.0)$ | $89.0$ $(0.0)$ | $82.3$ $(0.3)$ |  |
| CRM | $86.7$ $(0.9)$ | $88.7$ $(0.3)$ | $83.0$ $(1.5)$ |  |
| $(0,1)$ | ERM | $67.3$ $(0.3)$ | $71.7$ $(0.3)$ | $28.0$ $(1.2)$ |
| G-DRO | $58.3$ $(3.2)$ | $70.7$ $(2.0)$ | $11.7$ $(4.6)$ |  |
| LC | $82.7$ $(3.2)$ | $86.0$ $(1.7)$ | $72.0$ $(5.8)$ |  |
| sLA | $86.3$ $(1.7)$ | $88.0$ $(1.0)$ | $78.7$ $(3.3)$ |  |
| CRM | $86.0$ $(2.1)$ | $86.7$ $(0.7)$ | $73.0$ $(4.2)$ |  |
| $(1,0)$ | ERM | $84.0$ $(0.0)$ | $78.0$ $(0.0)$ | $38.3$ $(0.3)$ |
| G-DRO | $90.0$ $(0.0)$ | $86.0$ $(0.6)$ | $67.0$ $(3.6)$ |  |
| LC | $93.0$ $(0.0)$ | $89.0$ $(0.6)$ | $79.0$ $(1.2)$ |  |
| sLA | $93.0$ $(0.0)$ | $89.0$ $(0.6)$ | $79.3$ $(1.5)$ |  |
| CRM | $86.7$ $(0.3)$ | $89.0$ $(0.0)$ | $83.7$ $(0.3)$ |  |
|  | ERM | $86.3$ $(0.3)$ | $69.3$ $(0.3)$ | $38.7$ $(0.7)$ |
|  | G-DRO | $86.0$ $(0.6)$ | $75.7$ $(2.2)$ | $31.0$ $(9.2)$ |
| $(1,1)$ | LC | $92.0$ $(0.0)$ | $84.0$ $(0.6)$ | $69.0$ $(1.5)$ |
|  | sLA | $92.0$ $(0.0)$ | $84.0$ $(0.6)$ | $69.0$ $(1.5)$ |
|  | CRM | $89.0$ $(0.6)$ | $86.7$ $(0.7)$ | $75.0$ $(3.2)$ |

**Table 6: Results for the various compositional shift scenarios for the CelebA benchmark. For each metric, report the mean (standard error) over 3 random seeds on the test dataset. We highlight the worst case compositional shift scenario for each method, i.e, the scenario with the lowest worst group accuracy amongst all the compositional shift scenarios. CRM outperforms all the baselines in the respective worst case compositional shift scenarios.**
| Discarded Group ($y,a$) | Method | Average Acc | Balanced Acc | Worst Group Acc |
| --- | --- | --- | --- | --- |
| $(0,0)$ | ERM | $68.7$ $(0.3)$ | $74.0$ $(0.0)$ | $37.7$ $(0.3)$ |
| G-DRO | $85.0$ $(0.6)$ | $88.0$ $(0.0)$ | $75.0$ $(1.2)$ |  |
| LC | $88.0$ $(0.0)$ | $90.3$ $(0.3)$ | $82.3$ $(0.3)$ |  |
| sLA | $87.7$ $(0.3)$ | $90.3$ $(0.3)$ | $82.3$ $(0.7)$ |  |
| CRM | $91.7$ $(0.3)$ | $89.3$ $(0.3)$ | $81.0$ $(2.0)$ |  |
| $(0,1)$ | ERM | $91.3$ $(0.9)$ | $91.0$ $(0.6)$ | $86.7$ $(1.3)$ |
| G-DRO | $85.0$ $(1.5)$ | $88.7$ $(0.7)$ | $72.7$ $(3.7)$ |  |
| LC | $93.0$ $(0.6)$ | $87.7$ $(0.9)$ | $71.0$ $(1.7)$ |  |
| sLA | $92.7$ $(0.3)$ | $88.0$ $(0.0)$ | $71.3$ $(0.9)$ |  |
| CRM | $88.3$ $(0.9)$ | $91.0$ $(0.6)$ | $85.0$ $(2.0)$ |  |
|  | ERM | $87.0$ $(0.0)$ | $59.3$ $(0.3)$ | $4.0$ $(0.0)$ |
|  | G-DRO | $91.7$ $(0.3)$ | $86.3$ $(0.7)$ | $71.7$ $(0.9)$ |
| $(1,0)$ | LC | $88.3$ $(0.3)$ | $70.7$ $(0.7)$ | $21.0$ $(2.1)$ |
|  | sLA | $88.3$ $(0.3)$ | $71.0$ $(0.6)$ | $21.3$ $(1.9)$ |
|  | CRM | $93.0$ $(0.0)$ | $85.7$ $(0.3)$ | $73.3$ $(1.8)$ |
| $(1,1)$ | ERM | $96.0$ $(0.0)$ | $78.0$ $(0.6)$ | $27.7$ $(2.0)$ |
| G-DRO | $95.0$ $(0.0)$ | $84.3$ $(0.3)$ | $51.7$ $(1.2)$ |  |
| LC | $95.0$ $(0.0)$ | $85.3$ $(0.3)$ | $55.3$ $(1.9)$ |  |
| sLA | $95.0$ $(0.0)$ | $85.0$ $(0.6)$ | $54.7$ $(2.3)$ |  |
| CRM | $91.3$ $(0.3)$ | $91.0$ $(0.0)$ | $88.0$ $(0.6)$ |  |

**Table 7: Results for the various compositional shift scenarios for the MetaShift benchmark. For each metric, report the mean (standard error) over 3 random seeds on the test dataset. We highlight the worst case compositional shift scenario for each method, i.e, the scenario with the lowest worst group accuracy amongst all the compositional shift scenarios. CRM outperforms all the baselines in the respective worst case compositional shift scenarios.**
| Discarded Group ($y,a$) | Method | Average Acc | Balanced Acc | Worst Group Acc |
| --- | --- | --- | --- | --- |
| $(0,0)$ | ERM | $84.3$ $(0.3)$ | $84.0$ $(0.6)$ | $80.3$ $(0.9)$ |
| G-DRO | $84.0$ $(0.6)$ | $83.3$ $(0.7)$ | $78.0$ $(0.6)$ |  |
| LC | $89.0$ $(0.0)$ | $85.7$ $(0.3)$ | $74.3$ $(1.8)$ |  |
| sLA | $90.0$ $(0.0)$ | $85.0$ $(0.0)$ | $67.3$ $(1.9)$ |  |
| CRM | $87.3$ $(0.3)$ | $84.3$ $(0.3)$ | $73.3$ $(0.7)$ |  |
| $(0,1)$ | ERM | $85.0$ $(0.0)$ | $79.0$ $(0.0)$ | $49.0$ $(0.0)$ |
| G-DRO | $86.0$ $(1.0)$ | $81.7$ $(0.3)$ | $55.3$ $(3.2)$ |  |
| LC | $86.0$ $(0.0)$ | $84.0$ $(0.0)$ | $63.7$ $(0.3)$ |  |
| sLA | $86.0$ $(0.0)$ | $84.0$ $(0.0)$ | $64.0$ $(0.6)$ |  |
| CRM | $88.3$ $(0.3)$ | $85.7$ $(0.3)$ | $78.0$ $(1.0)$ |  |
|  | ERM | $90.0$ $(0.0)$ | $82.0$ $(0.0)$ | $48.3$ $(0.3)$ |
|  | G-DRO | $90.3$ $(0.3)$ | $82.7$ $(0.9)$ | $52.7$ $(2.3)$ |
| $(1,0)$ | LC | $90.0$ $(0.0)$ | $84.3$ $(0.3)$ | $62.0$ $(0.0)$ |
|  | sLA | $88.7$ $(0.3)$ | $81.0$ $(0.0)$ | $46.7$ $(0.7)$ |
|  | CRM | $87.0$ $(1.2)$ | $83.3$ $(0.7)$ | $70.0$ $(1.0)$ |
| $(1,1)$ | ERM | $83.3$ $(1.2)$ | $81.7$ $(0.9)$ | $64.3$ $(1.2)$ |
| G-DRO | $83.7$ $(0.9)$ | $82.7$ $(0.9)$ | $69.3$ $(2.0)$ |  |
| LC | $89.0$ $(0.0)$ | $86.0$ $(0.0)$ | $72.7$ $(0.7)$ |  |
| sLA | $89.0$ $(0.0)$ | $86.0$ $(0.0)$ | $74.0$ $(0.0)$ |  |
| CRM | $87.7$ $(0.3)$ | $85.3$ $(0.3)$ | $72.3$ $(1.7)$ |  |

**Table 8: Results for the various compositional shift scenarios for the MultiNLI benchmark. For each metric, report the mean (standard error) over 3 random seeds on the test dataset. We highlight the worst case compositional shift scenario for each method, i.e, the scenario with the lowest worst group accuracy amongst all the compositional shift scenarios. CRM outperforms all the baselines in the respective worst case compositional shift scenarios.**
| Discarded Group $(y,a)$ | Method | Average Acc | Balanced Acc | Worst Group Acc |
| --- | --- | --- | --- | --- |
|  | ERM | $62.7$ $(0.3)$ | $66.7$ $(0.3)$ | $0.7$ $(0.3)$ |
|  | G-DRO | $63.3$ $(0.3)$ | $68.0$ $(0.0)$ | $1.7$ $(0.7)$ |
| $(0,0)$ | LC | $68.0$ $(0.0)$ | $72.0$ $(0.0)$ | $20.0$ $(0.0)$ |
|  | sLA | $67.7$ $(0.3)$ | $72.0$ $(0.0)$ | $19.7$ $(1.5)$ |
|  | CRM | $64.7$ $(0.9)$ | $70.7$ $(0.9)$ | $31.0$ $(5.6)$ |
| $(0,1)$ | ERM | $77.7$ $(0.3)$ | $71.7$ $(0.3)$ | $14.0$ $(1.0)$ |
| G-DRO | $80.7$ $(0.7)$ | $80.7$ $(0.7)$ | $74.0$ $(1.0)$ |  |
| LC | $81.0$ $(0.0)$ | $81.0$ $(0.0)$ | $75.3$ $(0.3)$ |  |
| sLA | $81.3$ $(0.3)$ | $80.7$ $(0.3)$ | $69.0$ $(0.6)$ |  |
| CRM | $80.0$ $(0.6)$ | $78.0$ $(1.2)$ | $62.3$ $(8.2)$ |  |
| $(1,0)$ | ERM | $58.0$ $(0.0)$ | $67.0$ $(0.0)$ | $0.0$ $(0.0)$ |
| G-DRO | $57.7$ $(0.3)$ | $67.7$ $(0.3)$ | $0.0$ $(0.0)$ |  |
| LC | $70.7$ $(0.9)$ | $74.3$ $(0.3)$ | $47.3$ $(4.3)$ |  |
| sLA | $73.3$ $(2.7)$ | $76.3$ $(1.7)$ | $58.3$ $(9.7)$ |  |
| CRM | $69.5$ $(0.5)$ | $74.0$ $(0.0)$ | $63.5$ $(0.5)$ |  |
| $(1,1)$ | ERM | $82.0$ $(0.2)$ | $73.0$ $(0.2)$ | $20.0$ $(1.2)$ |
| G-DRO | $80.3$ $(0.3)$ | $79.3$ $(0.3)$ | $72.7$ $(0.9)$ |  |
| LC | $81.7$ $(0.3)$ | $81.3$ $(0.3)$ | $74.3$ $(1.5)$ |  |
| sLA | $82.0$ $(0.0)$ | $81.0$ $(0.0)$ | $75.3$ $(0.7)$ |  |
| CRM | $81.3$ $(0.3)$ | $80.7$ $(0.3)$ | $71.3$ $(1.8)$ |  |
| $(2,0)$ | ERM | $62.0$ $(0.0)$ | $68.3$ $(0.3)$ | $0.0$ $(0.0)$ |
| G-DRO | $60.0$ $(0.0)$ | $67.7$ $(0.3)$ | $0.0$ $(0.0)$ |  |
| LC | $72.3$ $(0.3)$ | $74.7$ $(0.3)$ | $48.7$ $(0.7)$ |  |
| sLA | $72.7$ $(0.7)$ | $74.3$ $(0.3)$ | $48.3$ $(0.9)$ |  |
| CRM | $68.7$ $(0.3)$ | $72.7$ $(0.3)$ | $50.0$ $(0.6)$ |  |
| $(2,1)$ | ERM | $81.3$ $(0.3)$ | $74.3$ $(0.3)$ | $17.3$ $(2.4)$ |
| G-DRO | $80.7$ $(0.3)$ | $79.0$ $(0.0)$ | $57.3$ $(2.2)$ |  |
| LC | $82.0$ $(0.0)$ | $80.7$ $(0.3)$ | $60.0$ $(1.2)$ |  |
| sLA | $81.7$ $(0.3)$ | $80.3$ $(0.3)$ | $59.3$ $(0.9)$ |  |
| CRM | $81.3$ $(0.3)$ | $80.0$ $(0.6)$ | $72.7$ $(0.9)$ |  |

**Table 9: Results for the various compositional shift scenarios for the CivilComments benchmark.**
| Discarded Group ($y,a$) | Method | Average Acc | Balanced Acc | Worst Group Acc |
| --- | --- | --- | --- | --- |
| $(0,0)$ | ERM | $79.0$ $(0.6)$ | $78.7$ $(0.3)$ | $61.3$ $(1.5)$ |
| G-DRO | $79.3$ $(1.2)$ | $79.0$ $(0.0)$ | $64.7$ $(3.0)$ |  |
| LC | $79.7$ $(0.3)$ | $79.0$ $(0.0)$ | $64.3$ $(0.9)$ |  |
| sLA | $79.7$ $(0.3)$ | $79.3$ $(0.3)$ | $66.7$ $(1.8)$ |  |
| CRM | $84.0$ $(0.0)$ | $78.7$ $(0.3)$ | $67.0$ $(2.5)$ |  |
| $(0,1)$ | ERM | $78.0$ $(0.6)$ | $78.3$ $(0.3)$ | $64.3$ $(1.2)$ |
| G-DRO | $78.0$ $(0.6)$ | $78.7$ $(0.3)$ | $64.3$ $(1.5)$ |  |
| LC | $79.3$ $(0.3)$ | $79.0$ $(0.0)$ | $64.3$ $(0.9)$ |  |
| sLA | $79.7$ $(0.3)$ | $79.0$ $(0.0)$ | $65.3$ $(0.3)$ |  |
| CRM | $83.3$ $(0.7)$ | $78.7$ $(0.3)$ | $71.0$ $(1.5)$ |  |
|  | ERM | $78.3$ $(0.3)$ | $77.7$ $(0.3)$ | $38.0$ $(1.0)$ |
| $(0,2)$ | G-DRO | $79.0$ $(0.6)$ | $78.3$ $(0.3)$ | $43.7$ $(0.3)$ |
|  | LC | $79.0$ $(0.6)$ | $79.0$ $(0.0)$ | $53.7$ $(2.3)$ |
|  | sLA | $79.3$ $(0.3)$ | $79.0$ $(0.0)$ | $55.0$ $(2.1)$ |
|  | CRM | $83.3$ $(0.3)$ | $78.7$ $(0.3)$ | $68.0$ $(1.0)$ |
| $(0,3)$ | ERM | $80.5$ $(0.5)$ | $79.0$ $(0.0)$ | $66.0$ $(2.0)$ |
| G-DRO | $80.0$ $(0.6)$ | $79.0$ $(0.0)$ | $67.3$ $(2.7)$ |  |
| LC | $81.3$ $(0.3)$ | $79.0$ $(0.0)$ | $69.0$ $(1.2)$ |  |
| sLA | $80.7$ $(0.7)$ | $79.0$ $(0.0)$ | $66.7$ $(2.7)$ |  |
| CRM | $83.7$ $(0.3)$ | $78.7$ $(0.3)$ | $69.7$ $(0.3)$ |  |
| $(0,4)$ | ERM | $78.0$ $(0.0)$ | $77.7$ $(0.3)$ | $38.0$ $(0.6)$ |
| G-DRO | $78.7$ $(0.9)$ | $78.7$ $(0.3)$ | $52.0$ $(3.2)$ |  |
| LC | $79.0$ $(0.0)$ | $79.0$ $(0.0)$ | $60.7$ $(1.5)$ |  |
| sLA | $78.3$ $(0.3)$ | $79.0$ $(0.0)$ | $62.0$ $(1.0)$ |  |
| CRM | $83.7$ $(0.3)$ | $79.0$ $(0.0)$ | $69.7$ $(1.9)$ |  |
| $(0,5)$ | ERM | $80.0$ $(0.0)$ | $79.0$ $(0.0)$ | $61.0$ $(0.6)$ |
| G-DRO | $80.0$ $(0.6)$ | $79.0$ $(0.0)$ | $67.3$ $(1.8)$ |  |
| LC | $79.3$ $(0.9)$ | $79.0$ $(0.0)$ | $65.7$ $(2.3)$ |  |
| sLA | $80.0$ $(0.0)$ | $79.7$ $(0.3)$ | $66.7$ $(0.3)$ |  |
| CRM | $84.0$ $(0.0)$ | $78.7$ $(0.3)$ | $71.0$ $(1.0)$ |  |
| $(0,6)$ | ERM | $78.7$ $(0.3)$ | $78.0$ $(0.0)$ | $36.3$ $(1.2)$ |
| G-DRO | $78.3$ $(0.3)$ | $78.3$ $(0.3)$ | $46.3$ $(1.2)$ |  |
| LC | $80.7$ $(0.3)$ | $79.0$ $(0.0)$ | $58.7$ $(2.3)$ |  |
| sLA | $79.7$ $(0.9)$ | $79.0$ $(0.0)$ | $57.0$ $(3.1)$ |  |
| CRM | $83.3$ $(0.7)$ | $78.7$ $(0.3)$ | $70.0$ $(1.0)$ |  |
| $(0,7)$ | ERM | $79.0$ $(0.0)$ | $77.7$ $(0.3)$ | $40.0$ $(1.2)$ |
| G-DRO | $77.7$ $(0.3)$ | $78.7$ $(0.3)$ | $49.7$ $(0.3)$ |  |
| LC | $79.7$ $(0.3)$ | $79.0$ $(0.0)$ | $60.0$ $(2.3)$ |  |
| sLA | $78.7$ $(0.3)$ | $79.0$ $(0.0)$ | $56.3$ $(1.3)$ |  |
| CRM | $83.3$ $(0.3)$ | $78.3$ $(0.3)$ | $64.0$ $(1.2)$ |  |
| $(1,0)$ | ERM | $81.3$ $(0.3)$ | $79.0$ $(0.0)$ | $60.3$ $(0.3)$ |
| G-DRO | $82.3$ $(0.7)$ | $79.0$ $(0.0)$ | $69.7$ $(1.3)$ |  |
| LC | $81.3$ $(0.3)$ | $79.0$ $(0.0)$ | $71.0$ $(0.6)$ |  |
| sLA | $81.3$ $(0.9)$ | $79.0$ $(0.0)$ | $70.0$ $(1.2)$ |  |
| CRM | $84.0$ $(0.0)$ | $78.0$ $(0.0)$ | $68.3$ $(0.9)$ |  |
| $(1,1)$ | ERM | $81.7$ $(0.3)$ | $77.7$ $(0.3)$ | $60.3$ $(1.2)$ |
| G-DRO | $82.0$ $(0.6)$ | $79.0$ $(0.0)$ | $67.3$ $(0.9)$ |  |
| LC | $80.7$ $(0.3)$ | $79.0$ $(0.0)$ | $69.3$ $(0.9)$ |  |
| sLA | $81.3$ $(0.3)$ | $79.0$ $(0.0)$ | $71.0$ $(1.2)$ |  |
| CRM | $84.0$ $(0.0)$ | $78.3$ $(0.3)$ | $70.0$ $(0.6)$ |  |
| $(1,2)$ | ERM | $81.3$ $(0.3)$ | $78.7$ $(0.3)$ | $61.3$ $(0.7)$ |
| G-DRO | $80.7$ $(0.3)$ | $79.0$ $(0.0)$ | $63.7$ $(2.4)$ |  |
| LC | $82.0$ $(0.6)$ | $79.0$ $(0.0)$ | $70.0$ $(2.1)$ |  |
| sLA | $82.0$ $(0.6)$ | $79.0$ $(0.0)$ | $69.7$ $(1.8)$ |  |
| CRM | $83.7$ $(0.3)$ | $78.3$ $(0.3)$ | $63.7$ $(3.2)$ |  |
| $(1,3)$ | ERM | $82.3$ $(0.9)$ | $78.0$ $(0.0)$ | $59.0$ $(1.5)$ |
| G-DRO | $81.0$ $(0.6)$ | $79.0$ $(0.0)$ | $67.3$ $(2.6)$ |  |
| LC | $82.0$ $(0.0)$ | $79.0$ $(0.0)$ | $70.0$ $(1.5)$ |  |
| sLA | $82.7$ $(0.9)$ | $79.3$ $(0.3)$ | $69.0$ $(1.5)$ |  |
| CRM | $83.7$ $(0.3)$ | $78.0$ $(0.0)$ | $71.0$ $(1.5)$ |  |
| $(1,4)$ | ERM | $82.3$ $(0.3)$ | $78.7$ $(0.3)$ | $58.3$ $(1.8)$ |
| G-DRO | $80.3$ $(0.3)$ | $79.0$ $(0.0)$ | $68.0$ $(0.6)$ |  |
| LC | $82.0$ $(0.0)$ | $79.3$ $(0.3)$ | $70.7$ $(0.3)$ |  |
| sLA | $82.0$ $(0.6)$ | $79.3$ $(0.3)$ | $70.0$ $(0.6)$ |  |
| CRM | $83.7$ $(0.3)$ | $78.3$ $(0.3)$ | $60.0$ $(1.5)$ |  |
| $(1,5)$ | ERM | $82.0$ $(0.0)$ | $78.7$ $(0.3)$ | $63.7$ $(0.3)$ |
| G-DRO | $81.7$ $(0.3)$ | $79.0$ $(0.0)$ | $64.7$ $(1.3)$ |  |
| LC | $81.3$ $(0.3)$ | $79.3$ $(0.3)$ | $68.3$ $(0.7)$ |  |
| sLA | $82.0$ $(0.6)$ | $79.0$ $(0.0)$ | $71.3$ $(0.9)$ |  |
| CRM | $83.7$ $(0.3)$ | $78.3$ $(0.3)$ | $70.0$ $(1.0)$ |  |
| $(1,6)$ | ERM | $82.0$ $(0.6)$ | $79.0$ $(0.0)$ | $65.3$ $(2.4)$ |
| G-DRO | $81.0$ $(0.0)$ | $79.3$ $(0.3)$ | $66.0$ $(1.2)$ |  |
| LC | $81.7$ $(0.7)$ | $79.0$ $(0.0)$ | $69.7$ $(2.3)$ |  |
| sLA | $80.7$ $(0.3)$ | $79.0$ $(0.0)$ | $66.7$ $(0.3)$ |  |
| CRM | $84.0$ $(0.0)$ | $78.3$ $(0.3)$ | $70.0$ $(1.5)$ |  |
| $(1,7)$ | ERM | $82.0$ $(1.2)$ | $78.7$ $(0.3)$ | $63.3$ $(1.8)$ |
| G-DRO | $81.0$ $(0.0)$ | $79.0$ $(0.0)$ | $64.3$ $(0.3)$ |  |
| LC | $81.7$ $(0.3)$ | $79.0$ $(0.0)$ | $66.0$ $(1.5)$ |  |
| sLA | $82.3$ $(0.3)$ | $79.0$ $(0.0)$ | $67.0$ $(1.5)$ |  |
| CRM | $84.0$ $(0.3)$ | $77.0$ $(0.0)$ | $65.0$ $(1.0)$ |  |

### 11.2 Results for Ablations with CRM

In the implementation of CRM in Algorithm 1, we have the following two choices; 1) we use the extrapolated bias $B^{\star}$ (equation 10); 2) we set $\hat{q}(z)$ as the uniform distribution, i.e, $\hat{q}(z=(y,a))=\frac{1}{d_{y}\times d_{a}}$. We now conduct ablation studies by varying these components as follows.

- •
*Bias $B^{\star}$ + Emp Prior:* We still use the extrapolated bias $B^{\star}$ but instead of uniform $\hat{q}(z)$, we use test dataset to obtain the counts of each group, denoted as the empirical prior. Note that this approach assumes the knowledge of test distribution of groups, hence we expect this to improve the average accuracy but not the necessarily the worst group accuracy.
- •
*Bias $\hat{B}$ + Unf Prior:* We still use the uniform prior for $\hat{q}(z)$ but instead of the extrapolated bias $B^{\star}$, we use the learned bias $\hat{B}$ (equation 8). This ablation helps us to understand whether extrapolated bias $B^{\star}$ are crucial for CRM to generalize to compositional shifts.
- •
*Bias $\hat{B}$+ Emp Prior:* Here we change both aspects of CRM as we use the learned bias $\hat{B}$ and empirical prior from the test dataset for $\hat{q}(z)$.

Table 10 presents the results of the ablation study. We find that extrapolated bias is crucial for CRM as the worst group accuracy with learned bias is much worse! Further, using empirical prior instead of the uniform prior leads to improvement in average accuracy at the cost of worst group accuracy.

**Table 10: Ablation study with CRM. We consider the average performance over the different compositional shift scenarios for each benchmark, and report the mean (standard error) over 3 random seeds on the test dataset. CRM corresponds to the usual implementation with extrapolated bias $B^{\star}$ and uniform prior for $\hat{q}(z)$. CRM obtains better worst group accuracy than all the ablations, highlighting the importance of both extrapolated bias and uniform prior! Extrapolated bias is critical for generalization to compositional shifts as the performance with learned bias is much worse.**
| Dataset | Ablation | Average Acc | Balanced Acc | Worst Group Acc |
| --- | --- | --- | --- | --- |
|  | CRM | $87.1$ $(0.7)$ | $87.8$ $(0.1)$ | $78.7$ $(1.6)$ |
| Waterbirds | Bias $B^{\star}$ + Emp Prior | $91.6$ $(0.2)$ | $87.4$ $(0.3)$ | $75.2$ $(1.3)$ |
| Bias $\hat{B}$ + Unf Prior | $81.2$ $(0.6)$ | $82.7$ $(0.2)$ | $55.7$ $(1.0)$ |  |
| Bias $\hat{B}$ + Emp Prior | $84.3$ $(0.6)$ | $81.6$ $(0.3)$ | $51.3$ $(1.0)$ |  |
|  | CRM | $91.1$ $(0.2)$ | $89.2$ $(0.3)$ | $81.8$ $(1.2)$ |
| CelebA | Bias $B^{\star}$ + Emp Prior | $94.3$ $(0.1)$ | $75.8$ $(0.4)$ | $34.1$ $(1.0)$ |
| Bias $\hat{B}$ + Unf Prior | $83.6$ $(0.1)$ | $84.7$ $(0.2)$ | $58.9$ $(0.4)$ |  |
| Bias $\hat{B}$ + Emp Prior | $90.9$ $(0.1)$ | $77.2$ $(0.3)$ | $35.4$ $(0.7)$ |  |
|  | CRM | $87.6$ $(0.2)$ | $84.7$ $(0.1)$ | $73.4$ $(0.7)$ |
| MetaShift | Bias $B^{\star}$ + Emp Prior | $89.2$ $(0.2)$ | $84.0$ $(0.4)$ | $65.1$ $(1.4)$ |
| Bias $\hat{B}$ + Unf Prior | $87.2$ $(0.3)$ | $82.9$ $(0.4)$ | $58.7$ $(0.6)$ |  |
| Bias $\hat{B}$ + Emp Prior | $88.1$ $(0.1)$ | $82.1$ $(0.1)$ | $56.1$ $(0.4)$ |  |
|  | CRM | $74.6$ $(0.5)$ | $76.1$ $(0.4)$ | $57.7$ $(3.0)$ |
| MultiNLI | Bias $B^{\star}$ + Emp Prior | $75.0$ $(0.5)$ | $72.2$ $(0.4)$ | $39.7$ $(3.2)$ |
| Bias $\hat{B}$ + Unf Prior | $72.9$ $(0.9)$ | $74.0$ $(0.4)$ | $28.9$ $(2.1)$ |  |
| Bias $\hat{B}$ + Emp Prior | $73.6$ $(0.9)$ | $70.8$ $(0.4)$ | $20.2$ $(0.2)$ |  |
|  | CRM | $83.7$ $(0.1)$ | $78.4$ $(0.1)$ | $68.1$ $(0.5)$ |
| CivilComments | Bias $B^{\star}$ + Emp Prior | $87.0$ $(0.0)$ | $74.1$ $(0.3)$ | $48.0$ $(1.2)$ |
| Bias $\hat{B}$ + Unf Prior | $76.8$ $(0.2)$ | $77.8$ $(0.0)$ | $51.9$ $(1.0)$ |  |
| Bias $\hat{B}$ + Emp Prior | $83.5$ $(0.1)$ | $78.0$ $(0.0)$ | $62.2$ $(0.6)$ |  |
|  | CRM | $84.7$ $(0.3)$ | $84.7$ $(0.3)$ | $40.3$ $(4.3)$ |
| NICO++ | Bias $B^{\star}$ + Emp Prior | $85.0$ $(0.0)$ | $85.0$ $(0.0)$ | $41.0$ $(4.9)$ |
| Bias $\hat{B}$ + Unf Prior | $85.0$ $(0.0)$ | $85.0$ $(0.0)$ | $31.0$ $(1.0)$ |  |
| Bias $\hat{B}$ + Emp Prior | $85.0$ $(0.0)$ | $85.0$ $(0.0)$ | $27.7$ $(3.9)$ |  |

### 11.3 Results for the Original Benchmarks

We present results for the original benchmarks $({\mathcal{D}}_{\mathsf{train}},{\mathcal{D}}_{\mathsf{val}},{\mathcal{D}}_{
\mathsf{train}})$ in Table 11, which corresponds to the standard subpopulation shift case for these benchmarks. For Waterbirds, CelebA, MetaShift, and MultiNLI, subpopulation shift implies all the groups $z=(y,a)$ are present in both the train and test dataset ($\mathcal{Z}^{\mathsf{train}}=\mathcal{Z}^{\mathsf{test}}={\mathcal{Z}^{\times}}$), however, the groups sizes change from train to test, inducing a spurious correaltion between class labels $y$ and attributes $a$. For the NICO++ dataset, we have a total of 360 groups in the test dataset but only 337 of them are present in the train dataset. But still this is not a compositional shift as the validation dataset contains all the 360 groups. We find that CRM is still competitive to the baselines for the standard subpopulation shift scenario of each benchmark!

**Table 11: Results for the standard subpopulation shift case for each benchmark. Here we do not transform the datasets for compositional shifts, hence all the groups are present in both the train and the test dataset (except the NICO++ benchmark). CRM is still competitive with the baselines for this scenario where no groups were discarded additionally.**
| Dataset | Method | Average Acc | Balanced Acc | Worst Group Acc |
| --- | --- | --- | --- | --- |
| Waterbirds | ERM | $87.3$ $(0.3)$ | $84.0$ $(0.0)$ | $62.3$ $(1.2)$ |
| G-DRO | $91.7$ $(0.3)$ | $91.0$ $(0.0)$ | $87.3$ $(0.3)$ |  |
| LC | $92.0$ $(0.0)$ | $91.0$ $(0.0)$ | $88.7$ $(0.3)$ |  |
| sLA | $92.3$ $(0.3)$ | $91.0$ $(0.0)$ | $89.7$ $(0.3)$ |  |
| CRM | $91.3$ $(0.9)$ | $91.0$ $(0.0)$ | $86.0$ $(0.6)$ |  |
| CelebA | ERM | $95.7$ $(0.3)$ | $84.0$ $(0.0)$ | $52.0$ $(1.0)$ |
| G-DRO | $92.0$ $(0.6)$ | $93.0$ $(0.0)$ | $91.0$ $(0.6)$ |  |
| LC | $92.0$ $(0.6)$ | $92.0$ $(0.0)$ | $90.0$ $(0.6)$ |  |
| sLA | $92.3$ $(0.3)$ | $91.7$ $(0.3)$ | $86.7$ $(1.9)$ |  |
| CRM | $93.0$ $(0.0)$ | $92.0$ $(0.0)$ | $89.0$ $(0.6)$ |  |
| MetaShift | ERM | $90.0$ $(0.0)$ | $84.0$ $(0.0)$ | $63.0$ $(0.0)$ |
| G-DRO | $90.3$ $(0.3)$ | $88.3$ $(0.3)$ | $80.7$ $(1.3)$ |  |
| LC | $89.7$ $(0.3)$ | $87.7$ $(0.3)$ | $80.0$ $(1.2)$ |  |
| sLA | $90.0$ $(0.6)$ | $87.7$ $(0.3)$ | $80.0$ $(1.2)$ |  |
| CRM | $88.3$ $(0.7)$ | $85.7$ $(0.3)$ | $74.7$ $(1.5)$ |  |
| MultiNLI | ERM | $81.7$ $(0.3)$ | $80.7$ $(0.3)$ | $68.0$ $(1.7)$ |
| G-DRO | $80.7$ $(0.3)$ | $78.0$ $(0.0)$ | $57.0$ $(2.3)$ |  |
| LC | $82.0$ $(0.0)$ | $82.0$ $(0.0)$ | $74.3$ $(1.2)$ |  |
| sLA | $82.0$ $(0.0)$ | $82.0$ $(0.0)$ | $71.7$ $(0.3)$ |  |
| CRM | $81.7$ $(0.3)$ | $81.7$ $(0.3)$ | $74.7$ $(1.3)$ |  |
| CivilComments | ERM | $80.3$ $(0.3)$ | $79.0$ $(0.0)$ | $61.0$ $(2.5)$ |
| G-DRO | $79.7$ $(0.3)$ | $79.0$ $(0.0)$ | $64.7$ $(1.5)$ |  |
| LC | $80.7$ $(0.3)$ | $79.7$ $(0.3)$ | $67.3$ $(0.3)$ |  |
| sLA | $80.3$ $(0.3)$ | $79.0$ $(0.0)$ | $66.3$ $(0.9)$ |  |
| CRM | $83.3$ $(0.3)$ | $78.0$ $(0.0)$ | $70.0$ $(0.6)$ |  |
| NICO++ | ERM | $85.3$ $(0.3)$ | $85.0$ $(0.0)$ | $35.3$ $(2.3)$ |
| G-DRO | $83.7$ $(0.3)$ | $83.3$ $(0.3)$ | $33.7$ $(1.2)$ |  |
| LC | $85.0$ $(0.0)$ | $85.0$ $(0.0)$ | $35.3$ $(2.3)$ |  |
| sLA | $85.0$ $(0.0)$ | $85.0$ $(0.0)$ | $35.3$ $(2.3)$ |  |
| CRM | $85.0$ $(0.0)$ | $84.7$ $(0.3)$ | $39.0$ $(3.2)$ |  |

### 11.4 Numerical Experiment for Discrete Affine Hull

**Table 12: Numerical experiments to check the probability that the affine hull of random $\mathcal{O}(\mathsf{poly}(m*d))$ one-hot concatenations span the entire set $\mathcal{Z}$. We sample random $3*m*d$ one-hot vectors and report the frequency of times out of $1000$ runs a random one-hot concatenation is in the affine hull of the selected set of vectors.**
| ($m=5,d=5$) | ($m=10,d=10$) | ($m=20,d=20$) |
| --- | --- | --- |
| $1.0$ | $1.0$ | 0.986 |

## Peer Reviews

confidence: 2
contribution: 3
initial_rating: 6
presentation: 3
questions: Please refer to weaknesses.
soundness: 3
strengths: - The compositional risk minimization method is reasonable and well-motivated.
- The formulation of the compositional shift setting provides a foundation for further research.
- Experimental results are good to support the method.
summary: This paper addresses the compositional shifts, a hard type of sub-population shifts, and proposes compositional risk minimization. The method is well-motivated and some theoretical analyses are provided. Results on the sub-population shift benchmark are shown to support the proposed method.
weaknesses: Based on the theoretical analysis and experimental results, my main concerns are as follows:

1. **Experimental Setting**: The analysis and proposed algorithm are designed to handle multiple attributes, with the theoretical advantages being most relevant for this multi-attribute context. However, the experiments are limited to only two attributes. I suggest that the authors include empirical results with multiple attributes to better align with the theoretical analysis.

2. **Results**: While the CRM results outperform the baselines in this study, I check the original benchmark paper [1] and find that CRM’s performance does not consistently exceed that of the baselines. Furthermore, the authors only report accuracy, which doesn’t fully account for group imbalances. Reporting Macro-F1 scores would provide a more comprehensive evaluation.

3. **“Disjoint” Setting**: I understand that the paper’s chosen disjoint setting adds a level of complexity. However, in real-world scenarios, it is often feasible to obtain a small number of samples for different attribute combinations (particularly with only two attributes, as in these experiments). The proposed method should also be evaluated in traditional settings where all attribute combinations have some representation. This would confirm that the method performs well without requiring group-dropping.

---

confidence: 4
contribution: 3
initial_rating: 6
presentation: 3
questions: The authors should address all my concerns presented in the Weakness part.
soundness: 3
strengths: This paper explores a significant and under-researched area related to compositional shifts, which has been largely overlooked in the existing literature. 

The study is quite rigorous and comprehensive. Notably, it introduces the proposed approach through a running example involving two attributes, which makes the contributions and motivations clear and accessible. Additionally, the formulation of the Compositional Risk Minimization (CRM) framework offers valuable insights for future research.
summary: This paper addresses a challenging scenario involving compositional shifts, where certain combinations of attributes are not present in the training distribution but appear in the test distribution. To tackle this issue, the authors propose a Compositional Risk Minimization (CRM) framework, which incorporates an additive energy classifier to predict multiple attributes. Furthermore, the framework adapts this classifier to effectively handle compositional shifts. Empirical studies demonstrate the effectiveness of the proposed CRM approach.
weaknesses: One significant concern pertains to the attribute distributions during compositional shifts, which are frequently encountered in real-world applications. For instance, the distribution may shift from uniform to long-tailed, or it may be long-tailed from the outset. In this context, is it still effective to assume the test group prior $q(z)$ to be uniform? I encourage the authors to consider and discuss this issue in their paper.

The efficiency of the proposed CRM approach should also be examined, particularly in the context of multiple attribute abstention cases.

---

confidence: 4
contribution: 3
initial_rating: 6
presentation: 4
questions: 1. I am a little confused of the assumption 1: $p(x|z)=q(x|z)$，i.e.  the data generation mechanism from attributes to the inputs remains invariant, which is the main claim in the paper,  hence the distribution shift is essentially caused by $p(z)\neq q(z)$, which further implies that $p(x)\neq q(x)$, due to  $p(x)= \int p(x|z)p(z)dz$, and $q(x)=\int q(x|z)q(z)dz$. So, the covariate shift is caused by the marginal differences on the attributes. This seems contradict to traditional DG. 

2. For sample complexity $s\geq 8cd\log(d/2)$,  $c$ lacks of specifications?
soundness: 3
strengths: 1. **Novel Approach**: The paper introduces a novel approach based on flexible additive energy models for compositionality in discriminative tasks, which can provably extrapolate to novel attribute combinations.
2. **Theoretical Grounding**: The approach is theoretically grounded, providing guarantees for generalization under compositional shifts, which is crucial for robust machine learning models.
3. **Comprehensive Evaluation**:  Extensive empirical studies and experiments to demonstrate the impact of different choices and validate the effectiveness of the proposed method.
summary: This paper focus on tackling the challenge of  subpopulation shift through Compositional risk minimization, where the theory of discriminative compositional shifts is established, and a practical algorithm (compositional risk minimization, CRM) is also given. Overall, the theory are technically sound  and the experimental results demonstrates that CRM is . A good paper but require more specifications.
weaknesses: 1. The Compositional Risk Minimization (CRM) framework lacks explicit constraints on feature representations, which is widely recognized as crucial for generalization under sub-population shifts [1]. While CRM effectively models compositional shifts through additive energy distributions, it does not incorporate mechanisms to ensure the learned features are robust and semantically meaningful across different attribute combinations. Could the author make a further discussion on this problem?
    
    [1] Liu et al., Causal Triplet: An Open Challenge for Intervention-centric Causal Representation Learning, 2023
    
2. For the implementation of Algorithm 1, how to pre-specifies the spurious attribute $a$?

3. The current experimental results are somewhat lacking of conviction. More advanced DG algorithms, e.g. IRM, VREx, Fishr, SelfReg, are recommended to be included in the experiments. 

4. The sample complexity $s$ w.r.t the dimension $d$ should be verified through simulation studies.

Meta-review: This submission is a borderline case. It proposed a problem called "compositional shift" as well as its solution called "compositional risk minimization". After the rebuttal, all three reviewers gave a rating of 6 that is "marginally above the acceptance threshold". During the internal discussions, none of three positive reviewers showed up, even after I cued them, suggesting that they were not truly supportive. In particular, reviewer x1T8 mentioned in his or her post-rebuttal comment that "although I still have concerns about the experimental settings (even if there are three attributes, I don't think they're enough to represent the setting considered in this paper), I would raise my score." My personal feeling is that the motivation of this work may not be strong enough --- as the authors mentioned, the problem under consideration is a **challenging and extreme** form of subpopulation shift, so why is such a hard problem meaningful in practice? Therefore, I don't think we can accept it for publication at such a competitive venue unless the authors can justify their motivation.

Decision: Reject