SlowGuess/NeurIPS_2023_OCR huggingface dataset:
the feature number. Let  $c^s(\boldsymbol{z}) = \boldsymbol{w}_{ca}^s \cdot \boldsymbol{z}_{ca} + \boldsymbol{w}_{sp}^s \cdot \boldsymbol{z}_{sp}$  be any classifier which uses spurious feature  $\boldsymbol{z}_{sp}$  for its prediction s.t.  $\boldsymbol{w}_{sp}^s \neq 0$ . From statement 1 of this theorem, when the regularization strength are related such that  $\lambda_{ca} \cdot \eta < \lambda_{sp}$ , we have  $\mathcal{L}_{AutoACER}(c^{des}(\boldsymbol{z})) < \mathcal{L}_{AutoACER}(c^s(\boldsymbol{z}))$  where  $\eta = \frac{\|\boldsymbol{w}_{ca}^{des}\|_2 - \|\boldsymbol{w}_{ca}^s\|_2}{\|\boldsymbol{w}_{sp}^s\|_2}$ . Since the search space of the linear classifiers is constrained to have the norm of parameters equal to 1 we have  $\| \boldsymbol{w}_{ca}^s\|_2^2 + \| \boldsymbol{w}_{sp}^s\|_2^2 = 1$  and  $\| \boldsymbol{w}_{ca}^{des}\|_2 = 1$ . Let  $\| \boldsymbol{w}_{ca}^s\| = \theta \in [0,1)$ , then we have  $\| \boldsymbol{w}_{sp}^s\| = \sqrt{1 - \theta^2}$ . Substituting these values in  $\eta$  we get:
$$
\begin{array}{l} \eta (\theta) = \frac {1 - \theta}{\sqrt {1 - \theta^ {2}}} \tag {28} \\ = \sqrt {\frac {1 - \theta}{1 + \theta}} \quad (\theta \neq 1) \\ \end{array}
$$
Thus  $\eta(\theta)$  is a decreasing function for  $\theta \in [0,1)$  and has its maximum value  $\eta_{\max} = 1$  at  $\theta = 0$ . Thus, if the regularization strengths are related such that  $\lambda_{ca} \cdot \eta_{\max} < \lambda_{sp} \Rightarrow \lambda_{ca} < \lambda_{sp}$  we have  $\mathcal{L}_{AutoACER}(c^{des}(z)) < \mathcal{L}_{AutoACER}(c^s (z))$  for all possible  $c^s (z)$ . Since we are given that  $\lambda_{ca} < \lambda_{sp}$  in the second statement of the theorem  $c^{des}(z)$  is preferred by our regularization objective among all possible  $c^s (z)$ . Next, among the classifier  $c^{\psi}(z) \neq c^{des}(z)$  which only uses the causal feature for prediction, we have:
$$
\mathcal {L} _ {\text {A u t o A C E R}} \left(c ^ {d e s} (\boldsymbol {z})\right) = \mathcal {L} _ {m m} \left(c ^ {d e s} (\boldsymbol {z})\right) + R \cdot \left\{\lambda_ {c a} \| \boldsymbol {w} _ {c a} ^ {d e s} \| _ {2} \right\} = \mathcal {L} _ {m m} \left(c ^ {d e s} (\boldsymbol {z})\right) + R \lambda_ {c a} \cdot 1 \tag {29}
$$
$$
\mathcal {L} _ {\text {A u t o A C E R}} \left(c ^ {\psi} (\boldsymbol {z})\right) = \mathcal {L} _ {m m} \left(c ^ {\psi} (\boldsymbol {z})\right) + R \cdot \left\{\lambda_ {c a} \| \boldsymbol {w} _ {c a} ^ {\psi} \| _ {2} \right\} = \mathcal {L} _ {m m} \left(c ^ {\psi} (\boldsymbol {z})\right) + R \lambda_ {c a} \cdot 1 \tag {30}
$$
Since the desired classifier has maximum margin when using only causal feature for prediction (by definition), we have  $\mathcal{L}_{mm}(c^{des}(\pmb {z})) < \mathcal{L}_{mm}(c^{\psi}(\pmb {z}))$  for all other classifiers  $(c^{\psi}(\pmb {z}))$  which only uses the causal feature for prediction. Thus the desired classifier is the global optimum for our loss function  $\mathcal{L}_{AutoACER}$  when the classifiers are constrained to have parameters with a norm equal to 1 thereby completing the proof.
We perform extensive experiments on 6 datasets spanning synthetic, semi-synthetic, and real-world datasets. In §4 we give results for 3 such datasets — Syn-Text which is a synthetic dataset, MNIST34 which is a semi-synthetic dataset and Twitter-AAE which is a real-world dataset. In §F, we further evaluate our methods and other baselines on one additional real-world dataset (Civil-Comments) which has three different subsets. Below we give a detailed description of all the datasets.
Syn-Text Dataset. To create this Syn-Text dataset we first create a tabular dataset with three binary attributes—causal, spurious and confound. The causal and confound attribute create the task label  $(Y)$  and the confound attribute creates the spurious attribute. Causal and confound attributes are independent,  $P(\text{causal} = 0) = P(\text{causal} = 1) = 0.5$  and  $P(\text{confound} = 0) = P(\text{confound} = 1) =$
Table 3: World List corresponding to every Attribute for Syn-Text dataset. Every value of a given attribute is associated with the following list of words. For creating a sentence we take the values of every attribute, randomly sample 3 words from the corresponding set, and concatenate them to form the final sentence i.e. sentence = [causal words, confound words, spurious words].
Attribute	Value	Word List
Causal	0	apple, mango, tomato, cherry, pear, fruit, banana, pear, grapes
1	rose, jasmine, tulip, lotus, daisy, sunflower, flower, marigold, dahlia, orchid
Confound	0	bad, inferior, substandard, inadequate, rotten, pathetic, faulty, defective,
1	good, best, awesome, teriffic, mighty, gigantic, tremendous, mega, colossal,
Spurious	0	horror, gore, crime, thriller, mystery, gangster, drama, dark
1	comedy, romance, fantasy, sports, epic, animated, adventure, science
Table 4: Automatically generated counterfactual example using GPT3.5 for Twitter-AAE dataset.
Input Race	Input Sentence	Generated Counterfactual
white	hey guess where i just ate at ? cracker barrel . they had plenty of mashed potatoes . just thought i'd let you know . twitter-entity	Hey, guess where I jus' ate at? Cracker Barrel! Dey had plenty o' mashed potatoes. Jus' thought I'd letchu know. #CrackerBarrelCravings
white	girl don't sit there and listen to him talk about lacrosse when we all know you have no clue what he is saying	Girl, don't siddity there listenin' to him talkin' 'bout lacrosse when we all know you ain't got no clue 'bout what he sayin'.
black	we don't wanna neva end	We don't want it to ever end.
black	i wonder if reggie evan still thnk blatche and joe johnson on the same level as lebron	I wonder if Reggie Evans still regard Blatche and Joe Johnson at the same level as LeBron.
0.5. The conditional probability distribution (CPD) of the task label given to the parents is given in Table 2. The CPD for spurious attribute is not fixed i.e  $P(\text{spurious} \mid \text{confound}) = \kappa$ , which we vary in our experiment to change the overall predictive correlation of spurious attribute with the task label. We then create two versions of this dataset (1) Syn-Text-Obs-Conf and (2) Syn-Text-Unobs-Conf. In the Syn-Text-Obs-Conf dataset, we keep all the attributes in the dataset but for Syn-Text-Obs-Conf to simulate the real-world setting where there is an unobserved confounding variable we remove the confound attribute from the dataset. Post this, we use this tabular dataset to generate textual sentences for every example. For each of the values of (observed) attributes, we sample 3 words from a fixed set of words (separate for each value of attribute) that we append together to form the final sentence (see Table 3 for the set of words corresponding to every attribute). The Syn-Text-Unobs-Conf dataset corresponds to the DGP-3 in the Fig. 2 where the unobserved node  $U$  is the confound attribute and  $A$  is the spurious attribute and there is no edge between  $A$  and task label  $Y$ . In our experiment, we sample 1k examples using the above methods and create an 80-20 split for the train and test set. Note that the predictive correlation mentioned in experiments and other tables for all versions of Syn-Text dataset is between the confound and spurious attribute given by  $\kappa = P(\text{spurious} \mid \text{confound})$ . Our experiments require access to the counterfactual example  $x_{a'} \sim \mathcal{Q}(x_a)$  where the attribute  $A = a$  is changed to  $A = a'$  in the input. To generate this counterfactual example we flip the value of
Table 5: Words associated with different attributes in Civil-Comments dataset.
Attribute	Associated Word List
Race	black, white, supremacists, obama, clinton, trump, john, negro, blacks, whites, nigga
Gender	male, patriarchy, feminist, woman, men, man, female, women, he, she, him, his, mother, father, feminists, boy, girl
Religion	christian, muslim,allah, jesus, john, mohammed, catholic, priest, church, islam, islam, hijab
the attribute in the given input and generate the corresponding sentence using the same procedure mentioned above.
MNIST34 Dataset. We use the MNIST to evaluate the efficacy of our method on the vision dataset. Following Mouli and Ribeiro [25], we subsample only the digits 3 (digit attribute label=0) and 4 (digit attribute label=1) from this dataset and create a synthetic task. To create this dataset, we first take a grayscale image (with digit attribute either 3 or 4). Then we add background color — red labeled as 1 or green labeled as 0 — to the image uniformly randomly i.e.  $P(\text{color|digit}) = 0.5$ . We create the task label using a deterministic function over the digit and color attribute formally defined as  $Y =$  color XOR digit where XOR is the exclusive OR operator. Thus the attribute, digit, and color are causal attributes for this dataset. Next, to introduce spurious correlation we add rotation transformation to the image —  $0^\circ$  labeled as 1 or  $90^\circ$  labelled as 0. We vary the correlation between the causal attributes (color and digit) and spurious attribute (rotation) by varying the CPD  $P(\text{rotation|color, digit})$ . Since the combined causal attribute label is the same as the task label the predictive correlation between the task label and spurious attribute is given by  $\kappa = P(\text{rotation|color, digit})$  which is vary in all our experiments. The above data-generating process resembles DGP-2 in the Fig. 2 where the node  $C$  is the combined causal attributes (color and digit) and the node  $S$  is the spurious attribute (rotation). The core input feature  $x$  is an empty set in this dataset. All the attributes combinedly create the final input image  $X$ . We sample 10k examples using the above process described above and create an 80-20 split for the train and test set. Our experiments require access to the counterfactual example  $x_{a'} \sim \mathcal{Q}(x_a)$  where the attribute  $A = a$  is changed to  $A = a'$  in the input. To generate this counterfactual example we flip the value of the relevant attribute the attribute label and generate the counterfactual image.
Twitter-AAE Dataset. This is a real-world dataset where given a sentence the task is to predict the sentiment of the sentence. Following Elazar and Goldberg [9], Kumar et al. [19], we simplify the task to predict the binary sentiment (Positive or Negative) given the tweet. Every tweet is also associated with the demographic attribute "race" which is correlated with the task label in the dataset. Following Elazar and Goldberg [9], Kumar et al. [19] and considering that changing the race of the person in the tweet should not affect the sentiment, we consider race as the spurious attribute. We use the code made available by Elazar and Goldberg [9] to automatically label the tweet with the race that uses AAE (African-American English) and SAE (Standard American English) as a proxy for race. This data-generating process of this dataset resembles DGP-1 in Fig. 2 since the sentiment (task) labels are annotated using a deterministic function given the input tweet ([9]). The dataset  $^{1}$  and code  $^{2}$  to create the dataset are available online. We subsample 10k examples and use an 80-20 split for the train and test set. See §E.2 for details on how we vary the predictive correlation in this dataset between the task labels and spurious attribute in our experiment. Our experiments require access to the counterfactual example  $x_{a'} \sim \mathcal{Q}(x_a)$  where the attribute  $A = a$  is changed to  $A = a'$  in the input. Since this is a real-world dataset where we don't have access to the data-generating process. Thus we take help from GPT3.5 (text-davinci-003 model) [5] to automatically generate the counterfactual tweet where the race attribute is changed. See Table 4 for a sample of generated counterfactual tweets.
Civil-Comments Datasets. To further evaluate our result on another real-world dataset we conduct use another dataset Civil-Comments<sup>3</sup> (WILDS dataset, [18]). Given a sentence, the task is to predict the toxicity of the sentence which is a continuous value in the original dataset. In our experiment,
TwitterAAE dataset could be found online at: http://slanglab.cs.umass.edu/TwitterAAE/
2The code for Twitter-AAE dataset acquisition and automatically labeling race information is available at: https://github.com/yanaiela/demog-text-removal
Civil Comments dataset is available online at https://www.tensorflow.org/datasets/catalog/civil/comments
we binarize this task to predict whether the sentence is toxic or not by labeling the sentence with toxicity score  $\geq 0.5$  as toxic or otherwise non-toxic. We use a subset of the original dataset (CivilCommentsIdentities) which includes an extended set of auxiliary identity labels associated with the sentence. We finally select three different identity labels (race, gender, and religion). Race attribute takes two values black or white, Gender attribute takes two values male or female, and Religion attribute also takes two values muslim or christian. We expect that these identity attributes to have zero causal effect on the task label since changing a person's race, gender, or religion in the sentence should not change the toxicity of the sentence. For each considered identity label, we create a corresponding different subset of the dataset named Civil-Comments (Race), Civil-Comments (Gender), and Civil-Comments (Religion). This data-generating process of this dataset also follows DGP-1 since toxicity (task) labels were generated from human annotators. We subsample  $5\mathrm{k}$  examples for Civil-Comments (Race) and Civil-Comments (Gender) and  $4\mathrm{k}$  examples to create Civil-Comments (Religion) dataset that we use in our experiments. Then, we use an 80-20 split to create a train and test set. For details on how we vary the predictive correlation see §E.2. In our experiment, for every input  $x$  we need access to the counterfactual where the attribute's value is changed in the input. To create such counterfactuals we use a deterministic function that removes the words related to the attribute from the sentence. Currently, we use a hand-crafted set of words for each of the attributes for removal, we plan to replace that more natural counterfactual generated from generative models like GPT3. Table 5 show the set of words associated with every attribute that we use for removal.
E.2 Dataset with varying levels of spurious Correlation.
We create multiple subsets of the dataset with different levels of predictive correlation  $(\kappa)$  between the task label  $(y)$  and the attribute  $(a)$ . The task label and all the attributes we consider in our work are binary taking values from 0 and 1. Following Kumar et al. [19], we define 4 subgroups in the dataset for each combination of  $(y, a)$ . The subset of the dataset with  $(y = 1, a = 1)$  and  $(y = 0, a = 0)$  is defined as majority group  $S_{maj}$  where the task labels  $y$  are correlated with the attribute. The remaining subset of the dataset where the correlation break is named  $S_{min}$  which contains the dataset with  $(y = 1, a = 0)$  and  $(y = 0, a = 1)$ . Next, we artificially vary the correlation between the attribute and the task label by varying  $\kappa = Pr(y = a)$  i.e. the number of examples with the same task label and attribute. Following Kumar et al. [19], we can reformulate  $\kappa$  in terms of the size of the majority and minority groups:
$$
\kappa := \frac {\left| S _ {m a j} \right|}{\left| S _ {m a j} \right| + \left| S _ {m i n} \right|} \tag {31}
$$
For both Twitter-AAE and Civil-Comments dataset, we consider 6 different settings of  $\kappa$  from the set  $\{0.5, 0.6, 0.7, 0.8, 0.9, 0.99\}$  by artificially varying the size of  $S_{maj}$  and  $S_{min}$ . To do so, we keep the size of  $S_{maj}$  fixed, and then based on the desired value of  $\kappa$  we determine the number of samples to take in  $S_{min}$  using the above equation. Thus for different values of  $\kappa$  the overall training dataset size  $(|S_{maj}| + |S_{min}|)$  changes in Twitter-AAE and Civil-Comments datasets. Thus it is important to only draw an independent conclusion from the different settings of  $\kappa$  in these datasets.
E.3 Encoder for the different datasets.
We give the details of how we encode different types of inputs to feed to the neural network in our experiment. For specific details of the rest of the architecture see the individual setup for every method in §E.4, E.5 and E.6.
Syn-Text Dataset. We tokenize the sentence into a list of words and use 100-dimensional pretrained GloVe word embedding [28] to get a vector representation for each word. Next, to get the final representation of a sentence we take the average of all the word embedding in the sentence. The word embedding is fixed and not trained with the model. Post this we add an additional trainable fully connected layer (with output dimension 50) without any activation to get the final representation for the sentence used by different methods with different loss objectives (see §E.4, E.5 and E.6).
MNIST34 Dataset. We directly take the image as input and normalize it by dividing it with a scalar 255. Post this we use a convolutional neural network for further processing the image. Specifically, we apply the following layers in sequence to get the final representation of the image.
1. 2D convolution layer, activation = relu, filter size = (3,3), channels = 32
2. 2D max pooling layer, with filter size (2,2)
3. 2D convolution layer, activation = relu, filter size = (3,3), channels = 64
4. 2D max pooling layer, with filter size (2,2)
5. 2D convolution layer, activation = relu, filter size = (3,3), channels = 128
Next, we flatten the output of the above last layer to get the final representation of the image used by different methods with different loss objectives (see §E.4, E.5 and E.6).
Twitter-AAE and Civil-Comments Datasets. We use Hugging Face [36] transformer implementation of BERT [8] bert-base-uncased model to encode the input sentence. We use the pooled output of the [CLS] token as the encoded representation of the input for further processing by other methods (see §E.4, E.5 and E.6). We start with the pretrained weight and fine-tune the model based on the specific task.
E.4 Setup: Causal Effect Estimators
We use two different causal effect estimators — Direct (Eq. 5) and Riesz (Eq. 8) — to estimate the causal effect of a attribute on the task label  $Y$  (see §A.1 for details of the individual estimators).
Direct estimator in practice. For Direct estimator we use a neural network to estimate  $\mathbb{E}[Y|X,A]$ . To get the causal effect we select the best model based either based on validation loss or validation accuracy in the prediction of the task label  $Y$  given  $(X,A)$ . We refer to these two versions of Direct estimators as Direct(loss) and Direct(acc) for the setting when validation loss and validation accuracy are used for selection respectively. To estimate  $\mathbb{E}[Y|X,A]$  we use the following loss objective:
$$
\left[ Y - g (X, A) \right] ^ {2} + R \cdot \mathrm {L 2 l o s s} \tag {32}
$$
where  $g(X, A)$  is the neural network predicting the task label  $Y$  given input  $(X, A)$ , L2loss is the L2 regularization loss and  $R$  is the regularization strength hyperparameter. For Syn-Text dataset, we don't apply L2loss, for MNIST34 dataset we do a hyperparameter search over  $R \in \{0.0, 0.1, 1.0, 10.0, 100.0, 200.0, 1000.0\}$ , for Twitter-AAE we use  $R \in \{0.0, 10.0, 100.0, 1000.0\}$  and Civil-Comments dataset we use  $R \in \{0.0, 1.0, 10.0, 100.0, 200.0, 1000.0\}$ .
Riesz estimator in practice. To get the causal effect from Riesz we optimize the loss function defined in Eq. 8. We fix the regularization hyperparameter  $R_{1}$  for RRloss to a fixed value 1 in all the experiments and search over the L2loss regularization hyperparameter  $(R_{2})$ . For Syn-Text dataset, we don't use the L2loss at all, for MNIST34 dataset we search over  $R_{2} \in \{0.0, 0.1, 1.0, 10.0, 100.0, 200.0, 1000.0\}$ , for Twitter-AAE dataset we use  $R_{2} \in \{0.0, 10.0, 100.0, 200.0, 1000.0\}$  and for Civil-Comments dataset we use  $R_{2} \in \{0.0, 1.0, 10.0, 100.0, 200.0, 1000.0\}$ . Then similar to Direct estimator, for selecting the best model for estimating the causal effect we use validation loss and validation accuracy of  $g(X, A)$  for predicting the task label  $Y$  using input  $(X, A)$ . We call the estimators Riesz(loss) and Riesz(acc) based on this selection criteria.
For both the estimator we train the model for 200 epochs/iterations in Syn-Text dataset and 20 epochs for the rest of the datasets and use either validation loss or validation accuracy to select the best training epoch (as described above).
E.5 Setup: AutoACER
We use the regularization objective defined in Eq. 1 and 2 to train the classifier using our method AutoACER. For each dataset, first, we encode the inputs to get a vector representation using the procedure described in §E.3. We use cross-entropy objectives to train the task prediction  $(\mathcal{L}_{task})$ . Next, we take the causal effect estimated from Stage 1 and map it to the closest value in set  $\{-1.0, -0.5, -0.1, 0.0, 0.1, 0.3, 0.5, 1.0\}$ . For Syn-Text and MNIST34 dataset we map the estimated treatment effect from Stage 1 to the closest value in set  $\{-1.0, -0.7, -0.5, -0.3, -0.1, 0.0, 0.1, 0.3, 0.5, 0.7, 1.0\}$ . The mapped causal effect is then used to regularize the model using the regularization term  $\mathcal{L}_{Reg}$  (see Eq. 1 and 2). Also, we search over the regularization strength  $R$  (Eq. 1) to select the best model. For all the datasets we choose the
value of  $R$  from set  $\{1, 10, 100, 1000\}$ . We train the model for 20 epochs for all the datasets. Next, to compare the results with other methods we select the best model (across different regularization hyperparameters and training epochs) that has the highest accuracy on the validation set. Here accuracy of the model is defined as:
$$
\text {a c c u r a c y} = \frac {\sum_ {i = 1} ^ {N} \mathbb {1} \left(f \left(\boldsymbol {x} _ {i}\right) = y _ {i}\right)}{N} \tag {33}
$$
where  $\mathbb{1}(\cdot)$  is the indicator function that is equal to 1 if the argument is true and 0 otherwise, "f" is the model,  $x_{i}$  is the input to the model and  $y_{i}$  is the target label, and  $\mathbf{N}$  is the total number of sample in the dataset.
The abovementioned selection criteria assume that we don't know the spurious attribute. However, some of the baselines we considered in our work (JTT and IRM) do assume that the spurious attributes are known and use them to train and select the best model that generalizes under spurious correlations. Thus for a fair comparison, in §F.2 and Fig. 7, we re-evaluate all the methods on all the datasets by relaxing this assumption. Now we select the configuration that performs the best on the following metric (see §4.2 for the definition of the individual metrics):
$$
\text {s e l e c t i o n c r i t e r i a} = \frac {\text {M a j o r i t y G r o u p A c c u r a c y} + \text {M i n o r i t y G r o u p A c c u r a c y} + (1 - \Delta \text {P r o b})}{3} \tag {34}
$$
E.6 Setup: Mouli+CAD and other related baselines