SlowGuess/NeurIPS_2023_OCR huggingface dataset:
where  $\lambda_{ca_k} := 1 / |TE_{ca_k}|$  and  $\lambda_{sp_j} := 1 / |TE_{sp_j}|$  are the regularization strength for the causal and spurious features  $z_{ca_k}$  and  $z_{sp_j}$  respectively,  $|\cdot|$  is the absolute value operator and  $\| \boldsymbol{w} \|_p$  is the  $L_p$  norm of the vector  $\boldsymbol{w}$ . Since  $|TE_{(\cdot)}| \in [0,1]$ , we have  $\lambda_{(\cdot)} = 1 / |TE_{(\cdot)}| \geq 1$ . In practice, we only have access to the empirical estimate of the causal effect  $TE_{(\cdot)}$  denoted as  $\hat{T} E_{(\cdot)}$  and the regularization coefficient becomes  $\lambda_{(\cdot)} = 1 / |\hat{T} E_{(\cdot)}|$ . Now we are ready to state the main theoretical result that shows our regularization objective will learn the correct classifier which uses only the causal attribute for its prediction, given that the ranking of estimated treatment effect is correct up to some constant factor. Let  $[S]$  denote the set  $\{1, \dots, S\}$ .
Theorem 3.1. Let the latent space be frozen and disentangled such that  $\mathbf{z} = [z_{ca_1},\dots,z_{ca_K},z_{sp_1},\dots,z_{sp_J}]$  (Assm D.1). Let the desired classifier  $c^{des}(z) = \sum_{k=1}^{K}\mathbf{w}_{ca_k}^{des} \cdot \mathbf{z}_{ca_k}$  be the max-margin classifier among all linear classifiers that use only the causal features  $\mathbf{z}_{ca_k}$ 's for prediction. Let  $c^{mm}(z) = \sum_{k=1}^{K}\mathbf{w}_{ca_k}^{mm} \cdot \mathbf{z}_{ca_k} + \sum_{j=1}^{J}\mathbf{w}_{sp_j}^{mm} \cdot \mathbf{z}_{sp_j}$  be the max-margin classifier that uses both the causal and the spurious features, and let  $\mathbf{w}_{sp_j}^{mm} \neq \mathbf{0}, \forall j \in [J]$ . We assume  $\mathbf{w}_{sp_j}^{mm} \neq \mathbf{0}, \forall j \in [J]$ , without loss of generality because otherwise, we can restrict our attention only to those  $j \in [J]$  that have  $\mathbf{w}_{sp_j}^{mm} \neq \mathbf{0}$ . Let the norm of the parameters of both the classifier be set to 1 i.e.  $\sum_{k=1}^{K}\|\mathbf{w}_{ca_k}^{mm}\|_{p=2}^2 + \sum_{j=1}^{J}\|\mathbf{w}_{sp_j}^{mm}\|_{p=2}^2 = \sum_{k=1}^{K}\|\mathbf{w}_{ca_k}^{des}\|_{p=2}^2 = 1$ . Then if regularization coefficients are related s.t. mean  $\left(\left\{\frac{\lambda_{ca_k}}{\lambda_{sp_j}} \cdot \eta_{k,j}\right\}_{k \in [K], j \in [J]}\right) < \frac{J}{K}$  where  $\eta_{k,j} = \frac{\|\mathbf{w}_{ca_k}^{des}\| - \|\mathbf{w}_{ca_k}^{mm}\|_p}{\|\mathbf{w}_{sp_j}^{mm}\|_p}$ , then
1. Preference:  $\mathcal{L}_{AutoACER}(c^{des}(z)) < \mathcal{L}_{AutoACER}(c^{mm}(z))$ . Thus, our causal effect regularization objective (Def 3) will choose the  $c^{des}(z)$  classifier over the max-margin classifier  $c^{mm}(z)$  which uses the spuriously correlated feature.
2. Global Optimum: The desired classifier  $c^{des}(z)$  is the global optimum of our loss function  $\mathcal{L}_{AutoACER}$  when  $J = 1$ ,  $K = 1$ ,  $p = 2$ , the regularization strength are related s.t.  $\lambda_{ca_1} < \lambda_{sp_1} \Rightarrow |T\hat{E}_{ca_1}| > |T\hat{E}_{sp_1}|$  and search space of linear classifiers  $c(z)$  are restricted to have the norm of parameters equal to 1.
Remark. The result of Theorem 3.1 holds under a more intuitive but stricter constraint on the regularization coefficient  $\lambda$  which states that  $\lambda_{sp_j} > \left(\frac{K}{J}\eta_{k,j}\right)\lambda_{ca_k} \Rightarrow |\hat{T}E_{sp_j}| < \left(\frac{K}{J}\eta_{k,j}\right)|\hat{T}E_{ca_k}|$ $\forall k \in [K]$  and  $j \in [J]$ . The above constraint states that if the treatment effect of the causal feature is more than that of the spurious feature by a constant factor then the claims in Theorem 3.1 hold.
Proof Sketch. (1) We compare both the classifier  $c^{des}(z)$  and  $c^{mm}(z)$  using our overall training objective to our training objective  $\mathcal{L}_{AutoACER}$  (Eq. 1). Given the relation between the regularization strength mentioned in the above theorem is satisfied, we then show that one can always choose a regularization strength "R" greater than a constant value s.t classifier  $c^{mm}(z)$  incurs a greater
regularization penalty than  $c^{des}(z)$  (Eq. 3) which is not compensated by the gain in the max-margin objective of  $c^{mm}(z)$  over  $c^{des}(z)$ . Thus, the desired classifier  $c^{des}(z)$  has lower overall loss than the  $c^{mm}(z)$  in terms of our training objective  $\mathcal{L}_{AutoACER}$ . (2) We use the result from the first claim to show that  $c^{des}(z)$  has a lower loss than any other classifier that uses the spurious feature  $z_{sp1}$ . Then, among the classifier that only uses the causal feature  $z_{ca_1}$ , we show that again  $c^{des}(z)$  has the lower loss w.r.t.  $\mathcal{L}_{AutoACER}$ . Thus the desired classifier has a lower loss than all other classifiers w.r.t  $\mathcal{L}_{AutoACER}$  with parameter norm 1 hence a global optimum. Refer §D for proof.
4 Empirical Results
Theorem 3.1 showed that our method can find the desired classifier in a simple linear setup. We now evaluate the method on a synthetic, semi-synthetic and real-world dataset. Details are in §E.
Syn-Text. We introduce a synthetic dataset where the ground truth causal graph is known and thus the ground truth spuriously correlated feature is known apriori (but unknown to all the methods). The dataset contains two random variables (causal and confound) that cause the binary main task label  $y_{m}$  and the variable spurious is spuriously correlated with the confound variable. Given the values of spurious and causal features, we create a sentence as input. We define Syn-Text-Obs-Conf-- a version of the Syn-Text dataset where all three variables/attributes are observed. Next, to increase difficulty, we create a version of this dataset — Syn-Text-Unobs-Conf— where the confound attribute is not observed in the training dataset, corresponding to DGP-3 from Fig. 2.
MNIST34. We use MNIST [20] to compare our method on a similar semi-synthetic dataset as used in Mouli and Ribeiro [25]. We define a new task over this dataset but use the same attributes, color, rotation, and digit, whose associated transformation satisfies the lumpability assumption in their work. We define the digit attribute (3 and 4) and the color attribute (red or green color of digit) as the causal attributes which creates the binary main task label using the  $XOR$  operation. Then we add rotation  $(0^{\circ}$  or  $90^{\circ})$  to introduce spurious correlation with the main task label. This dataset corresponds to DGP-2, where  $C$  is color and digit attribute,  $S$  is rotation attribute and  $x$  is an empty set.
Twitter-AAE [4]. This is a real-world dataset where the main task is to predict a binary sentiment label from a tweet's text. The tweets are associated with race of the author which is spuriously correlated with the main task label. Since this is a real-world dataset where we have not artificially introduced the spurious attribute we don't have a ground truth causal effect of race on the sentiment label. But we expect it to be zero since changing race of a person should not change the sentiment of the tweet. We use GPT3 [5] to create the counterfactual example by prompting it to change the race-specific information in the given sentence (see §F for examples). This dataset corresponds to DGP-1, where the node  $A$  is the spurious attribute race.
Varying spurious correlation in the dataset. Since the goal is to train a model that doesn't rely on the spuriously correlated attribute, we create multiple settings for every dataset with different levels of correlations between the main task labels  $y_{m}$  and spurious attribute  $y_{c_{sp}}$ . Following [19], we use a predictive correlation metric to define the label-attribute correlation that we vary in our experiments. The predictive correlation  $(\kappa)$  measures how informative one label or attribute  $(s)$  is for predicting the other  $(t)$ ,  $\kappa := Pr(s = t) = \sum_{i=1}^{N} \mathbf{1}[s = t] / N$ , where  $N$  is the size of the dataset and  $\mathbf{1}[\cdot]$  is the indicator function that is 1 if the argument is true otherwise 0. Without loss of generality, assuming  $s = 1$  is correlated with  $t = 1$  and similarly,  $s = 0$  is correlated with  $t = 0$ ; predictive correlation lies in  $\kappa \in [0.5, 1]$  where  $\kappa = 0.5$  indicates no correlation and  $\kappa = 1$  indicates that the attributes are fully correlated. For Syn-Text dataset, we vary the predictive correlation between the confound attribute and the spurious attribute; for MNIST34, between the combined causal attribute (digit and color) and the spurious attribute (rotation); and for Twitter-AAE, between the task label and the spurious attribute (race). See §E for details.
4.2 Baselines and evaluation metrics
Baselines. We compare our method with five baseline algorithms: (i)  $ERM$ : Base algorithm for training the main task classifier using cross-entropy loss without any additional regularization. (ii)  $Mouli + CAD$ : The method proposed in [25] to automatically detect the spurious attributes and
(a) Syn-Text-Unobs-Conf dataset
(b) MNIST34 dataset
Figure 3: Detecting spurious attribute using Mouli+CAD: x-axis is the predictive correlation and y-axis shows the score defined by Mouli+CAD. The orange curve shows the score for true spurious attribute. The blue curve shows the score for setting when Mouli+CAD considers none of the given attributes as spurious. The attribute with the lowest score is selected as spurious. If the blue curve has the lowest score for a dataset with predictive correlations  $(\kappa)$ , Mouli+CAD will not declare any attributes as spurious for that  $\kappa$ . (a) and (b). Mouli+CAD fails to detect the spurious attribute at high  $\kappa$ . (c) Mouli+CAD correctly identifies the race attribute as spurious.
(c) Twitter-AAE dataset
train a model invariant to those attributes. Given a set of attributes, this method computes a score for every subset of attributes, selects the subset with a minimum score as the spurious subset, and finally enforces invariance with respect to those subsets using counterfactual data augmentation (CAD) [32, 16]. (iii) Mouli+AutoACER: Empirically, we observe that CAD does not correctly impose invariance for a given attribute (see §F for discussion). Thus we add a variant of Mouli+CAD's method where instead of using CAD it uses our regularization objective (Eq. 2) to impose invariance using the causal effect  $TE_{a} = 0$  for some attribute "a". (iv) Just Train Twice [21] (JTT): Given a known spurious attribute, JTT aims to train a model that performs well on all subgroups of the dataset, where subgroups are defined based on different correlations between the task label and spurious attribute. Unlike methods like GroupDRO [30], JTT requires (expensive) subgroup labels only for the examples in the validation set. (v) Invariant Risk Minimization [2] (IRM): This method requires access to multiple environments or subsets of the dataset where the correlation between the spurious attribute and task label changes and then it trains a classifier that only uses the attributes with stable correlations across environments (see E for experimental setup).
Metrics. We use two metrics for evaluation. Since all datasets have binary task labels and attributes, we define a group-based metric (average group accuracy) to measure generalization under distribution shift. Specifically, given binary task label  $y \in \{0,1\}$  and spurious attribute  $a \in \{0,1\}$ . Following Kumar et al. [19] we define  $2 \times 2$  groups, one for each combination of  $(y,a)$ . The subset of the dataset with  $(y = 1,a = 1)$  and  $(y = 0,a = 0)$  are the majority group  $S_{maj}$  while groups  $(y = 1,a = 0)$  and  $(y = 0,a = 1)$  make up the minority group  $S_{min}$ . We expect the main classifier to exploit this correlation and hence perform better on  $S_{maj}$  but badly on  $S_{min}$  where the correlation breaks. Thus we want a method that performs better on the average accuracy on both the groups i.e  $\frac{Acc(S_{min}) + Acc(S_{maj})}{2}$ , where  $Acc(S_{maj})$  and  $Acc(S_{min})$  are the accuracy on majority and minority group respectively. The second metric (ΔProb) measures the reliance of a classifier on the spurious feature. For every given input  $x_a$  we have access to the counterfactual distribution  $(\pmb{x}_{a'}) \sim \mathcal{Q}(\pmb{x}_a)$  (\$2) where the attribute  $A = a$  is changed to  $A = a'$ . ΔProb is defined as the change in the prediction probability of the model on changing the spurious attribute  $a$  in the input, thus directly measuring the reliance of the model on the spurious attribute. For background on baselines refer §A a detailed description of our experiment setup refer §E.
4.3 Evaluating Stage 1: Automatic Detection of Spurious Attributes
Failure of Mouli+CAD in detecting the spurious attributes at high correlation. In Fig. 3, we test the effectiveness of Mouli+CAD to detect the subset of attributes which are spurious on different datasets with varying levels of spurious correlation  $(\kappa)$ . In Syn-Text dataset, at low correlations  $(\kappa < 0.8)$  Mouli+CAD correctly detects spurious attribute (orange line is lower than blue). As the correlation increases, their method incorrectly states that there is no spurious attribute (blue line lower than orange). In MNIST34 dataset, Mouli+CAD does not detect any attributes as spurious (shown by blue line for all  $\kappa$ ). For Twitter-AAE dataset, Mouli+CAD's method is correctly able to detect the spuriously correlated attribute (race) for all the values of predictive correlation, perhaps because the spurious correlation is weak compared to the causal relationship from causal features to task label.
Table 1: Causal Effect Estimate of spurious attribute. Direct and Riesz are two different causal effect estimators as described in §3.2. Overall we see that Riesz performs better or comparable to the baseline Direct and closer to ground truth value 0. Since Twitter-AAE is a real dataset we don't have a ground causal effect of race attribute but we expect it to be zero (see §4.1).
Dataset	True	Method	Predictive Correlation (κ)
0.5	0.6	0.7	0.8	0.9	0.99
Syn-Text-Obs-Conf	0	Direct	0.00	0.00	0.01	0.08	0.16	0.22
Riesz	0.00	0.03	0.03	0.03	0.05	0.15
Syn-Text-Unobs-Conf	0	Direct	-0.01	0.13	0.24	0.37	0.49	0.67
Riesz	0.06	0.19	0.31	0.42	0.58	0.70
MNIST34	0	Direct	0.02	0.03	0.05	0.06	0.15	0.27
Riesz	-0.01	0.06	0.05	0.04	0.2	0.31
Twitter-AAE	-	Direct	0.01	0.07	0.12	0.20	0.27	0.31
Riesz	0.02	0.07	0.12	0.17	0.27	0.37
(a) Syn-Text-Unobs-Conf
(b) MNIST34
(c) Twitter-AAE
Figure 4: Average group accuracy (top row) and  $\Delta$  Prob (bottom row) for different methods. x-axis denotes predictive correlation  $(\kappa)$  in the dataset. Compared to other baselines, (a) and (b) show that AutoACER performs better or comparable in average group accuracy and trains a classifier significantly less reliant to spurious attribute as measured by  $\Delta$  Prob. In (a), IRM has lower  $\Delta$  Prob as compared to other methods but performs worse on average group accuracy. Mouli+CAD performs better in average group accuracy in (c) but relies heavily on spurious attribute shown by high  $\Delta$  Prob whereas AutoACER performs equivalent to all other baselines on average group accuracy with lowest  $\Delta$  Prob among all.
AutoACER is robust to error in the estimation of spurious attributes. Unlike Mouli+CAD's method that does a hard categorization, AutoACER estimates the causal effect of every attribute on the task label as a fine-grained measure of whether an attribute is spurious or not. Table 1 summarizes the estimated treatment effect of spurious attributes in every dataset for different levels of predictive correlation  $(\kappa)$ . We use two different causal effect estimators named Direct and Riesz with the best estimate selected using validation loss (see §E). Overall, the Riesz estimator gives a better or comparable estimate of the causal effect of spurious attribute than Direct, except in the Syn-Text-Unobs-Conf dataset where the causal effect is not identified. At high predictive correlation  $(> = 0.9)$ , as expected, the causal effect estimates are incorrect. But as we will show next, since AutoACER uses a continuous effect value to detect the spurious attribute, it allows for errors in the first (detection) step to not affect later steps severely.
4.4 Evaluating Stage 2: Evaluation of AutoACER and other baselines
Fig. 4 compares the efficacy of our method with other baselines in removing the model's reliance on spurious attributes. On Syn-Text-Unobs-Conf dataset, our method (AutoACER) performs better than all the other baselines for all levels of predictive correlation  $(\kappa)$  on average group accuracy
(first row in Fig. 4a). In addition,  $\Delta$  Prob (the sensitivity of model on changing spurious attribute in input, see 4.1) for our method is the lowest compared to other baselines (see bottom row of Fig. 4a). For  $\kappa \geq 0.8$ , Mouli+CAD is the same as ERM since it fails to detect the spurious attribute and thus doesn't impose invariance w.r.t the spurious attribute. (Fig. 3a for details). On MNIST34 dataset, the average group accuracy of all methods is comparable (except JTT that performs worse), but AutoACER has a substantially lower  $\Delta$  Prob than baselines for all values of  $\kappa$ . Again, the main reason why Mouli+CAD fails is that it is not able to detect the spurious attribute for all  $\kappa$  and thus doesn't impose invariance w.r.t them (see Fig. 3b and §4.3). On Twitter-AAE dataset, Mouli+CAD correctly detects the race attribute as spurious and performs better in terms of Average Group Accuracy compared to all other baselines. But if we look at  $\Delta$  Prob, the gain in accuracy is not because of better invariance: in fact, the reliance on the spurious attribute (race) is worse than ERM. In contrast, AutoACER has lowest  $\Delta$  Prob among all while obtaining comparable accuracy to ERM, JTT and IRM. To summarize, in all datasets, AutoACER ensures a higher or comparable accuracy to ERM while yielding the lowest  $\Delta$  Prob. Note that AutoACER does not require knowledge of the spurious attribute whereas JTT and IRM do; hence we selected the best model using overall accuracy on the validation set for all the methods (see Eq. 33). For a fair comparison to JTT and IRM, in §F.2 (Fig. 7) we show results under the setting where all the methods (including AutoACER) assume that the spurious attribute is known. Even with access to this additional information, we observe a similar trend as in Fig. 4. AutoACER performs equivalent to all other baselines on average group accuracy with the lowest  $\Delta$  Prob among all. Finally, in §F we provide an in-depth analysis of our results, provide recommendations for selecting among different causal effect estimators used by our method (§F.1) and evaluate AutoACER and other baselines on an additional dataset —Civil-Comments [18]—a popular dataset for studying generalization under spurious correlation (§F.2).
Known spurious attributes. When the spuriously correlated attributes are known a priori, three major types of methods have been proposed, based on worst-group optimization [30], conditional independence constraints [35, 15, 22], or data augmentation [16, 17]. Methods like GroupDRO [30] create multiple groups in the training dataset based on the spurious attribute and optimize for worst group accuracy. To reduce labelling effort for the spurious attribute, methods like JTT [21] and EIIL [7] improve upon GroupDRO by requiring the spurious attribute labels only on the validation set. Other methods assume knowledge of causal graphs and impose conditional independence constraints for removing spurious attributes [35, 15, 22]. Methods based on data augmentation add counterfactual training data where only the spurious attribute is changed (and label remains the same) [16, 14, 17].
Automatically discovering spurious attributes. The problem becomes harder if spurious attributes are not known. Mouli and Ribeiro's work [24, 25] provides a method assuming specific kinds of transformations on the spurious attributes, either transformations that form finite linear automorphism groups [24] or symmetry transformations over equivalence classes [25]. Any attribute changed via the corresponding transformation that does not hurt the training accuracy is considered spurious. However, they do not consider settings with correlation between the transformed attributes and the task labels. Our work considers a more realistic setup where we don't impose any constraint on the transformation or the attribute values, and allows attributes to be correlated with the task label (at different strengths). Using conditional independencies derived from a causal graph, Zheng and Makar [38] propose a method to automatically discover the spurious attributes under the anti-causal classification setting. Our work, considering the causal classification setting (features cause label) complements their work and allows soft regularization proportional to the causal effect.
We presented a method for automatically detecting and removing spurious correlations while training a classifier. While we focused on spurious attributes, estimation of causal effects can be used to regularize the effect of non-spurious features too. That said, our work has limitations: we can guarantee the identification of causal effects only in certain DGPs. In future work, it will be useful to characterize the datasets on which our method is likely to work and where it fails. Another limitation is that our method is not guaranteed to work on datasets with an anti-causal data-generating process, wherein the observed input  $x$  and other attributes are generated from the task label  $y$ .
[37] Tongshuang Wu, Marco Tulio Ribeiro, Jeffrey Heer, and Daniel Weld. Polyjuice: Generating counterfactuals for explaining, evaluating, and improving models. In Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 1: Long Papers), pages 6707-6723, Online, August 2021. Association for Computational Linguistics. doi:10.18653/v1/2021.acl-long.523. URL https://aclanthology.org/2021.acl-long.523.
[38] Jiayun Zheng and Maggie Makar. Causally motivated multi-shortcut identification and removal. In S. Koyejo, S. Mohamed, A. Agarwal, D. Belgrave, K. Cho, and A. Oh, editors, Advances in Neural Information Processing Systems, volume 35, pages 12800-12812. Curran Associates, Inc., 2022. URL https://proceedings.neurips.cc/paper_files/paper/2022/file/536d643875321d6c3282ee8c7ea5eb6a-Paper-Conference.pdf.
[39] Yuchen Zhu, Limor Gultchin, Arthur Gretton, Matt J. Kusner, and Ricardo Silva. Causal inference with treatment measurement error: a nonparametric instrumental variable approach. In James Cussens and Kun Zhang, editors, Proceedings of the Thirty-Eighth Conference on Uncertainty in Artificial Intelligence, volume 180 of Proceedings of Machine Learning Research, pages 2414-2424. PMLR, 01-05 Aug 2022. URL https://proceedings.mlr.press/v180/zhu22a.html.
A.1 Causal Effect Estimation and RieszNet Estimator
Let  $(X,Y,A)$  denote a random input point from the data distribution, where  $A$  is the auxiliary attribute label and  $X$  is the input covariate and  $Y$  is the task label. Assuming binary  $A$ , the average causal effect (or equivalently called as average treatment effect) of attribute  $A$  on the task label  $Y$  is defined as (Chapter 3 in Pearl [27]):
$$
T E _ {A} = \mathbb {E} [ Y | d o (A) = 1 ] - \mathbb {E} [ Y | d o (A) = 0 ] \tag {4}
$$
Given  $X$  satisfies sufficient backdoor adjustment the causal effect can be estimated using (see Chapter 3 in Pearl [27] for details):
$$
D i r e c t := T E _ {A} = \mathbb {E} _ {X} \left[ \mathbb {E} [ Y | X, A = 1 ] - \mathbb {E} [ Y | X, A = 0 ] \right] \tag {5}
$$