SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Figure 7: Accuracy of NW (imbalanced) and  $\mathrm{NW}^{\mathrm{B}}$  (balanced) models over varying prevalence of  $y = 0$  for ISIC dataset. At low prevalence where the prevalence differs the most from training domains, we observe that model performance is higher for  $\mathrm{NW}^{\mathrm{B}}$ . The default prevalence is 6705/7818 = 0.8576, which is the right-most value in the x-axis.
G Nearest-neighbor Inference Modes
In addition to Random, Full, Cluster, and Ensemble inference modes, we additionally experiment with two inference modes based on nearest neighbors: k-NN and HNSW. HNSW (Hierarchical Navigable Small Worlds) is a fast approximate nearest neighbor algorithm [33]. We choose  $k = 20$  based on prior work [25]. HNSW is about two times faster in total runtime on a GPU than full k-NN.
Overall, we observe that k-NN and HNSW perform nearly identically for all the datasets and variants. Additionally, both modes perform better in terms of mean performance on Camelyon-17, and perform on par with the best-performing modes for ISIC (Cluster) and FMoW (Ensemble). However, they generally have higher variances across model runs. We suspect that less total samples used in the support (20 as compared to more than 1000 for Full) and the fact that not all classes are guaranteed to be represented in the support may lead to less stability across model runs.
Table 6: Metric average  $\pm$  standard deviation for all datasets (%) . Higher is better. Implicit / Explicit.
Algorithm	Camelyon-17	ISIC	FMoW
NWb, Full	72.0±6.7	61.9±3.5	31.6±0.9
NWb, Cluster	70.6±6.9	61.4±2.3	31.3±0.9
NWb, Ensemble	71.9±6.0	63.9±3.8	32.2±1.0
NWb, k-NN	72.5±3.2	64.2±2.6	32.5±1.4
NWb, HNSW	72.5±3.2	64.2±2.6	32.5±1.4
NWb, Full	80.0±2.7 / 79.7±1.9	69.6±2.3 / 70.0±1.0	35.0±0.7 / 34.6±0.4
NWb, Cluster	78.6±2.5 / 79.0±1.4	71.1±1.7 / 71.0±1.0	33.9±0.6 / 34.0±0.3
NWb, Ensemble	79.5±2.6 / 79.6±1.9	69.5±2.2 / 69.8±0.8	37.8±0.9 / 38.2±0.4
NWb, k-NN	80.9±10.3 / 80.2±4.9	70.7±7.4 / 71.0±7.2	37.9±2.3 / 38.3±1.1
NWb, HNSW	80.9±10.3 / 80.2±5.0	70.7±7.4 / 71.0±7.2	37.9±2.2 / 38.2±1.1
H Interpretability of NW Head
In this section, we provide both a visual and quantitative exploration of the interpretability capabilities of the NW head. In Fig. 8, we show several query images and its 8 nearest neighbors in the feature space, for both  $\mathrm{NW^B}$  and  $\mathrm{NW_e^B}$  variants. The colored border around each neighbor indicates which training environment the image comes from. Interestingly, we notice that the neighbors for  $\mathrm{NW_e^B}$  come from a variety of environments (note a variety of colored borders), while the neighbors for  $\mathrm{NW^B}$  are less diverse.
Fig. 9 quantifies this phenomenon, depicting a normalized histogram of the environments from which the top 20 nearest neighbors originate in the training dataset for Camelyon-17, averaged over all queries in the test set. From these results, it is clear that  $\mathrm{NW_e^B}$  leverages support images from a wider variety of environments to make its prediction, suggesting that it captures more invariant representations.
Figure 8: Visualization of 3 query images and their 8 nearest neighbors in the feature space, for both  $\mathrm{NW_e^B}$  (top) and  $\mathrm{NW^B}$  (bottom). Labels are shown in the bottom right corner, and colored borders of neighbors indicate which of the 3 training environments the image comes from. For both variants, we observe visual similarity between the query images and the nearest neighbors. However, we observe the neighbors for  $\mathrm{NW^B}$  tend to lack diversity in the environments from which they originate. In contrast, neighbors for  $\mathrm{NW_e^B}$  tend to come from a wider variety of environments, suggesting that  $\mathrm{NW_e^B}$  captures more invariant representations.
Figure 9: Normalized histogram of the environments from which the top 20 nearest neighbors originate in the training dataset for Camelyon-17, averaged over all queries in the test set. We observe a more balanced proportion for  $\mathrm{NW_e^B}$ , indicating that the model relies more evenly across all 3 environments to make its prediction, and further suggesting that representations are more invariant than  $\mathrm{NW^B}$ .