SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Leonidas Tsepenekas
JPMorganChase AI Research
New York, USA
leonidas.tsepenekas@jpmchase.com
Ivan Brugere
ivan.brugere@jpmchase.com
Freddy Lecue
freddy. lecue@jpmchase.com
Daniele Maggazeni
daniele.magazzeni@jpmorgan.com
Similarity functions measure how comparable pairs of elements are, and play a key role in a wide variety of applications, e.g., notions of Individual Fairness abiding by the seminal paradigm of Dwork et al. [2012], as well as Clustering problems. However, access to an accurate similarity function should not always be considered guaranteed, and this point was even raised by Dwork et al. [2012]. For instance, it is reasonable to assume that when the elements to be compared are produced by different distributions, or in other words belong to different "demographic" groups, knowledge of their true similarity might be very difficult to obtain. In this work, we present an efficient sampling framework that learns these across-groups similarity functions, using only a limited amount of experts' feedback. We show analytical results with rigorous theoretical bounds, and empirically validate our algorithms via a large suite of experiments.
Given a feature space  $\mathcal{I}$ , a similarity function  $\sigma : \mathcal{I}^2 \mapsto \mathbb{R}_{\geq 0}$  measures how comparable any pair of elements  $x, x' \in \mathcal{I}$  are. The function  $\sigma$  can also be interpreted as a distance function, where the smaller  $\sigma(x, x')$  is, the more similar  $x$  and  $x'$  are. Such functions are crucially used in a variety of AI/ML problems, and in each such case  $\sigma$  is assumed to be known.
The most prominent applications where similarity functions have a central role involve considerations of individual fairness. Specifically, all such individual fairness paradigms stem from the seminal work of Dwork et al. [2012], in which fairness is defined as treating similar individuals similarly. In more concrete terms, such paradigms interpret the aforementioned abstract definition of fairness as guaranteeing that for every pair of individuals  $x$  and  $y$ , the difference in the quality of service  $x$  and  $y$  receive (a.k.a. their received treatment) is upper bounded by their respective similarity value  $\sigma(x, y)$ ; the more similar the individuals are, the less different their quality of service will be. Therefore, any algorithm that needs to abide by such concepts of fairness, should always be able to access the similarity score for every pair of individuals that are of interest.
Another family of applications where similarity functions are vital, involves Clustering problems. In a clustering setting, e.g., the standard  $k$ -means task, the similarity function is interpreted as a distance
function, that serves as the metric space in which we need to create the appropriate clusters. Clearly, the aforementioned metric space is always assumed to be part of the input.
Nonetheless, it is not realistic to assume that a reliable and accurate similarity function is always given. This issue was even raised in the work of Dwork et al. [2012], where it was acknowledged that the computation of  $\sigma$  is not trivial, and thus should be deferred to third parties. The starting point of our work here is the observation that there exist scenarios where computing similarity can be assumed as easy (in other words given), while in other cases this task would be significantly more challenging. Specifically, we are interested in scenarios where there are multiple distributions that produce elements of  $\mathcal{I}$ . We loosely call each such distribution a "demographic" group, interpreting it as the stochastic way in which members of this group are produced. In this setting, computing the similarity value of two elements that are produced according to the same distribution, seems intuitively much easier compared to computing similarity values for elements belonging to different groups. We next present a few motivating examples that clarify this statement.
Individual Fairness: Consider a college admissions committee that needs access to an accurate similarity function for students, so that it provides a similar likelihood of acceptance to similar applicants. Let us focus on the following two demographic groups. The first being students from affluent families living in privileged communities and having access to the best quality schools and private tutoring. The other group would consist of students from low-income families, coming from a far less privileged background. Given this setting, the question at hand is "Should two students with comparable feature vectors (e.g., SAT scores, strength of school curriculum, number of recommendation letters) be really viewed as similar, when they belong to different groups?" At first, it appears that directly comparing two students based on their features can be an accurate way to elicit their similarity only if the students belong to the same demographic (belonging to the same group serves as a normalization factor). However, this trivial approach might hurt less privileged students when they are compared to students of the first group. This is because such a simplistic way of measuring similarity does not reflect potential that is undeveloped due to unequal access to resources. Hence, accurate across-groups comparisons that take into account such delicate issues, appear considerably more intricate.
Clustering: Suppose that a marketing company has a collection of user data that wants to cluster, with its end goal being a downstream market segmentation analysis. However, as it is usually the case, the data might come from different sources, e.g., data from private vendors and data from government bureaus. In this scenario, each data source might have its own way of representing user information, e.g., each source might use a unique subset of features. Therefore, eliciting the distance metric required for the clustering task should be straightforward for data coming from the same source, while across-sources distances would certainly require extra care, e.g., how can one extract the distance of two vectors containing different sets of features?
As suggested by earlier work on computing similarity functions for applications of individual fairness [Ilvento, 2019], when obtaining similarity values is an overwhelming task, one can employ the advice of domain experts. Such experts can be given any pair of elements, and in return produce their true similarity value. However, utilizing this experts' advice can be thought of as very costly, and hence it should be used sparingly. For example, in the case of comparing students from different economic backgrounds, the admissions committee can reach out to regulatory bodies or civil rights organizations. Nonetheless, resorting to these experts for every student comparison that might arise, is clearly not a sustainable solution. Therefore, our goal in this paper is to learn the across-groups similarity functions, using as few queries to experts as possible.
2 Preliminaries and contribution
For the ease of exposition, we accompany the formal definitions with brief demonstrations on how they could relate to the previously mentioned college applications use-case.
Let  $\mathcal{I}$  denote the feature space of elements; for instance each  $x\in \mathcal{I}$  could correspond to a valid student profile. We assume that elements come from  $\gamma$  known "demographic" groups, where  $\gamma \in \mathbb{N}$ , and each group  $\ell \in [\gamma ]$  is governed by an unknown distribution  $\mathcal{D}_{\ell}$  over  $\mathcal{I}$ . We use  $x\sim \mathcal{D}_{\ell}$  to denote a randomly drawn  $x$  from  $\mathcal{D}_{\ell}$ . Further, we use  $x\in \mathcal{D}_{\ell}$  to denote that  $x$  is an element in the support of  $\mathcal{D}_{\ell}$ , and thus  $x$  is a member of group  $\ell$ . In the college admissions scenario where we have two demographic groups, there will be two distributions  $\mathcal{D}_1$  and  $\mathcal{D}_2$  dictating how the profiles of
privileged and non-privileged students are respectively produced. Observe now that for a specific  $x \in \mathcal{I}$ , we might have  $x \in \mathcal{D}_{\ell}$  and  $x \in \mathcal{D}_{\ell'}$ , for  $\ell \neq \ell'$ . Hence, in our model group membership is important, and every time we are considering an element  $x \in \mathcal{I}$ , we know which distribution produced  $x$ , e.g., whether the profile  $x$  belongs to a privileged or non-privileged student.
For every group  $\ell \in [\gamma]$  there is an intra-group similarity function  $d_{\ell}:\mathcal{I}^{2}\mapsto \mathbb{R}_{\geq 0}$ , such that for all  $x,y\in \mathcal{D}_{\ell}$  we have  $d_{\ell}(x,y)$  representing the true similarity between  $x,y$ . In addition, the smaller  $d_{\ell}(x,y)$  is, the more similar  $x,y$ . Note here that the function  $d_{\ell}$  is only used to compare members of group  $\ell$  (in the college admissions example, the function  $d_{1}$  would only be used to compare privileged students with each other). Further, a common assumption for functions measuring similarity is that they are metric[1] [Yona and Rothblum, 2018, Kim et al., 2018, Ilvento, 2019, Mukherjee et al., 2020, Wang et al., 2019]. We also adopt the metric assumption for the function  $d_{\ell}$ . Finally, based on the earlier discussion regarding computing similarity between elements of the same group, we assume that  $d_{\ell}$  is known, and given as part of the instance.
Moreover, for any two groups  $\ell$  and  $\ell'$  there exists an unknown across-groups similarity function  $\sigma_{\ell,\ell'}: \mathcal{I}^2 \mapsto \mathbb{R}_{\geq 0}$ , such that for all  $x \in \mathcal{D}_{\ell}$  and  $y \in \mathcal{D}_{\ell'}$ ,  $\sigma_{\ell,\ell'}(x,y)$  represents the true similarity between  $x,y$ . Again, the smaller  $\sigma_{\ell,\ell'}(x,y)$  is, the more similar the two elements, and for a meaningful use of  $\sigma_{\ell,\ell'}$  we must make sure that  $x$  is a member of group  $\ell$  and  $y$  a member of group  $\ell'$ . In the college admissions scenario,  $\sigma_{1,2}$  is the way you can accurately compare a privileged and a non-privileged student. Finally, to capture the metric nature of a similarity function, we impose the following mild properties on  $\sigma_{\ell,\ell'}$ , which can be viewed as across-groups triangle inequalities:
1. Property  $\mathcal{M}_1$ :  $\sigma_{\ell, \ell'}(x, y) \leq d_\ell(x, z) + \sigma_{\ell, \ell'}(z, y)$  for every  $x, z \in \mathcal{D}_\ell$  and  $y \in \mathcal{D}_{\ell'}$ .
2. Property  $\mathcal{M}_2$ :  $\sigma_{\ell, \ell'}(x, y) \leq \sigma_{\ell, \ell'}(x, z) + d_{\ell'}(z, y)$  for every  $x \in \mathcal{D}_{\ell}$  and  $y, z \in \mathcal{D}_{\ell'}$ .
In terms of the college admissions use-case,  $\mathcal{M}_1$  and  $\mathcal{M}_2$  try to capture reasonable assumptions of the following form. If a non-privileged student  $x$  is similar to another non-privileged student  $z$ , and  $z$  is similar to a privileged student  $y$ , then  $x$  and  $y$  should also be similar to each other.
Observe now that the collection of all similarity values (intra-group and across-groups) in our model does not axiomatically yield a valid metric space. This is due to the following reasons. 1) If  $\sigma_{\ell, \ell'}(x, y) = 0$  for  $x \in \mathcal{D}_{\ell}$  and  $y \in \mathcal{D}_{\ell'}$ , then we do not necessarily have  $x = y$ . 2) It is not always the case that  $d_{\ell}(x, y) \leq \sigma_{\ell, \ell'}(x, z) + \sigma_{\ell, \ell'}(y, z)$  for  $x, y \in \mathcal{D}_{\ell}, z \in \mathcal{D}_{\ell'}$ . 3) It is not always the case that  $\sigma_{\ell, \ell'}(x, y) \leq \sigma_{\ell, \ell''}(x, z) + \sigma_{\ell'', \ell'}(z, y)$  for  $x \in \mathcal{D}_{\ell}, y \in \mathcal{D}_{\ell'}, z \in \mathcal{D}_{\ell''}$ .
However, not having the collection of similarity values necessarily produce a metric space is not a weakness of our model. On the contrary, we view this as one of its strongest aspects. For one thing, imposing a complete metric constraint on the case of intricate across-groups comparisons sounds unrealistic and very restrictive. Further, even though existing literature treats similarity functions as metric ones, the seminal work of Dwork et al. [2012] mentions that this should not always be the case. Hence, our model is more general than the current literature.
Goal of Our Problem: We want for any two groups  $\ell, \ell'$  to compute a function  $f_{\ell, \ell'}: \mathcal{I}^2 \mapsto \mathbb{R}_{\geq 0}$ , such that  $f_{\ell, \ell'}(x, y)$  is our estimate of similarity for any  $x \in \mathcal{D}_{\ell}$  and  $y \in \mathcal{D}_{\ell'}$ . Specifically, we seek a PAC (Probably Approximately Correct) guarantee, where for any given accuracy and confidence parameters  $\epsilon, \delta \in (0,1)$  we have:
$$
\operatorname * {P r} _ {x \sim \mathcal {D} _ {\ell}, y \sim \mathcal {D} _ {\ell^ {\prime}}} \left[ | f _ {\ell , \ell^ {\prime}} (x, y) - \sigma_ {\ell , \ell^ {\prime}} (x, y) | > \epsilon \right] \leq \delta
$$
The subscript in the above probability corresponds to two independent random choices, one  $x \sim \mathcal{D}_{\ell}$  and one  $y \sim \mathcal{D}_{\ell'}$ . In other words, we want for any given pair our estimate to be  $\epsilon$ -close to the real similarity value, with probability at least  $1 - \delta$ , where  $\epsilon$  and  $\delta$  are user-specified parameters.
As for tools to learn  $f_{\ell, \ell'}$ , we only require two things. At first, for each group  $\ell$  we want a set  $S_{\ell}$  of i.i.d. samples from  $\mathcal{D}_{\ell}$ . Obviously, the total number of used samples should be polynomial in the input parameters, i.e., polynomial in  $\gamma$ ,  $\frac{1}{\epsilon}$  and  $\frac{1}{\delta}$ . Secondly, we require access to an expert oracle, which given any  $x \in S_{\ell}$  and  $y \in S_{\ell'}$  for any  $\ell$  and  $\ell'$ , returns the true similarity value  $\sigma_{\ell, \ell'}(x, y)$ . We refer to a single invocation of the oracle as a query. Since there is a cost to collecting expert feedback, an additional objective in our problem is minimizing the number of oracle queries.
$^1$ A function  $d$  is metric if a)  $d(x,y) = 0$  iff  $x = y$ , b)  $d(x,y) = d(y,x)$  and c)  $d(x,y) \leq d(x,z) + d(z,y)$  for all  $x,y,z$  (triangle inequality).
2.1 Outline and discussion of our results
In Section 4 we present our theoretical results. We begin with a simple and very intuitive learning algorithm which achieves the following guarantees.
Theorem 2.1. For any given parameters  $\epsilon, \delta \in (0,1)$ , the simple algorithm produces a similarity approximation function  $f_{\ell,\ell'}$  for every  $\ell$  and  $\ell'$ , such that:
$$
\begin{array}{l} \operatorname *{Pr}[Error_{(\ell ,\ell^{\prime})}]:= \operatorname *{Pr}_{\substack{x\sim \mathcal{D}_{\ell},\\ y\sim \mathcal{D}_{\ell^{\prime}},  \mathcal{A}}}\left[|f_{\ell ,\ell^{\prime}}(x,y) - \sigma_{\ell ,\ell^{\prime}}(x,y)| = \omega (\epsilon)\right] \\ = O \left(\delta + p _ {\ell} (\epsilon , \delta) + p _ {\ell^ {\prime}} (\epsilon , \delta)\right) \\ \end{array}
$$
The randomness here is of three independent sources. The internal randomness  $\mathcal{A}$  of the algorithm, a choice  $x\sim \mathcal{D}_{\ell}$ , and a choice  $y\sim \mathcal{D}_{\ell^{\prime}}$ . The algorithm requires  $\frac{1}{\delta}\log \frac{1}{\delta^2}$  samples from each group, and utilizes  $\frac{\gamma(\gamma - 1)}{\delta^2}\log^2\frac{1}{\delta^2}$  oracle queries.
In plain English, the above theorem says that with a polynomial number of samples and queries, the algorithm achieves an  $O(\epsilon)$  accuracy with high probability, i.e., with probability  $\omega \left(1 - \delta - p_{\ell}(\epsilon, \delta) - p_{\ell'}(\epsilon, \delta)\right)$ . The definition of the functions  $p_{\ell}$  is presented next.
Definition 2.2. For each group  $\ell$ , we use  $p_{\ell}(\epsilon, \delta)$  to denote the probability of sampling an  $(\epsilon, \delta)$ -rare element of  $\mathcal{D}_{\ell}$ . We define as  $(\epsilon, \delta)$ -rare for  $\mathcal{D}_{\ell}$ , an element  $x \in \mathcal{D}_{\ell}$  for which there is a less than  $\delta$  chance of sampling  $x' \sim \mathcal{D}_{\ell}$  with  $d_{\ell}(x, x') \leq \epsilon$ . Formally,  $x \in \mathcal{D}_{\ell}$  is  $(\epsilon, \delta)$ -rare iff  $\operatorname{Pr}_{x' \sim \mathcal{D}_{\ell}}[d_{\ell}(x, x') \leq \epsilon] < \delta$ , and  $p_{\ell}(\epsilon, \delta) = \operatorname{Pr}_{x \sim \mathcal{D}_{\ell}}[x$  is  $(\epsilon, \delta)$ -rare for  $\mathcal{D}_{\ell}$ . Intuitively, a rare element should be interpreted as an "isolated" member of the group, in the sense that it is at most  $\delta$ -likely to encounter another element that is  $\epsilon$ -similar to it. For instance, a privileged student is considered isolated, if only a small fraction of other privileged students have a profile similar to them.
Clearly, to get a PAC guarantee where the algorithm's error probability for  $\ell$  and  $\ell'$  is  $O(\delta)$ , we need  $p_{\ell}(\epsilon, \delta), p_{\ell'}(\epsilon, \delta) = O(\delta)$ . We hypothesize that in realistic distributions each  $p_{\ell}(\epsilon, \delta)$  should indeed be fairly small, and this hypothesis is actually validated by our experiments. The reason we believe this hypothesis to be true, is that very frequently real data demonstrate high concentration around certain archetypal elements. Hence, this sort of distributional density does not leave room for isolated elements in the rest of the space. Nonetheless, we also provide a strong no free lunch result for the values  $p_{\ell}(\epsilon, \delta)$ , which shows that any practical PAC-algorithm necessarily depends on them. This result further implies that our algorithm's error probabilities are indeed almost optimal.
Theorem 2.3 (No-Free Lunch Theorem). For any given  $\epsilon, \delta \in (0,1)$ , any algorithm using finitely many samples, will yield similarity approximations  $f_{\ell,\ell'}$  with  $\operatorname*{Pr}\left[|f_{\ell,\ell'}(x,y) - \sigma_{\ell,\ell'}(x,y)| = \omega(\epsilon)\right] = \Omega(\max\{p_{\ell}(\epsilon,\delta), p_{\ell'}(\epsilon,\delta)\} - \epsilon)$ ; the probability is over the independent choices  $x \sim \mathcal{D}_{\ell}$  and  $y \sim \mathcal{D}_{\ell}'$  as well as any potential internal randomness of the algorithm.
In plain English, Theorem 2.3 says that any algorithm using a finite amount of samples, can achieve  $\epsilon$ -accuracy with a probability that is necessarily at most  $1 - \max \{p_{\ell}(\epsilon, \delta), p_{\ell'}(\epsilon, \delta)\} + \epsilon$ , i.e., if  $\max \{p_{\ell}(\epsilon, \delta), p_{\ell'}(\epsilon, \delta)\}$  is large, learning is impossible.
Moving on, we focus on minimizing the oracle queries. By carefully modifying the earlier simple algorithm, we obtain a new more intricate algorithm with the following guarantees:
Theorem 2.4. For any given parameters  $\epsilon, \delta \in (0,1)$ , the query-minimizing algorithm produces similarity approximation functions  $f_{\ell,\ell'}$  for every  $\ell$  and  $\ell'$ , such that:
$$
\Pr \left[ E r r o r _ {(\ell , \ell^ {\prime})} \right] = O (\delta + p _ {\ell} (\epsilon , \delta) + p _ {\ell^ {\prime}} (\epsilon , \delta))
$$
$\operatorname{Pr}[Error_{(\ell, \ell')}]$  is as defined in Theorem 2.1. Let  $N = \frac{1}{\delta} \log \frac{1}{\delta^2}$ . The algorithm requires  $N$  samples from each group, and the number of oracle queries used is at most
$$
\sum_ {\ell \in [ \gamma ]} \left(Q _ {\ell} \sum_ {\ell^ {\prime} \in [ \gamma ]: \ell^ {\prime} \neq \ell} Q _ {\ell^ {\prime}}\right)
$$
where  $Q_{\ell}\leq N$  and  $\mathbb{E}[Q_{\ell}]\leq \frac{1}{\delta} +p_{\ell}(\epsilon ,\delta)N$  for each  $\ell$
At first, the confidence, accuracy and sample complexity guarantees of the new algorithm are the same as those of the simpler one described in Theorem 2.1. Furthermore, because  $Q_{\ell} \leq N$ , the
queries of the improved algorithm are at most  $\gamma (\gamma -1)N$ , which is exactly the number of queries in our earlier simple algorithm. However, the smaller the values  $p_{\ell}(\epsilon ,\delta)$  are, the fewer queries in expectation. Our experimental results indeed confirm that the improved algorithm always leads to a significant decrease in the used queries.
Our final theoretical result involves a lower bound on the number of queries required for learning.
Theorem 2.5. For all  $\epsilon, \delta \in (0,1)$ , any learning algorithm producing similarity approximation functions  $f_{\ell,\ell'}$  with  $\operatorname{Pr}_{x \sim \mathcal{D}_{\ell},y \sim \mathcal{D}_{\ell'}}\left[|f_{\ell,\ell'}(x,y) - \sigma_{\ell,\ell'}(x,y)| = \omega(\epsilon)\right] = O(\delta)$ , needs  $\Omega\left(\frac{\gamma^2}{\delta^2}\right)$  queries.
Combining Theorems 2.4 and 2.5 implies that when all  $p_{\ell}(\epsilon, \delta)$  are negligible, i.e.,  $p_{\ell}(\epsilon, \delta) \to 0$ , the expected queries of the Theorem 2.4 algorithm are asymptotically optimal.
Finally, Section 5 contains our experimental evaluation, where through a large suite of simulations we validate our theoretical findings.
Metric learning is a very well-studied area [Bellet et al., 2013, Kulis, 2013, Moutafis et al., 2017, Suárez-Díaz et al., 2018]. There is also an extensive amount of work on using human feedback for learning metrics in specific tasks, e.g., image similarity and low-dimensional embeddings [Frome et al., 2007, Jamieson and Nowak, 2011, Tamuz et al., 2011, van der Maaten and Weinberger, 2012, Wilber et al., 2014]. However, since these works are either tied to specific applications or specific metrics, they are only distantly related to ours.
Our model is more closely related to the literature on trying to learn the similarity function from the fairness definition of Dwork et al. [2012]. This concept of fairness requires treating similar individuals similarly. Thus, it needs access to a function that returns a non-negative value for any pair of individuals, and this value corresponds to how similar the individuals are. Specifically, the smaller the value the more similar the elements that are compared. Even though the fairness definition of Dwork et al. [2012] is very elegant and intuitive, the main obstacle for adopting it in practice is the inability to easily compute or access the crucial similarity function. To our knowledge, the only papers that attempt to learn this similarity function using expert oracles like us, are Ilvento [2019], Mukherjee et al. [2020] and Wang et al. [2019]. Ilvento [2019] addresses the scenario of learning a general metric function, and gives theoretical PAC guarantees. Mukherjee et al. [2020] give theoretical guarantees for learning similarity functions that are only of a specific Mahalanobis form. Wang et al. [2019] simply provide empirical results. The first difference between our model and these papers is that unlike us, they do not consider elements coming from multiple distributions. However, the most important difference is that these works only learn metric functions. In our case the collection of similarity values (from all  $d_{\ell}$  and  $\sigma_{\ell,\ell'}$ ) does not necessarily yield a complete metric space; see the discussion in Section 2. Hence, our problem addresses more general functions.