SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Table 7: A summary of datasets information from WILDS.
Dataset	Data (x)	Class information	Domains	Metric	Architecture
AMAZON	Product reviews	Star ratings (5 classes)	7,676 reviewers	10-eth percentile acc.	DistillBERT
CAMELYON17	Tissue slides	Tumor (2 classes)	5 hospitals	Avg. acc.	DenseNet-121
CIVILCOMMENTS	Online comments	Toxicity (2 classes)	8 demographic groups	Wr. group acc.	DistillBERT
FMOW	Satellite images	Land use (62 classes)	16 years x 5 regions	Wr. group acc.	DenseNet-121
iWILDCAM	Photos	Animal species (186 classes)	324 locations	Macro F1	ResNet-50
RXRx1	Cell images	Genetic treatments (1,139 classes)	51 experimental batches	Avg. acc	ResNet-50
Table 8: A summary of datasets statistics from WILDS.
Dataset	# Examples	# Domains
train	val	test	train	val	test
AMAZON	1,000,124	100,050	100,050	5,008	1,334	1,334
CAMELYON17	302,436	34,904	85,054	3	1	1
CIVILCOMMENTS	269,038	45,180	133,782	-	-	-
FMOW	76,863	19,915	22,108	11	3	2
IWILDCAM	129,809	14,961	42,791	243	32	48
RXRx1	40,612	9,854	34,432	33	4	14
Amazon. We follow the WILDS splits and data processing pipeline for the Amazon dataset [51]. It provides 1.4 million comments collected from 7,676 Amazon customers. The task is to predict the score (1-5 stars) for each review. The domains  $d$  are defined according to the reviewer/customer who wrote the product reviews. The evaluation metric used for the task is 10th percentile of per-user accuracies in the OOD test sets, and the backbone model is a DistilBert [66], following the WILDS protocol [39].
Camelyon17. We follow the WILDS splits and data processing pipeline for the Camelyon17 dataset [6]. It provides 450,000 lymph-node scans from 5 hospitals. The task in Camelyon17 is to take the input of  $96 \times 96$  medical images to predict whether there exists a tumor tissue in the image. The domains  $d$  refers to the index of the hospital where the image was taken. The training data are sampled from the first 3 hospitals where the OOD validation and test data are sampled from the 4-th and 5-th hospital, respectively. We will use the average accuracy as the evaluation metric and a DenseNet-121 [31] as the backbone for the featurizer.
CivilComments. We follow the WILDS splits and data processing pipeline for the CivilComments dataset [9]. It provides 450,000 comments collected from online articles. The task is to classify whether an online comment text is toxic or non-toxic. The domains  $d$  are defined according to the demographic features, including male, female, LGBTQ, Christian, Muslim, other religions, Black, and White. CivilComments is used to study the subpopulation shifts, here we will use the worst group/domain accuracy as the evaluation metric. As for the backbone of the featurizer, we will use a DistillBert [66] following WILDS [39].
FMoW. We follow the WILDS splits and data processing pipeline for the FMoW dataset [18]. It provides satellite images from 16 years and 5 regions. The task in FMoW is to classify the images into 62 classes of building or land use categories. The domain is split according to the year that the satellite image was collected, as well as the regions in the image which could be Africa, America, Asia, Europe or Oceania. Distribution shifts could happen across different years and regions. The training data contains data collected before 2013, while the validation data contains images collected within 2013 to 2015, and the test data contains images collected after 2015. The evaluation metric for FMoW is the worst region accuracy and the backbone model for the featurizer is a DenseNet-121 [31].
iWildCam. We follow the WILDS splits and data processing pipeline for the iWildCam dataset [8]. It is consist of 203,029 heat or motion-activated photos of animal specifies from 323 different camera traps across different countries around the world. The task of iWildCam is to classify the corresponding animal specifies in the photos. The domains is split according to the locations of the camera traps which could introduce the distribution shifts. We will use the Macro F1 as the evaluation metric and a ResNet-50 [27] as the backbone for the featurizer.
RxRx1. We follow the WILDS splits and data processing pipeline for the RxRx1 dataset [72]. The input is an image of cells taken by fluorescent microscopy. The cells can be genetically perturbed by siRNA and the task of RxRx1 is to predict the class of the corresponding siRNA that have treated the cells. There exists 1, 139 genetic treatments and the domain shifts are introduced by the experimental batches. We will use the average accuracy of the OOD experimental batches as the evaluation metric and a ResNet-50 [27] as the backbone for the featurizer.
F.2.2 Training and evaluation details.
We follow previous works to implement and evaluate different methods used in our experiments [39]. The information of the referred paper and code is listed as in Table. 9.
Table 9: The information of the referred paper and code.
Paper	Commit	Code
WILDS [39]	v2.0.0	https://wilds.stanford.edu/
Fish [69]	333efa24572d99da0a4107ab9cc4af93a915d2a9	https://github.com/YugeTen/fish
Bonsai [83]	33b9ecad0ce8b3462793a2da7a9348d053c06ce0	https://github.com/TjuJianyu/RFC
DFR [33, 38]	6d098440c697a1175de6a24d7a46cff91786804c	https://github.com/izmailovpavel/spurious-feature_learning
The general hyperparemter setting inherit from the referred codes and papers, and are as listed in Table 10. We use the same backbone models to implement the featurizer [27, 31, 66]. By default, we repeat the experiments by 3 runs with the random seeds of 0, 1, 2. While for Camelyon17, we follow the official guide to repeat 10 times with the random seeds from 0 to 9.
Table 10: General hyperparameter settings for the experiments on WILDS.
Dataset	AMAZON	CAMELYON17	CIVIL COMMENTS	FMOW	IWILDCAM	RXRx1
Num. of seeds	3	10	3	3	3	3
Learning rate	2e-6	1e-4	1e-5	1e-4	1e-4	1e-3
Weight decay	0	0	0.01	0	0	1e-5
Scheduler	n/a	n/a	n/a	n/a	n/a	Cosine Warmup
Batch size	64	32	16	32	16	72
Architecture	DistilBert	DenseNet121	DistilBert	DenseNet121	ResNet50	ResNet50
Optimizer	Adam	SGD	Adam	Adam	Adam	Adam
Domains in minibatch	5	3	5	5	10	10
Group by	Countries	Hospitals	Demographics× toxicity	Times × regions	Trap locations	Experimental batches
Training epochs	200	10	5	12	9	90
OOD objective implementations. We choose 4 representative OOD objectives to evaluate the quality of learned features, including GroupDRO [64], IRMv1 [4], VREx [41] and IRMX [16].
We implement the OOD objectives based on the code provided by Shi et al. [69]. For each OOD objective, by default, we follow the WILDS practice to sweep the penalty weights from the range of  $\{1e - 2,1e - 1,1,1e1,1e2\}$ , and perform the model and hyperparameter selection via the performance in the provided OOD validation set of each dataset. Due to the overwhelming computational overhead required by large datasets and resource constraints, we tune the penalty weight in iWildCam according to the performance with seed 0, which we empirically find yields similar results as full seed tunning. Besides in Amazon, we adopt the penalty weights tuned from CivilComments since the two datasets share a relatively high similarity, which we empirically find yields similar results as full seed tunning, too. On the other hand, it raises more challenges for feature learning algorithms in iWildCam and Amazon.
Deep Feature Reweighting (DFR) implementations. For the implementation of DFR [33, 38], we use the code provided in Izmailov et al. [33]. By default, DFR considers the OOD validation as an unbiased dataset and adopts the OOD validation set to learn a new classifier based on the frozen features from the pre-trained featurizer. We follow the same implementation and evaluation protocol when evaluating feature learning quality in FMoW and CivilComments. However, since Camelyon17 does not have the desired OOD validation set, we follow the "cheating" protocol as in Rosenfeld et al. [63] to perform the logistic regression based the train and test sets. Note that when "cheating", the model is not able to access the whole test sets. Instead, the logistic regression is conducted on a random split of the concatenated train and test data. Moreover, for Amazon and iWildCam, we find the original implementation fails to converge possibly due to the complexity of the task, and the relatively poor feature learning quality. Hence we implement a new logistic regression based on PyTorch [54] optimized with SGD, and perform DFR using "cheating" protocol based on the OOD validation set and test set. Besides, we find neither the two aforementioned implementations or dataset choices can lead to DFR convergence in RxRx, which we will leave for future investigations.
Feature learning algorithm implementations. We implement all the feature learning methods based on the Fish code framework. For the fairness of comparison, we set all the methods to train the same number of steps or rounds (if applicable) in WILDS datasets. The only exception is in RxRx1, where both Bonsai and FeAT require more steps to converge, since the initialized featurizer has a relatively large distance from the desired featurizer in the task. We did not train the model for much too long epochs as Izmailov et al. [33] find that it only requires 2 - 5 epochs for deep nets to learn high-quality invariant features. The final model is selected based on the OOD validation accuracy during the training. Besides, we tune the retain penalty in FeAT by searching over  $\{1e - 2, 1e - 1, 0.5, 1, 2, 10\}$ , and finalize the retain penalty according to the OOD validation performance. We list the detailed training steps and rounds setups, as well as the used retain penalty in FeAT in Table 11.
Table 11: Hyperparameter setups of feature learning algorithms for the experiments on WILDS.
Dataset	AMAZON	CAMELYON17	CIVIL COMMENTS	FMOW	IWILDCAM	RXRX1
Overall steps	31,000	10,000	50,445	9,600	48,000	20,000
Approx. epochs	4	10	3	4	10	10
Num. of rounds	3	2	3	2	2	10
Steps per round	10,334	5,000	16,815	4,800	10	10
FeAT Retain penalty	2.0	1e-2	1e-2	1.0	0.5	10
For ERM, we train the model simply by the overall number of steps, except for RxRx1 where we train the model by 15,000 steps following previous setups [69]. Bonsai and FeAT directly adopt the setting listed in the Table 11. Besides, Bonsai will adopt one additional round for synthesizing the pre-trained models from different rounds. Although Zhang et al. [83] requires Bonsai to train the two rounds for synthesizing the learned features, we empirically find additional training steps in synthesizing will incur overfitting and worse performance. Moreover, as Bonsai requires propagating  $2K - 1$  batches of the data that may exceed the memory limits, we use a smaller batch size when training Bonsai in iWildCam (8) and RxRx1 (56).
F.3 Software and hardware
We implement our methods with PyTorch [54]. For the software and hardware configurations, we ensure the consistent environments for each datasets. We run all the experiments on Linux servers with NVIDIA V100 graphics cards with CUDA 10.2.
F.4 Computational analysis
Compared to ERM, the additional computational and memory overhead introduced in FeAT mainly lie in the FeAT training and partitioning. At each training step, FeAT needs  $(k - 1)$  additional forward and backward propagation, the same as Bonsai, while FeAT only needs  $\min(1, k - 1)$  additional propagation. Besides, Bonsai additionally requires another round of training with  $(K - 1)$  additional propagation, given  $K$  total rounds.
We calculated the computational overhead: The results aligned with our discussion. Bonsai requires
Table 12: Training and memory overhead of different algorithms.
Camelyon17 Training time	Memory (%)	CivilComments Training time	Memory (%)
ERM	56.21±8.29 mins	22.56±0.00	24.22±0.33 hrs	36.46±0.00
Bonsai	214.55±1.13 mins	51.75±0.01	58.47±0.91 hrs	64.43±0.31
FeAT	101.14±12.79 mins	51.92±0.04	28.19±1.15 hrs	56.21±0.48
much more time for the additional synthetic round and much more memory when there are 3 or more rounds. In contrast, FeAT achieves the best performance without introducing too much additional computational overhead.
F.5 Feature learning analysis
We first visualize the feature learning of ERM and FeAT on ColoredMNIST-025, as shown in Fig. 4. It can be found that ERM can learn both invariant and spurious features to predict the label, aligned with our theory.
However, ERM focuses more on spurious features and even forgets certain features with longer training epochs, which could be due to multiple reasons such as the simplicity biases of ERM. Hence predictions based on ERM learned features fail to generalize to OOD examples. In contrast, FeAT effectively captures the meaningful features for all samples and generalizes to OOD examples well.
Table 13: Labels and predictions for the visualized samples.
Label	ERM	Bonsai	FeAT	Label	ERM	Bonsai	FeAT
CAMELYON17	1	1	0	1	IWILDCAM	113	68	0	113
1	1	0	1	113	0	0	113
1	1	0	1	36	36	36	36
1	0	0	0	36	36	36	36
FMOW	40	40	40	40	RxRx1	1138	812	812	812
40	40	40	40	1138	1133	1125	1133
40	2	29	29	35	43	1119	143
40	40	40	40	35	35	1054	35
CIVIL COMMENTS	toxic	toxic	toxic	toxic	AMAZON	2	3	3	2
toxic	toxic	toxic	toxic	5	5	5	5
toxic	toxic	toxic	toxic	3	4	4	4
nontoxic	nontoxic	nontoxic	nontoxic	5	5	5	5
We also visualize the saliency maps of ERM, Bonsai, and FeAT on all real-world datasets used in our work with https://github.com/pytorch/captum. The visualizations are shown as in Fig. 5 to Fig. 11, for which the labels and the predictions of different algorithms are given in Table. 13. It can be found that, across various tasks and data modalities, FeAT effectively learns more meaningful and diverse features than ERM and Bonsai, which serve as strong evidence for the consistent superiority of FeAT in OOD generalization.
(a) ERM 150 epochs
(b) ERM 300 epochs
(c) ERM 450 epochs
Figure 4: GradCAM visualization on COLOREDMNIST-025, where the shortcuts are now concentrated to a colored path at the up left. Three visualizations are drawn for each sample: the original figure, the gray-colored gradcam, and the gradcam. It can be found that ERM can not properly capture the desired features or even forget certain features with longer training epochs. FeAT can stably capture the desired features.
(d) FeAT 2 rounds
Legend: Negative □ Neutral □ Positive
Method	Word Importance
ERM	[CLS] "adol hilt ##er was actually left wing . the nazi party was very socialist . " if you knew anything about the history of nazi germany -- -- persecution of jews , intellectuals , communists , social democrats , etc -- - you ' d realize how ridiculous your statements are . [SEP]
ERM	[CLS] no one can force anyone to not say what they want , free speech lives get over it , , what is not toll ##erated is a call to harm people , that ##s all , and flying some lunatic nazi flag as stupid and disgusting as it is , , is not doing harm . . [SEP]
ERM	[CLS] the catholic church is officially part of # radical ##bol ##sh #ev #ik #ter #r #ism communist organizers as a catholic i ' m disgusted by the indo ##ct #rina #tion of what is becoming a cult the pope and this mor #on mc #el #roy ignore mass genocide while prop #piping up the cult of mohammed bent on the genocide of christians [SEP]
ERM	[CLS] does the term " cognitive di #sson #ance " apply to bailey ? [SEP]
Bonsai	[CLS] "adol hilt #er was actually left wing . the nazi party was very socialist . " if you knew anything about the history of nazi germany -- -- persecution of jews , intellectuals , communists , social democrats , etc -- - you ' d realize how ridiculous your statements are . [SEP]
Bonsai	[CLS] no one can force anyone to not say what they want , free speech lives get over it , , what is not toll #erated is a call to harm people , that ##s all , and flying some lunatic nazi flag as stupid and disgusting as it is , , is not doing harm . . [SEP]
Bonsai	[CLS] the catholic church is officially part of # radical #bol #sh #ev #ik #ter #r #ism communist organizers as a catholic i ' m disgusted by the indo #ct #rina #tion of what is becoming a cult the pope and this mor #on mc #el #roy ignore mass genocide while prop #piping up the cult of mohammed bent on the genocide of christians [SEP]
Bonsai	[CLS] does the term " cognitive di #sson #ance " apply to bailey ? [SEP]
FeAT	[CLS] "adol hilt #er was actually left wing . the nazi party was very socialist . " if you knew anything about the history of nazi germany -- -- persecution of jews , intellectuals , communists , social democrats , etc -- - you ' d realize how ridiculous your statements are . [SEP]
FeAT	[CLS] no one can force anyone to not say what they want , free speech lives get over it , , what is not toll #erated is a call to harm people , that ##s all , and flying some lunatic nazi flag as stupid and disgusting as it is , , is not doing harm . . [SEP]
FeAT	[CLS] the catholic church is officially part of # radical #bol #sh #ev #ik #ter #r #ism communist organizers as a catholic i ' m disgusted by the indo ##ct #rina #tion of what is becoming a cult the pope and this mor #on mc #el #roy ignore mass genocide while prop #piping up the cult of mohammed bent on the genocide of christians [SEP]
FeAT	[CLS] does the term " cognitive di #sson #ance " apply to bailey ? [SEP]
Figure 5: Saliency map of feature learning on WILDS CIVILCOMMENTS benchmark. The green-colored tokens are the learned features that contributed most to the target class, while the red-colored tokens contributed to the other classes. It can be found that FeAT is able to learn more meaningful and diverse features than ERM and Bonsai.
Word Importance
[CLS] american dream ##z try ##s to be american idol with a political agenda on the bush ad #mins #tra #tion which in itself goes all over the place & never provides entertainment . hugh grant is a actor who pretty much hit his peak well over a decade ago & his take as simon from idol is rather just there . mandy moore is ok nothing to say more than she may be a bit player as a actress at best . this film takes on so much to be a satire , but it ends up with more questions then any answers . too long & over #bl #own . william def #oe was trying to look like dick cheney but ended up looking more like henry fond ##a . dennis qu #aid was channel #ing george bush with mixed results . just a ok film . [SEP]
[CLS] this fits my iphone perfectly , and i already have an inc ##ip ##io silicon sleeve that i keep it in permanently . it ' s a little s ##nu ##g with the sleeve , but easy enough to put in and take out . there are 2 belt loops , that i don ' t use , and one belt clip that i do use . the belt clip seems sturdy enough . when i bought this , it was $ 2 . 98 with no s & h . this certainly isn ' t worth a whole lot more than that , but it ' s a great value for the price . i ' d actually be willing to pay up to $ 7 . 00 for it . it ' s not too bulky , at least not more than a holster should be . the magnet keeps it closed . it stays on my belt just fine , and it ' s sturdy enough to keep the iphone safe for a short drop , especially with the silicon sleeve . it ' s not terribly fashionable , but you can ' t beat the price . [SEP]
[CLS] the mind of till ##ie cole must be quite an interesting place . in her third book of the scarred souls series cole once again explores the deepest parts of human de ##pr ##avi #ty . it ' ll shock and outrage you , it ' ll make you feel so much more for her characters . ra ##va ##ge is told mainly from the points of views of 194 and z ##oya with a couple chapters from lu ##ka . it is not a stand alone book , in my opinion this series should be read in order . i ' ve been a fan of this series from the beginning . the darkness of human nature till ##ie cole continually portrays never cease #s to engage me . her stories come from a place of raw honesty and empathy . her writing mature #s with each book . the story of 194 and z ##oya and their roles in this tangled web of a world cole has created was as consuming as the others . however , for me , something was off in their relationship , in the romance . i missed the connection i felt with the previous books main characters . while cole dug deep into their past and pulled out their flaws and vu ##In ##era ##bilities so well as individuals , an aspect of their chemistry and need for each other just didn ' t quite click . this series consistently moves forward though adding more depth and layers to the ultimate story and goals of all of these characters . and in that aspect , the story really excelled and has me just as intrigued in how it all works out as i ever was and i very much look forward to the next installment of the scarred souls series . ra ##va ##ge left much open to be explored and i ' m confident in cole ' s story telling to take me even deeper into her interesting #ly de ##pr ##ave #d world . [SEP]
[CLS] just keeps getting better and better! if you like alpha men, strong heroine ##s and laughter with a dash of seriousness, don ' t miss this series !! [SEP]
(a) AMAZON-ERM
[CLS] american dream ##z try ##s to be american idol with a political agenda on the bush ad ##mins ##tra ##tion which in itself goes all over the place & never provides entertainment . hugh grant is a actor who pretty much hit his peak well over a decade ago & his take as simon from idol is rather just there . mandy moore is ok nothing to say more than she may be a bit player as a actress at best . this film takes on so much to be a satire , but it ends up with more questions then any answers . too long & over #bl #own . william def #oe was trying to look like dick cheney but ended up looking more like henry fond ##a . dennis qu ##aid was channel #ing george bush with mixed results . just aok film . [SEP]
[CLS] the mind of till ##ie cole must be quite an interesting place . in her third book of the scarred souls series cole once again explores the deepest parts of human de ##pr ##avi ##ty . it ' ll shock and outrage you , it ' ll make you feel so much more for her characters . ra ##va ##ge is told mainly from the points of views of 194 and z ##oya with a couple chapters from lu ##ka . it is not a stand alone book , in my opinion this series should be read in order . i ' ve been a fan of this series from the beginning . the darkness of human nature till ##ie cole continually portrays never cease ##s to engage me . her stories come from a place of raw honesty and empathy . her writing mature ##s with each book . the story of 194 and z ##oya and their roles in this tangled web of a world cole has created was as consuming as the others . however , for me , something was off in their relationship , in the romance . i missed the connection i felt with the previous books main characters . while cole dug deep into their past and pulled out their flaws and vu ##In ##era ###bilities so well as individuals , an aspect of their chemistry and need for each other just didn ' t quite click . this series consistently moves forward though adding more depth and layers to the ultimate story and goals of all of these characters . and in that aspect , the story really excelled and has me just as intrigued in how it all works out as i ever was and i very much look forward to the next installment of the scarred souls series . ra ##va ##ge left much open to be explored and i ' m confident in cole ' s story telling to take me even deeper into her interesting #ly de #pr #ave #d world . [SEP]
[CLS] just keeps getting better and better! if you like alpha men, strong heroine ##s and laughter with a dash of seriousness, don ' t miss this series ! ! [SEP]
(b)Amazon-Bonsai
Figure 6: Saliency map of feature learning on WILDS AMAZON benchmark. The green-colored tokens are the learned features that contributed most to the target class, while the red-colored tokens contributed to the other classes. It can be found that FeAT is able to learn more meaningful and diverse features than ERM and Bonsai.
FeAT