SlowGuess/NeurIPS_2023_OCR huggingface dataset:
where:  $a$  is from the fact that  $\mathcal{L}_{\widehat{\mathcal{D}}}^{\mathcal{B}}(\ell, \hat{h}) \leq \mathcal{L}_{\widehat{\mathcal{D}}}^{\mathcal{B}}(\ell, h^{\star})$  by the definition of  $\hat{h}$ ;  $b$  is from Theorem 3.1, although in Theorem 3.1, we only have bounds for  $\sup_{h \in \mathcal{H}} \left( \mathcal{L}_p^{\mathcal{B}}(\ell, h) - \mathcal{L}_{\widehat{\mathcal{D}}}^{\mathcal{B}}(\ell, h) \right)$ , we can use a similar argumentation as in Theorem 3.1 to get the same bound for  $\sup_{h \in \mathcal{H}} \left( \mathcal{L}_{\widehat{\mathcal{D}}}^{\mathcal{B}}(\ell, h) - \mathcal{L}_p^{\mathcal{B}}(\ell, h) \right)$ , both with probability at least  $1 - \delta'$ , using union bound for these two cases we get a bound for  $\sup_{h \in \mathcal{H}} \left| \mathcal{L}_p^{\mathcal{B}}(\ell, h) - \mathcal{L}_{\widehat{\mathcal{D}}}^{\mathcal{B}}(\ell, h) \right|$  with probability at least  $1 - 2\delta'$ , take  $\delta = \frac{\delta'}{2}$ , we get the bound for  $\sup_{h \in \mathcal{H}} \left| \mathcal{L}_p^{\mathcal{B}}(\ell, h) - \mathcal{L}_{\widehat{\mathcal{D}}}^{\mathcal{B}}(\ell, h) \right|$  with probability at least  $1 - \delta$ , this is why we get  $\ln 4/\delta$  in Theorem 3.1 but  $\ln 8/\delta$  here.
A.3 Proof of the Limited Environment Case
Proof  $d_{\ell(\mathcal{H})}^{\mathcal{B}}(\cdot, \cdot)$  is a pseudometric. It is obvious that  $d_{\ell(\mathcal{H})}^{\mathcal{B}}(\cdot, \cdot)$  is symmetric, now we proof that  $d_{\ell(\mathcal{H})}^{\mathcal{B}}(\cdot, \cdot)$  satisfies the triangle inequality. By definition, for distribution  $P, Q, R$ :
$$
\begin{array}{l} d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (P, Q) = \sup  _ {h \in \mathcal {H}} \left| \underset {(x, y) \sim P} {\mathbb {E}} \left[ \sup  _ {\boldsymbol {x} ^ {\prime} \in \mathcal {B} (\boldsymbol {x})} \ell (h (\boldsymbol {x} ^ {\prime}), y) \right] - \underset {(x, y) \sim Q} {\mathbb {E}} \left[ \sup  _ {\boldsymbol {x} ^ {\prime} \in \mathcal {B} (\boldsymbol {x})} \ell (h (\boldsymbol {x} ^ {\prime}), y) \right] \right| \\ = \sup  _ {h \in \mathcal {H}} \left| \underset {(x, y) \sim P} {\mathbb {E}} \left[ \sup  _ {\boldsymbol {x} ^ {\prime} \in \mathcal {B} (\boldsymbol {x})} \ell (h (\boldsymbol {x} ^ {\prime}), y) \right] - \underset {(x, y) \sim R} {\mathbb {E}} \left[ \sup  _ {\boldsymbol {x} ^ {\prime} \in \mathcal {B} (\boldsymbol {x})} \ell (h (\boldsymbol {x} ^ {\prime}), y) \right] \right. \\ + \underset {(\boldsymbol {x}, y) \sim R} {\mathbb {E}} \left[ \sup  _ {\boldsymbol {x} ^ {\prime} \in \mathcal {B} (\boldsymbol {x})} \ell (h (\boldsymbol {x} ^ {\prime}), y) \right] - \underset {(\boldsymbol {x}, y) \sim Q} {\mathbb {E}} \left[ \sup  _ {\boldsymbol {x} ^ {\prime} \in \mathcal {B} (\boldsymbol {x})} \ell (h (\boldsymbol {x} ^ {\prime}), y) \right] \\ \stackrel {a} {\leq} \sup  _ {h \in \mathcal {H}} \left| \underset {(x, y) \sim P} {\mathbb {E}} \left[ \sup  _ {x ^ {\prime} \in \mathcal {B} (x)} \ell (h \left(x ^ {\prime}\right), y) \right] - \underset {(x, y) \sim R} {\mathbb {E}} \left[ \sup  _ {x ^ {\prime} \in \mathcal {B} (x)} \ell (h \left(x ^ {\prime}\right), y) \right] \right| \\ + \sup  _ {h \in \mathcal {H}} \left| \underset {(x, y) \sim R} {\mathbb {E}} \left[ \sup  _ {x ^ {\prime} \in \mathcal {B} (x)} \ell (h (x ^ {\prime}), y) \right] - \underset {(x, y) \sim Q} {\mathbb {E}} \left[ \sup  _ {x ^ {\prime} \in \mathcal {B} (x)} \ell (h (x ^ {\prime}), y) \right] \right| \\ = d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (P, R) + d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (R, Q), \\ \end{array}
$$
where:  $a$  is from the subadditivity of the supremum operator. So  $d_{\ell(\mathcal{H})}^{\mathcal{B}}(\cdot, \cdot)$  is a pseudometric.
Before prove Theorem 3.3, we first give a useful lemma.
Lemma A.5. For any  $h \in \mathcal{H}$ , any distribution  $P, Q$  on, we have:
$$
\left| \mathcal {R} _ {P} ^ {\mathcal {B}} (\ell , h) - \mathcal {R} _ {Q} ^ {\mathcal {B}} (\ell , h) \right| \leq d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (P, Q)
$$
Proof of Lemma A.5. From the definition of  $d_{\ell(\mathcal{H})}^{\mathcal{B}}(P, Q)$ , we can know that:
$$
d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (P, Q) = \sup _ {h \in \mathcal {H}} \left| \mathcal {R} _ {P} ^ {\mathcal {B}} (\ell , h) - \mathcal {R} _ {Q} ^ {\mathcal {B}} (\ell , h) \right| \geq \left| \mathcal {R} _ {P} ^ {\mathcal {B}} (\ell , h) - \mathcal {R} _ {Q} ^ {\mathcal {B}} (\ell , h) \right|, \forall h \in \mathcal {H},
$$
which is just what we want.
Theorem 3.3. For a given but unknown target distribution  $\mathcal{T}$ , let  $\Delta^{t-1} \coloneqq \{(\lambda_1, \dots, \lambda_t) | \lambda_i \geq 0, \sum_{i=1}^t \lambda_i = 1\}$  be the  $t$ -dimensional simplex and  $\operatorname{Conv}(\mathfrak{D}) \coloneqq \left\{\sum_{i=1}^t \lambda_i \mathcal{D}_i | \boldsymbol{\lambda} \in \Delta^{t-1}\right\}$  be the convex hull of  $\mathfrak{D} = \{\mathcal{D}_1, \ldots, \mathcal{D}_t\}$ , define  $\mathcal{T}_P \in \underset{\mathcal{D} \in \operatorname{Conv}(\mathfrak{D})}{\arg \inf} d_{\ell(\mathcal{H})}^\mathcal{B}(\mathcal{D}, \mathcal{T})$  be the "projection" of  $\mathcal{T}$  onto  $\operatorname{Conv}(\mathfrak{D})$  and  $\boldsymbol{\lambda}^\star$  be the weight vector where  $\mathcal{T}_P = \sum_{i=1}^t \lambda_i^\star \mathcal{D}_i$ ,  $\ell \in [0, U]$ , then we have: with probability at least  $1 - \delta$ , for all  $h \in \mathcal{H}$ ,
$$
\begin{array}{l} \mathcal {R} _ {\mathcal {T}} ^ {\mathcal {B}} (\ell , h) \leq \frac {1}{t} \sum_ {i = 1} ^ {t} \mathcal {R} _ {\widehat {\mathcal {D}} _ {i}} ^ {\mathcal {B}} (\ell , h) + \frac {1}{t} \sum_ {i} \sum_ {j} \lambda_ {j} ^ {\star} d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (\widehat {\mathcal {D}} _ {i}, \widehat {\mathcal {D}} _ {j}) + d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (\mathcal {T}, \mathcal {T} _ {P}) \\ + 4 \Re_ {t n} (\widetilde {\mathcal {G}}) + 2 \Re_ {n} (\widetilde {\mathcal {G}}) + 6 U \sqrt {\frac {\ln 8 / \delta}{2 t n}} + 3 U \sqrt {\frac {\ln (1 6 t / \delta)}{2 n}} \\ \end{array}
$$
Proof of Theorem 3.3. Our proof is divided into 2 steps, the first step gets results for the population distributions and the second step uses finite sample approximation to get results for empirical distributions.
Step 1. Get the relationship between the population distributions.
Lemma A.5 tells us that: for all  $h\in \mathcal{H}$
$$
\mathcal {R} _ {\mathcal {T}} ^ {\mathcal {B}} (\ell , h) \leq \mathcal {R} _ {\mathcal {D}} ^ {\mathcal {B}} (\ell , h) + d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (\mathcal {T}, \bar {\mathcal {D}}) \leq \mathcal {R} _ {\bar {\mathcal {D}}} ^ {\mathcal {B}} (\ell , h) + d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (\mathcal {T}, \mathcal {T} _ {P}) + d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (\mathcal {T} _ {P}, \bar {\mathcal {D}}),
$$
where the last inequality is from the triangle inequality of  $d_{\ell(\mathcal{H})}^{\mathcal{B}}(\cdot, \cdot)$  and  $\bar{\mathcal{D}} = \frac{1}{t}\sum_{i=1}^{t}\mathcal{D}_i$ . Recall that  $\widehat{\mathcal{D}} = \frac{1}{t}\sum_{i=1}^{t}\widehat{\mathcal{D}}_i$ , then we have:
$$
\begin{array}{l} d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} \left(\mathcal {T} _ {P}, \bar {\mathcal {D}}\right) \stackrel {a} {\leq} d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} \left(\mathcal {T} _ {P}, \widehat {\mathcal {T}} _ {P}\right) + d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} \left(\widehat {\mathcal {T}} _ {P}, \widehat {\mathcal {D}}\right) + d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} \left(\widehat {\mathcal {D}}, \bar {\mathcal {D}}\right) \\ = d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} \left(\mathcal {T} _ {P}, \widehat {\mathcal {T}} _ {P}\right) + d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} \left(\widehat {\mathcal {D}}, \bar {\mathcal {D}}\right) + d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} \left(\sum_ {i = 1} ^ {t} \lambda_ {i} ^ {*} \widehat {\mathcal {D}} _ {i}, \frac {1}{t} \sum_ {i = 1} ^ {t} \widehat {\mathcal {D}} _ {i}\right) \\ = d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} \left(\mathcal {T} _ {P}, \widehat {\mathcal {T}} _ {P}\right) + d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} \left(\widehat {\mathcal {D}}, \bar {\mathcal {D}}\right) + \sup  _ {h \in \mathcal {H}} \left| \mathcal {R} _ {\sum_ {i} \lambda_ {i} ^ {\star} \widehat {\mathcal {D}} _ {i}} ^ {\mathcal {B}} (\ell , h) - \mathcal {R} _ {\sum_ {i} \frac {1}{t} \widehat {\mathcal {D}} _ {i}} ^ {\mathcal {B}} (\ell , h) \right| \\ = d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (\mathcal {T} _ {P}, \widehat {\mathcal {T}} _ {P}) + d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (\widehat {\mathcal {D}}, \bar {\mathcal {D}}) + \sup _ {h \in \mathcal {H}} \left| \mathcal {R} _ {\frac {1}{t} \sum_ {i} \sum_ {j} \lambda_ {j} ^ {\star} \widehat {\mathcal {D}} _ {j}} ^ {\mathcal {B}} (\ell , h) - \mathcal {R} _ {\sum_ {i} \frac {1}{t} \sum_ {j} \lambda_ {j} ^ {\star} \widehat {\mathcal {D}} _ {i}} ^ {\mathcal {B}} (\ell , h) \right| \\ \stackrel {b} {\leq} d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} \left(\mathcal {T} _ {P}, \widehat {\mathcal {T}} _ {P}\right) + d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} \left(\widehat {\mathcal {D}}, \bar {\mathcal {D}}\right) + \frac {1}{t} \sum_ {i} \sum_ {j} \lambda_ {j} ^ {\star} \sup  _ {h \in \mathcal {H}} \left| \mathcal {R} _ {\widehat {\mathcal {D}} _ {i}} ^ {\mathcal {B}} (\ell , h) - \mathcal {R} _ {\widehat {\mathcal {D}} _ {j}} ^ {\mathcal {B}} (\ell , h) \right| \\ = d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (\mathcal {T} _ {P}, \widehat {\mathcal {T}} _ {P}) + d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (\widehat {\mathcal {D}}, \bar {\mathcal {D}}) + \frac {1}{t} \sum_ {i} \sum_ {j} \lambda_ {j} ^ {\star} d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (\widehat {\mathcal {D}} _ {i}, \widehat {\mathcal {D}} _ {j}), \\ \end{array}
$$
where:  $a$  is from the triangle inequality of  $d_{\ell(\mathcal{H})}^{\mathcal{B}}(\cdot, \cdot)$ ;  $b$  follows from the linearity of  $\mathcal{R}_{\mathcal{D}}^{\mathcal{B}}(\ell, h)$  and the subadditivity of the supremum operator. So we have, for any  $h \in \mathcal{H}$ :
$$
\mathcal {R} _ {\mathcal {T}} ^ {\mathcal {B}} (\ell , h) \leq \mathcal {R} _ {\bar {\mathcal {D}}} ^ {\mathcal {B}} (\ell , h) + d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} \left(\mathcal {T}, \mathcal {T} _ {P}\right) + d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} \left(\mathcal {T} _ {P}, \widehat {\mathcal {T}} _ {P}\right) + d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} \left(\widehat {\mathcal {D}}, \bar {\mathcal {D}}\right) + \frac {1}{t} \sum_ {i} \sum_ {j} \lambda_ {j} ^ {\star} d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} \left(\widehat {\mathcal {D}} _ {i}, \widehat {\mathcal {D}} _ {j}\right). \tag {A.7}
$$
Step 2. We now show the bound of the finite sample approximation error  $d_{\ell(\mathcal{H})}^{\mathcal{B}}(\mathcal{T}_P, \widehat{\mathcal{T}}_P)$  and  $d_{\ell(\mathcal{H})}^{\mathcal{B}}(\widehat{\mathcal{D}}, \bar{\mathcal{D}})$ . Since we have no access to the population distribution  $\bar{\mathcal{D}}$ , we also give a finite sample approximation of  $\mathcal{R}_{\mathcal{D}}^{\mathcal{B}}(\ell, h)$  and bound the corresponding approximation error.
The empirical distribution of  $\bar{\mathcal{D}}$  is  $\widehat{\mathcal{D}} = \frac{1}{t}\sum_{i = 1}^{t}\widehat{\mathcal{D}}_i$ , then we have:
$$
\sup _ {h \in \mathcal {H}} \left(\mathcal {R} _ {\widehat {\mathcal {D}}} ^ {\mathcal {B}} (\ell , h) - \mathcal {R} _ {\widehat {\mathcal {D}}} ^ {\mathcal {B}} (\ell , h)\right) = \sup _ {h \in \mathcal {H}} \frac {1}{t} \sum_ {i = 1} ^ {t} \left(\mathcal {R} _ {\mathcal {D} _ {i}} ^ {\mathcal {B}} (\ell , h) - \mathcal {R} _ {\widehat {\mathcal {D}} _ {i}} ^ {\mathcal {B}} (\ell , h)\right) = \Psi^ {\mathcal {B}} (\widehat {\mathfrak {D}}),
$$
where  $\Psi^{\mathcal{B}}(\widehat{\mathfrak{D}})$  is defined in the proof of Theorem 3.1. Then we have, with probability at least  $1 - \frac{\delta}{4}$ , for all  $h\in \mathcal{H}$
$$
\mathcal {R} _ {\mathcal {D}} ^ {\mathcal {B}} (\ell , h) = \frac {1}{t} \sum_ {i = 1} ^ {t} \mathcal {R} _ {\mathcal {D} _ {i}} ^ {\mathcal {B}} (\ell , h) \leq \frac {1}{t} \sum_ {i = 1} ^ {t} \mathcal {R} _ {\widehat {\mathcal {D}} _ {i}} ^ {\mathcal {B}} (\ell , h) + 2 \Re_ {t n} (\widetilde {\mathcal {G}}) + 3 U \sqrt {\frac {\ln 8 / \delta}{2 t n}}. \tag {A.8}
$$
Note that  $d_{\ell(\mathcal{H})}^{\mathcal{B}}(\widehat{\mathcal{D}}, \bar{\mathcal{D}}) = \sup_{h \in \mathcal{H}} \left| \mathcal{R}_{\bar{\mathcal{D}}}^{\mathcal{B}}(\ell, h) - \mathcal{R}_{\bar{\mathcal{D}}}^{\mathcal{B}}(\ell, h) \right|$ , similar as the bound of  $\Psi^{\mathcal{B}}(\widehat{\mathfrak{D}}) = \sup_{h \in \mathcal{H}} \left( \mathcal{R}_{\bar{\mathcal{D}}}^{\mathcal{B}}(\ell, h) - \mathcal{R}_{\bar{\mathcal{D}}}^{\mathcal{B}}(\ell, h) \right)$ , we have that with probability at least  $1 - \frac{\delta}{4}$ :
$$
\sup _ {h \in \mathcal {H}} \left(\mathcal {R} _ {\widehat {\mathcal {D}}} ^ {\mathcal {B}} (\ell , h) - \mathcal {R} _ {\widehat {\mathcal {D}}} ^ {\mathcal {B}} (\ell , h)\right) \leq 2 \Re_ {t n} (\widetilde {\mathcal {G}}) + 3 U \sqrt {\frac {\ln 8 / \delta}{2 t n}},
$$
so with probability at least  $1 - \frac{\delta}{2}$ :
$$
d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (\widehat {\mathcal {D}}, \bar {\mathcal {D}}) = \sup  _ {h \in \mathcal {H}} \left| \mathcal {R} _ {\bar {\mathcal {D}}} ^ {\mathcal {B}} (\ell , h) - \mathcal {R} _ {\widehat {\mathcal {D}}} ^ {\mathcal {B}} (\ell , h) \right| \leq 2 \Re_ {t n} (\widetilde {\mathcal {G}}) + 3 U \sqrt {\frac {\ln 8 / \delta}{2 t n}}. \tag {A.9}
$$
Now we bound  $d_{\ell(\mathcal{H})}^{\mathcal{B}}(\mathcal{T}_P, \widehat{\mathcal{T}}_P)$ , by the definition of  $\mathcal{T}_P$ , we have:
$$
d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} \left(\mathcal {T} _ {P}, \widehat {\mathcal {T}} _ {P}\right) = d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} \left(\sum_ {i = 1} ^ {t} \lambda_ {i} ^ {\star} \mathcal {D} _ {i}, \sum_ {i = 1} ^ {t} \lambda_ {i} ^ {\star} \widehat {\mathcal {D}} _ {i}\right) \leq \sum_ {i = 1} ^ {t} \lambda_ {i} ^ {\star} d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} \left(\mathcal {D} _ {i}, \widehat {\mathcal {D}} _ {i}\right)
$$
For each  $i$ , we define:
$$
\Gamma^ {\mathcal {B}} (\widehat {\mathcal {D}} _ {i}) = \sup  _ {h \in \mathcal {H}} \left(\mathcal {R} _ {\mathcal {D} _ {i}} ^ {\mathcal {B}} (\ell , h) - \mathcal {R} _ {\widehat {\mathcal {D}} _ {i}} ^ {\mathcal {B}} (\ell , h)\right).
$$
Since  $\ell \in [0,U]$ , changing one example in  $\widehat{\mathcal{D}}_i$  will lead to at most  $\frac{1}{n}$  change in  $\Gamma^{\mathcal{B}}(\widehat{\mathcal{D}}_i)$ , so by McDiarmid's inequality we know: with probability at least  $1 - \frac{\delta}{16t}$ ,
$$
\Gamma^ {\mathcal {B}} (\widehat {\mathcal {D}} _ {i}) \leq \mathbb {E} \left[ \Gamma^ {\mathcal {B}} (\widehat {\mathcal {D}} _ {i}) \right] + U \sqrt {\frac {\ln (1 6 t / \delta)}{2 n}}.
$$
Next we upper bound  $\mathbb{E}\left[\Gamma^{\mathcal{B}}(\widehat{\mathcal{D}}_i)\right]$ , by similar analysis as in the proof of Theorem 3.1, we have: with probability at least  $1 - \frac{\delta}{16t}$
$$
\underset {\widehat {\mathcal {D}} _ {i}} {\mathbb {E}} \left[ \Gamma^ {\mathcal {B}} (\widehat {\mathcal {D}} _ {i}) \right] \leq \Re_ {n} (\widetilde {\mathcal {G}}) + U \sqrt {\frac {\ln (1 6 t / \delta)}{2 n}}.
$$
Then with probability at least  $1 - \frac{\delta}{8t}$ ,
$$
\sup _ {h \in \mathcal {H}} \left(\mathcal {R} _ {\mathcal {D} _ {i}} ^ {\mathcal {B}} (\ell , h) - \mathcal {R} _ {\widehat {\mathcal {D}} _ {i}} ^ {\mathcal {B}} (\ell , h)\right) = \Gamma^ {\mathcal {B}} (\widehat {\mathcal {D}} _ {i}) \leq 2 \Re_ {n} (\widetilde {\mathcal {G}}) + 3 U \sqrt {\frac {\ln (1 6 t / \delta)}{2 n}}.
$$
With similar argument, we know that with probability at least  $1 - \frac{\delta}{8t}$ ,
$$
\sup  _ {h \in \mathcal {H}} \left(\mathcal {R} _ {\widehat {\mathcal {D}} _ {i}} ^ {\mathcal {B}} (\ell , h) - \mathcal {R} _ {\mathcal {D} _ {i}} ^ {\mathcal {B}} (\ell , h)\right) \leq 2 \mathfrak {R} _ {n} (\widetilde {\mathcal {G}}) + 3 U \sqrt {\frac {\ln (1 6 t / \delta)}{2 n}}.
$$
So with probability at least  $1 - \frac{\delta}{4t}$ ,
$$
d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (\widehat {\mathcal {D}} _ {j}, \mathcal {D} _ {j}) = \sup  _ {h \in \mathcal {H}} \left| \mathcal {R} _ {\mathcal {D} _ {i}} ^ {\mathcal {B}} (\ell , h) - \mathcal {R} _ {\widehat {\mathcal {D}} _ {i}} ^ {\mathcal {B}} (\ell , h) \right| \leq 2 \Re_ {n} (\widetilde {\mathcal {G}}) + 3 U \sqrt {\frac {\ln (1 6 t / \delta)}{2 n}}.
$$
So with probability at least  $1 - \frac{\delta}{4}$ ,
$$
d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} \left(\mathcal {T} _ {P}, \widehat {\mathcal {T}} _ {P}\right) \leq \sum_ {j = 1} ^ {t} \lambda_ {j} ^ {\star} d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} \left(\widehat {\mathcal {D}} _ {j}, \mathcal {D} _ {j}\right) \leq 2 \Re_ {n} (\widetilde {\mathcal {G}}) + 3 U \sqrt {\frac {\ln (1 6 t / \delta)}{2 n}}. \tag {A.10}
$$
Now combine (A.7), (A.8), (A.9) and (A.10), we have: with probability at least  $1 - \delta$ , for any  $h \in \mathcal{H}$
$$
\begin{array}{l} \mathcal {R} _ {\mathcal {T}} ^ {\mathcal {B}} (\ell , h) \leq \mathcal {R} _ {\mathcal {D}} ^ {\mathcal {B}} (\ell , h) + d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (\mathcal {T}, \mathcal {T} _ {P}) + d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (\mathcal {T} _ {P}, \widehat {\mathcal {T}} _ {P}) + d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (\widehat {\mathcal {D}}, \bar {\mathcal {D}}) + \frac {1}{t} \sum_ {i} \sum_ {j} \lambda_ {j} ^ {\star} d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (\widehat {\mathcal {D}} _ {i}, \widehat {\mathcal {D}} _ {j}) \\ \leq \frac {1}{t} \sum_ {i = 1} ^ {t} \mathcal {R} _ {\widehat {\mathcal {D}} _ {i}} ^ {\mathcal {B}} (\ell , h) + 2 \Re_ {t n} (\widetilde {\mathcal {G}}) + 3 U \sqrt {\frac {\ln 8 / \delta}{2 t n}} + d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (\mathcal {T}, \mathcal {T} _ {P}) + 2 \Re_ {n} (\widetilde {\mathcal {G}}) \\ + 3 U \sqrt {\frac {\ln (1 6 t / \delta)}{2 n}} + 2 \Re_ {t n} (\widetilde {\mathcal {G}}) + 3 U \sqrt {\frac {\ln 8 / \delta}{2 t n}} + \frac {1}{t} \sum_ {i} \sum_ {j} \lambda_ {j} ^ {\star} d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (\widehat {\mathcal {D}} _ {i}, \widehat {\mathcal {D}} _ {j}) \\ = \frac {1}{t} \sum_ {i = 1} ^ {t} \mathcal {R} _ {\widehat {\mathcal {D}} _ {i}} ^ {\mathcal {B}} (\ell , h) + \frac {1}{t} \sum_ {i} \sum_ {j} \lambda_ {j} ^ {\star} d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (\widehat {\mathcal {D}} _ {i}, \widehat {\mathcal {D}} _ {j}) + d _ {\ell (\mathcal {H})} ^ {\mathcal {B}} (\mathcal {T}, \mathcal {T} _ {P}) + 4 \Re_ {t n} (\widetilde {\mathcal {G}}) \\ + 2 \Re_ {n} (\widetilde {\mathcal {G}}) + 6 U \sqrt {\frac {\ln 8 / \delta}{2 t n}} + 3 U \sqrt {\frac {\ln (1 6 t / \delta)}{2 n}}. \\ \end{array}
$$
B Toy Example to Model the ColoredMNIST
Example 2. Consider data point  $(\pmb{x},y)$ , where  $\pmb{x} \in \mathcal{X} \subseteq \mathbb{R}^{d+1}$  consists of invariant feature  $\pmb{x}_{\mathrm{inv}} \in \mathcal{X}_{\mathrm{inv}} \subseteq \mathbb{R}^d$  and spuriously correlated feature  $x_{\mathrm{sp}} \in \{\pm s\} \subsetneq \mathbb{R}$ , to simplify the example, let  $\pmb{x} =$
$(\pmb{x}_{\mathrm{inv}},x_{\mathrm{sp}})$  be the feature observed. Consider the case there is a linear classifier  $h(\pmb{x}_{\mathrm{inv}}) = \pmb{w}_{\mathrm{inv}}\cdot \pmb{x}_{\mathrm{inv}}$  such that  $y\cdot h(\pmb{x}_{\mathrm{inv}}) > 0$ , i.e.,  $\pmb{x}_{\mathrm{inv}}$  is invariant for all distributions on  $\mathcal{X}_{\mathrm{inv}}\times \{\pm 1\}$ . Suppose the dataset  $S = \{(x_i,y_i)\}_{i = 1}^n$  is linearly separable, and the dataset  $S$  is induced into two disjoint groups: a majority group  $S_{\mathrm{maj}}$  where  $x_{\mathrm{sp}}\cdot y > 0$  and a minority group  $S_{\mathrm{min}}$  where  $x_{\mathrm{sp}}\cdot y < 0$ , let  $p = \mathbb{P}[x_{\mathrm{sp}}\cdot y > 0] > 0.5$ , which means that the spurious feature is positively related to the label  $y$ .
The next theorem considers the degree of dependence on the spurious feature of the trained linear classifier.
Theorem B.1 (Theorem 4 of [48]). Let  $\mathbb{H}$  be the set for linear classifiers,  $h(\pmb{x}) = \pmb{w}_{inv} \pmb{x}_{inv} + w_{sp} x_{sp}$ . Consider any task that satisfies all the constraints in Section 3.1 of [48]. Consider a dataset  $S$  drawn from  $\mathcal{D}$  such that the empirical distribution of  $\pmb{x}_{inv}$  given  $x_{sp} \cdot y > 0$  is identical to the empirical distribution of  $\pmb{x}_{inv}$  given  $x_{sp} \cdot y < 0$ . Let  $\pmb{w}_{inv}(t) \pmb{x}_{inv} + w_{sp} x_{sp}$  be initialized to the origin, and trained with an infinitesimal learning rate gradient descent to minimize the exponential loss on a dataset  $S$ . Then, for any  $(\pmb{x}, y) \in S$ , we have:
$$
\Omega \left(\frac {\ln \frac {c + p}{c + \sqrt {p (1 - p)}}}{\mathcal {M} \ln (t + 1)}\right) \leq \frac {w _ {s p} (t) s}{| \boldsymbol {w} _ {i n v} (t) \cdot \boldsymbol {x} _ {i n v} |} \leq \mathcal {O} \left(\frac {\ln \frac {p}{1 - p}}{\ln (t + 1)}\right),
$$
1.  $p$  denotes the empirical level of spurious correlation,  $p = \frac{1}{|S|} \sum_{(\boldsymbol{x},y) \in S} \mathbf{1}[x_{sp} \cdot y > 0]$  which without generality is assumed to satisfy  $p \in [0.5, 1)$ .
2.  $\mathcal{M}$  denotes the maximum value of the margin of the max-margin classifier on  $S$ , i.e.,  $\mathcal{M} = \max_{\boldsymbol{x} \in S} \hat{\boldsymbol{w}} \cdot \boldsymbol{x}$  where  $\hat{\boldsymbol{w}}$  is the max-margin classifier on  $S$ .
3.  $c\coloneqq \frac{2(2\mathcal{M} - 1)}{s^2}$
Remark 4. In the proof of Theorem B.1 (please refer to [48]), the loss function is:
$$
L \left(\boldsymbol {w} _ {\text {i n v}}, w _ {s p}\right) = p \mathbb {E} _ {\boldsymbol {x} _ {\text {i n v}} \sim \hat {D} _ {\text {i n v}}} \left[ e ^ {- \left(\boldsymbol {w} _ {\text {i n v}} \boldsymbol {x} _ {\text {i n v}} + w _ {s p} s\right)} \right] + (1 - p) \mathbb {E} _ {\boldsymbol {x} _ {\text {i n v}} \sim \hat {D} _ {\text {i n v}}} \left[ e ^ {- \left(\boldsymbol {w} _ {\text {i n v}} \boldsymbol {x} _ {\text {i n v}} - w _ {s p} s\right)} \right]. \tag {B.11}
$$
We denote  $L_{1} = \mathbb{E}_{\pmb{x}_{inv}\sim \hat{D}_{inv}}\left[e^{-(\pmb{w}_{inv},\pmb{x}_{inv} + w_{sp}s)}\right]$  and  $L_{2} = \mathbb{E}_{\pmb{x}_{inv}\sim \hat{D}_{inv}}\left[e^{-(\pmb{w}_{inv},\pmb{x}_{inv} - w_{sp}s)}\right]$ , so  $L = pL_{1} + (1 - p)L_{2}$ . To model the case in the ColoredMNIST dataset, we let  $S_{1}$  denote the dataset with corruption rate 0.1,  $S_{2}$  the dataset with corruption rate 0.2,  $S_{3}$  the dataset with corruption rate 0.9. For training environment with corruption rate  $p_{train}$ , we have  $L_{train} = p_{train}L_{1} + (1 - p_{train})L_{2}$  and  $L_{test} = p_{test}L_{1} + (1 - p_{test})L_{2}$  if  $p_{train} > 0.5$ . Otherwise we have  $L_{train} = p_{train}L_{2} + (1 - p_{train})L_{1}$  and  $L_{test} = p_{test}L_{2} + (1 - p_{test})L_{1}$ . What's more, since the lower bound  $> 0$  for  $p > \frac{1}{2}$ , we have  $L_{1} < L_{2}$ . So in the standard training case: