SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Indradyumna Roy† Rishi Agarwal†
Soumen Chakrabarti† Anirban Dasgupta $^{\diamond}$  Abir De $^{\dagger}$
IIT Bombay, IIT Gandhinagar
{indraroy15, rishiagarwal18, soumen, abir}@cse.iitb.ac.in
anirbandg@cse.iitgn.ac.in
In many search applications related to passage retrieval, text entailment, and subgraph search, the query and each 'document' is a set of elements, with a document being relevant if it contains the query. These elements are not represented by atomic IDs, but by embedded representations, thereby extending set containment to soft set containment. Recent applications address soft set containment by encoding sets into fixed-size vectors and checking for elementwise vector dominance. This 0/1 property can be relaxed to an asymmetric hinge distance for scoring and ranking candidate documents. Here we focus on data-sensitive, trainable indices for fast retrieval of relevant documents. Existing LSH methods are designed for mostly symmetric or few simple asymmetric distance functions, which are not suitable for hinge distance. Instead, we transform hinge distance into a proposed dominance similarity measure, to which we then apply a Fourier transform, thereby expressing dominance similarity as an expectation of inner products of functions in the frequency domain. Next, we approximate the expectation with an importance-sampled estimate. The overall consequence is that now we can use a traditional LSH, but in the frequency domain. To ensure that the LSH uses hash bits efficiently, we learn hash functions that are sensitive to both corpus and query distributions, mapped to the frequency domain. Our experiments show that the proposed asymmetric dominance similarity is critical to the targeted applications, and that our LSH, which we call FOURIERHASHNET, provides a better query time vs. retrieval quality trade-off, compared to several baselines. Both the Fourier transform and the trainable hash codes contribute to performance gains.
Consider a corpus  $X$  of sets  $x$  (which we call 'documents') over some universe of discrete items, and let  $q$  be a query which is also a subset of this universe. We wish to retrieve those  $x \in X$  which satisfy  $q \subseteq x$ . In most real-world applications, the items in the universe are not just opaque IDs, but are embedded in a rich feature space, demanding that the definition of " $q \subseteq x$ " be generalized suitably.
We formalize the notion of soft set containment by writing  $q = \{q_i\}$  and  $x = \{x_i\}$  and the corresponding sets of item embeddings as  $\{\vec{q}_i\}$  and  $\{\vec{x}_i\}$ . If  $q, x$  are sentences,  $\vec{q}_i, \vec{x}_i$  may be perword contextual embeddings output from a transformer. If  $q, x$  are graphs,  $\vec{q}_i, \vec{x}_i$  may be contextual node embeddings, such as those output by a Graph Neural Network (GNN). These set-of-vector representations of  $q$  and  $x$  are generally of variable sizes. A suitable set encoding gadget, such as simple pooling [41, 31] or a trainable Deep Set [60] or Set Transformer [27] network, converts them to fixed-size vectors given by  $\mathbf{q} = \mathrm{SetEnc}(\{\vec{q}_i\})$  and  $\mathbf{x} = \mathrm{SetEnc}(\{\vec{x}_i\})$ , with  $\mathbf{x}, \mathbf{q} \in \mathbb{R}^K$ . Several applications [52, 26, 10, 31] then use the test "  $\mathbf{q} \leq \mathbf{x}$ " (elementwise vector dominance) as a surrogate for testing if  $q \subseteq x$ .
To convert the Boolean test for vector dominance,  $q \leq x$ , into a graded score suitable for ranking (and backpropagation), these applications [52, 26, 10, 31] use a form of (asymmetric) hinge distance
$$
d (q, x) = \left\| [ \boldsymbol {q} - \boldsymbol {x} ] _ {+} \right\| _ {1} = \sum_ {k} \max  \{0, \boldsymbol {q} [ k ] - \boldsymbol {x} [ k ] \}. \tag {1}
$$
$d(q, x) = 0$  when  $q \leq x$  holds elementwise, and measures the extent of the constraint violation otherwise. A search system must retrieve the top- $\tau$  documents  $x$  with the smallest  $d(q, x)$ , given query  $q$ . Several example applications that fit into this framework are elaborated in Appendix B. Even if an application does not fit (1) exactly, our technique may help address other asymmetric distances.
Our goal When corpus  $X$  is large, it is impractical to evaluate (1) for each document  $x$ . Our goal is to retrieve these  $\tau$  documents without explicitly evaluating  $d(q, x)$  for all  $x \in X$ , within query time that scales slowly with  $|X|$ . To achieve this, we design an asymmetric Locality Sensitive Hashing (ALSH) method tailored for hinge distance (1), which then immediately addresses soft set-containment based search.
Prior work and their limitations When set elements are represented by atomic IDs, Bloom filters [36] and maximum inner product search (MIPS) can be used to find the best  $\tau$  corpus items that are closest to being supersets [46, 59, 45, 2]. However, these techniques are designed specifically for items with opaque IDs, rather than contextual embeddings. LSH [7, 53, 17, 19, 1] has been established as a standard technique for fast approximate near-neighbor search (e.g., FAISS, DPR) in the space of contextual embeddings. However, they predominantly work for symmetric notions of relevance, such as Jaccard similarity, dot product, cosine similarity, or Hamming distance, rather than asymmetric distances like (1). Neyshabur and Srebro [35] propose a LSH suited for asymmetric relevance (ALSH), but it does not provide a satisfactory solution for (1), as our experiments show.
Responding to the above motivations, we present FOURIERHASHNET, a new LSH for hinge distance-based asymmetric distance measures. Specifically, we make the following contributions.
Scalable hinge distance search for soft set containment From several applications, we distil the strongly-motivated problem of fast top- $\tau$  retrieval using hinge distance (1), to capture soft set containment. To our knowledge, (A)LSH for hinge distance has not been explored till date.
Transformation of hinge distance to enable ALSH design One could leverage its shift-invariant property to apply a Fourier transform on the negative distance, express it as the dot product similarity between the corresponding Fourier features and then use Asymmetric LSH (ALSH) [35]. However, as we show in Section 3.1, using the negative distance leads to singularities of the underlying Fourier transform at some points. This in turn does not allow us to design an LSH for such measure. We circumvent this problem by a suitable transformation of hinge distance to a dominance similarity, whose Fourier transform is absolutely convergent.
Design of Fourier features Next, we propose a novel method of lifting the dense vectors to frequency domain, such that the dominance similarity in the original space can be expressed as the cosine similarity between the infinite dimensional Fourier features. However, our dominance similarity function is not a positive definite kernel. Hence, unlike Rahimi and Recht [40], we cannot apply Bochner theorem [44] to obtain finite dimensional Fourier features. Instead, we first scale the Fourier features with a sinc function and then obtain finite dimensional Fourier features via importance sampling.
Trainable hashingcode design The cosine similarity between the sampled Fourier features is the unbiased estimate of our dominance similarity measure. This allows the use of conventional random hyperplane LSH. However, such an LSH is not guided by the underlying data distribution. To mitigate this limitation, we compute the hashcodes by feeding the Fourier features into a trainable neural hashing network. Prior approaches [54, 15] to trainable hashing encourage bucket balance over the entire corpus, regardless of the query workload. However, this approach is not optimal if most corpus items are irrelevant for most queries, as is usually the case. We propose a new loss function that encourages the best-match hash bucket for a query to include relevant documents and exclude irrelevant documents.
Experiments We show, through extensive experiments, that FOURIERHASHNET is more effective than existing LSH schemes, and that both frequency domain representations and the new trainable hashcode contribute to our gains.
Notation Throughout, we will use  $[K]$  to mean  $\{1,\dots ,K\}$  or  $\{0,\ldots ,K - 1\}$  as convenient. We use  $q$  to indicate a query and  $x$  to indicate a corpus 'document'. Their (possibly learnt) representations are denoted by  $\pmb {x},\pmb {q}\in \mathbb{R}^{K}$ . For supervision,  $(q,x)$  may come with a binary relevance judgment  $\mathrm{rel}(q,x)\in \{0,1\}$ . We have defined a potentially learnable distance  $d(q,x)$  — a computable surrogate for  $\operatorname {rel}(q,x)$  — above in Eqn. (1). One can define a similarity measure  $\sin (q,x)$  by applying a monotonically decreasing function on the distance  $d(q,x)$ . We define  $\iota = \sqrt{-1}$  and denote the set of corpus items as  $X = \{x_{1},x_{2},\dots,x_{N}\}$ . We indicate the domain of query and corpus items as  $\mathcal{Q}$  and  $\mathcal{X}$  respectively. Given a function  $s(t)$ , its Fourier transform is the function  $S:\mathbb{C}\to \mathbb{C}$  which satisfies  $s(t) = \int_{-\infty}^{\infty}S(\imath \omega)e^{\imath \omega t}d\omega$ , where  $\omega$  is the frequency variable and  $S(\imath \omega) = \frac{1}{2\pi}\int_{-\infty}^{\infty}s(t)e^{-\imath \omega t}dt$ . For a vector  $\pmb{q}$  or  $\pmb{x}\in \mathbb{R}^{K}$ , the Fourier transform is synthesized using a frequency vector  $\omega \in \mathbb{R}^{K}$  of same dimension as  $\pmb{x}$  or  $\pmb{q}$ . Here, a function  $s(x)$  can be expanded as  $s(\pmb {x}) = \int_{\omega \in \mathbb{R}^{K}}S(\imath \omega)e^{-\imath \omega^{\top}\pmb{x}}d\omega$ .
2.1 Locality sensitive hashing
Indexing corpus items Given a set of corpus items  $X = \{x_{1}, x_{2}, \dots, x_{N}\}$ , an LSH will hash each item  $x_{i}$ ,  $L$  times, which is called the number of trials. For each trial  $\ell \in [L]$ , it prepares  $B$  buckets, which are indexed as the pair  $(\ell, b)$  with  $\ell \in [L]$  and  $b \in [B]$ . In the context of LSH, we draw  $L$  independent samples of hash functions  $h^{(\ell)}$  from a single hash family  $\mathcal{H}$ , such that  $h^{(\ell)}: \mathbb{R}^K \to [B]$ . A corpus item  $x$  is inserted in the bucket indexed  $(\ell, h^{(\ell)}(\pmb{x}))$ , for each  $\ell \in [L]$ .
Symmetric LSH Given a query  $q$ , a symmetric LSH computes bucket indices  $(\ell, h^{(\ell)}(q))$  for all  $L$  using the same hash functions  $h^{(\ell)}$  used for indexing the corpus. Only those items  $x$  that are in bucket  $(\ell, h^{(\ell)}(q))$  are considered as candidates; overall, the candidates are in the union of these buckets. In the rest of the paper, we will describe retrieval for one bucket under one trial, with the understanding that  $L$  buckets will contribute candidates. An LSH exists if the query and corpus items are hashed in the same bucket with high (low) probability as long as their similarities are high (low). Formally, we define symmetric LSH as follows.
Definition 2.1 (Symmetric Locality Sensitive Hashing (LSH)). Given a domain of queries  $\mathcal{Q}$  and corpus  $\mathcal{X}$  with  $\mathcal{Q},\mathcal{X}\subset \mathcal{Z}$  and a similarity measure  $\mathrm{sim}:\mathcal{Z}\times \mathcal{Z}\to \mathbb{R}$ . A distribution over mappings  $\mathcal{H}:\mathcal{Z}\rightarrow \mathbb{N}$  is said to be a  $(S_0,cS_0,p_1,p_2)$ -LSH for the similarity function  $\mathrm{sim}(\cdot)$  if for all  $q\in \mathcal{Q}$  and  $x\in \mathcal{X}$  we have, with  $p_1 > p_2$  and  $c < 1$ ,
- if  $\operatorname{sim}(q, x) \geq S_0$ , then  $\operatorname{Pr}_{h \sim \mathcal{H}}[h(q) = h(x)] \geq p_1$
- if  $\operatorname{sim}(q, x) \leq cS_0$ , then  $\operatorname{Pr}_{h \sim \mathcal{H}}[h(q) = h(x)] \leq p_2$ .
The hash family  $\mathcal{H}$  is tailored to the specific choice of similarity function  $\mathrm{sim}(q,x)$  (equivalently, the distance  $d(q,x)$ ). When  $\pmb{q},\pmb{x} \in \mathbb{R}^{K}$  and  $\mathrm{sim}(q,x) = \cos(\pmb{q},\pmb{x})$ , the choice of  $\mathcal{H}$  corresponds to the uncountable set of all hyperplanes in  $K$  dimensions passing through the origin [9]. When  $\mathrm{sim}(q,x)$  is the Jaccard similarity  $|q \cap x| / |q \cup x|$ ,  $\mathcal{H}$  is the space of minwise independent hash functions [7].
Asymmetric LSH (ALSH) In many applications, like the current setup (1), we have asymmetric similarity where  $\sin(q, x) \neq \sin(x, q)$ . In such cases, we employ two different hash families  $\mathcal{G}$  and  $\mathcal{H}$  to determine the bucket of query and corpus respectively. Formally, we define ALSH as follows:
Definition 2.2 (Asymmetric Locality Sensitive Hashing (ALSH) [35]). An asymmetric LSH is  $(S_0, cS_0, p_1, p_2)$ -ALSH for a similarity function  $\mathrm{sim}(\bullet, \bullet)$  over  $\mathcal{Q}$ ,  $\mathcal{X}$  if we have two different distributions over mappings  $\mathcal{G}$  and  $\mathcal{H}$  such that, with  $p_1 > p_2$  and  $c < 1$ ,
- if  $\operatorname{sim}(q, x) \geq S_0$  then  $\operatorname{Pr}_{g \sim \mathcal{G}, h \sim \mathcal{H}}[g(q) = h(x)] \geq p_1$
- if  $\operatorname{sim}(q, x) \leq cS_0$  then  $\operatorname{Pr}_{g \sim \mathcal{G}, h \sim \mathcal{H}}[g(q) = h(x)] \leq p_2$ .
As an example, given  $\| \pmb{x} \| \leq 1$ , consider  $\sin(q, x) = \pmb{q}^\top \pmb{x} / \| \pmb{q} \|_2$ , which can be re-written as  $\cos(\alpha(\pmb{q}), \beta(\pmb{x}))$ , where  $\alpha(\pmb{q}) = [0; \pmb{q} / \| \pmb{q} \|_2]$ ,  $\beta(\pmb{x}) = [\sqrt{1 - \| \pmb{x} \|_2^2}; \pmb{x}]$ . Thus, we can apply random hyperplane hash on both  $\alpha(\pmb{x})$  and  $\beta(\pmb{x})$  to construct  $g(q) = \mathrm{sign}(\mathbf{w} \cdot \alpha(\pmb{q}))$  and  $h(x) = \mathrm{sign}(\mathbf{w} \cdot \beta(\pmb{x}))$  with  $\mathbf{w} \sim \mathcal{N}(\mathbf{0}, \mathbf{I})$ . If  $\| \pmb{x} \|$  is unbounded, no ALSH exists for  $\sin(q, x) = \pmb{q}^\top \pmb{x} / \| \pmb{q} \|_2$  [35]. In  $(S_0, cS_0, p_1, p_2)$ -ALSH, retrieval of items with similarity score more than  $S_0$  out of a database of items having a similarity score less than  $cS_0$  will admit time-complexity  $O(n^\rho \log n)$  and space complexity  $O(n^{1+\rho})$  where  $\rho = \log p_1 / \log p_2$  [35].
Figure 1: Outline of FOURIERHASHNET. (a) Given the input query embedding  $q$  and corpus embedding  $x$ , we apply the asymmetric transformation in Eq. (10) to obtain corresponding Fourier features  $F_{q}(\iota \omega^{1\dots M})$  and  $F_{x}(\iota \omega^{1\dots M})$ . (b) We use the generated Fourier features as inputs, to train asymmetric Fourier transformation networks  $\phi_q$  and  $\phi_x$  using Eq. (12). This generates transformed Fourier representations  $z_{q} = \phi_{q}(F_{q}(\iota \omega^{1\dots M}))$  and  $z_{x} = \phi_{x}(F_{x}(\iota \omega^{1\dots M}))$ , which are in turn used to train the random hyperplanes  $W$  using Eq. (14). The trained  $\widehat{\phi_q},\widehat{\phi_x}$  and  $\widehat{W}$  thus obtained are used to generate final hashcodes  $g(q) = \mathrm{sign}(\widehat{W}\widehat{\phi_q} (F_q(\iota \omega^{1\dots M})))$ ,  $h(x) = \mathrm{sign}(\widehat{W}\widehat{\phi_x} (F_x(\iota \omega^{1\dots M})))$ .
Given the set of training queries  $Q$  and corpus  $X$ , with supervised relevance scores  $\mathrm{rel}(q, x) \in \{0, 1\}$  and the surrogate score  $d(q, x)$  defined in Eq. (1), we aim to design an LSH of the distance  $d(q, x)$  which can efficiently retrieve top- $\tau$  corpus items for any new query  $q'$ .
Why are existing methods not suitable? As we discussed in Section 2.1, relevance metrics for popular LSHs are mostly symmetric, e.g., cosine, dot-product, and Jaccard similarity. In particular, Jaccard similarity, although commonly used in set-related applications, is not suitable for our problem, where we define  $\operatorname{rel}(q,x) = 1$  when  $q \subseteq x$  and 0 otherwise — it is possible that there exists a higher overlap between  $q$  and  $x$  when  $q \not\subseteq x$ , and a lower overlap when  $q \subseteq x$ . E.g., suppose  $q = \{a,b\}$ ,  $x_1 = \{a,b,c,d,e\}$ , and  $x_2 = \{b\}$ . Here,  $\operatorname{rel}(q,x_1) = 1$  and  $\operatorname{rel}(q,x_2) = 0$ . However, the Jaccard similarity  $J(q,x)$  is not able to reflect the order of  $\operatorname{rel}(q,x)$  since  $J(q,x_1) = 2/5 < J(q,x_2) = 1/2$ .
As discovered by Charikar [9, Lemma 1], the similarity functions in symmetric LSH are inversely related to a metric, which must satisfy symmetry and triangle inequality. Although a query normalized dot product similarity appears asymmetric, it can be expressed using cosine similarity. This readily allows us to use a random hyperplane based (asymmetric) LSH. In contrast, it is not immediately apparent how to find such a connection for our asymmetric hinge distance (1).
3 FOURIERHASHNET: A new ALSH for hinge distance search
Overview of our approach We design an ALSH for  $d(q, x)$  in three steps. In the first step, we construct a suitable dominance similarity function  $\mathrm{sim}(q, x)$  from  $d(q, x)$  in such a way that there exists a probability distribution  $p: \mathbb{R}^K \to [0,1]$  and bounded Fourier representations  $F_q(\iota \omega)$  and  $F_x(\iota \omega)$  of both query  $q$  and corpus items  $x$  such that
$$
\sin (q, x) = \int_ {\boldsymbol {\omega} \in \mathbb {R} ^ {K}} \boldsymbol {F} _ {q} (\iota \boldsymbol {\omega}) ^ {\top} \boldsymbol {F} _ {x} (\iota \boldsymbol {\omega}) p (\boldsymbol {\omega}) d \boldsymbol {\omega} = \mathbb {E} _ {\boldsymbol {\omega} \sim p (\bullet)} [ \boldsymbol {F} _ {q} (\iota \boldsymbol {\omega}) ^ {\top} \boldsymbol {F} _ {x} (\iota \boldsymbol {\omega}) ] \tag {2}
$$
In the second step, we approximate the expected value of the  $F_{q}(\iota \omega)^{\top}F_{x}(\iota \omega)$  using a finite sample of Fourier features. This allows us to apply random hyperplane LSH, similar to asymmetric dot product LSH. However, these hyperplanes are drawn from an isotropic Gaussian distribution in a data-oblivious manner, which results in suboptimal bucket distribution in terms of accuracy-efficiency trade off. To tackle this issue, in the third step, we train the random hyperplanes  $W$  which takes the Fourier features as input and give (soft) binary hashcodes, which are optimized to effectively trade off between accuracy and efficiency. Next, we provide the details of the above three steps.
3.1 Design of dominance similarity function  $\sin (q,x)$  from hinge distance
Limitations of simple choices of dominance similarity function  $\sin (q,x)$  A dominance similarity function  $\sin (q,x)$  is inversely related to the hinge distance  $d(q,x)$ . Chierichetti and Kumar [11] characterized that, any function of a similarity measure is LSHable, if and only if this function is a probability generating function. However, this characterization applies only to symmetric LSH and no such guiding principle is available for an ALSH. In this context, one can experiment with simple designs of sim that are inversely related to  $d$ . An immediate choice is  $\sin (q,x) = -d(q,x)$ .
However, if we allow  $q$  and  $x$  to be any vector from  $\mathbb{R}^K$ , then  $\mathrm{sim}(q,x)$  is not bounded. Finding ALSH for unbounded similarity measures is extremely difficult if not impossible. For example, no ALSH exists even for dot product similarity in two or more dimensions [35]. Moreover, suppose we express  $\mathrm{sim}(q,x)$  using the Fourier expansion
$$
\operatorname {s i m} (q, x) = \sum_ {k \in [ K ]} \int_ {- \infty} ^ {\infty} S (\iota \omega_ {k}) e ^ {\iota \omega_ {k} \left(\boldsymbol {q} [ k ] - \boldsymbol {x} [ k ]\right)} d \omega_ {k}. \tag {3}
$$
Then,  $S(\iota \omega)$ , i.e., the Fourier transform of the function  $s(t) = -[t]_{+}$  used in each dimension, has a singularity at  $\omega = 0$ . In particular, we have  $S(\iota \omega) = -\iota \delta'(\omega) / 2 + 1 / 2\pi \omega^2$ . Here,  $\delta'(\omega)$  is the derivative of Dirac delta functional. Thus,  $S(\iota \omega)$  becomes unbounded as  $\omega \to 0$ . These issues eventually prevent us from designing bounded Fourier features  $F_q(\iota \omega)$  and  $F_x(\iota \omega)$  for Eq. (2).
$\operatorname{sim}(q, x)$  with bounded Fourier transform The key reason for which  $S(\iota \omega)$  becomes unbounded as  $\omega \to 0$  is that the function  $s(t) = -[t]_{+}$  is unbounded at  $t \to \infty$ . However, in practice, the embeddings are bounded and we have a bounded difference  $|\pmb{q}[k] - \pmb{x}[k]| \leq T$ . Thus, it is reasonable to ignore the effect of  $[q[k] - x[k]]_{+}$  when  $|\pmb{q}[k] - \pmb{x}[k]| > T$ . To this end, we compute  $\operatorname{sim}(q, x)$  as
$$
\operatorname {s i m} (q, x) = \sum_ {k \in [ K ]} s (\boldsymbol {q} [ k ] - \boldsymbol {x} [ k ]), \quad \text {w h e r e} s (t) = \left\{ \begin{array}{l l} T - t & \text {i f} 0 \leq t \leq T, \\ T & \text {i f} - T \leq t <   0, \\ 0 & \text {o t h e r w i s e .} \end{array} \right. \tag {4}
$$
In practice, we choose  $T$  as a hyperparameter greater than  $\max_k |\pmb{q}[k] - \pmb{x}[k]|$ . Upon restricting the computation within this domain, one can immediately show that  $\mathrm{sim}(q, x) = KT - d(q, x)$ .
3.2 Computation of finite dimensional Fourier features for dominance similarity  $\mathrm{sim}(q,x)$
Fourier transform of  $s(t)$  We next compute the Fourier representation  $S(\iota \omega)$  of  $s:\mathbb{R}\to \mathbb{R}$  (4).
Proposition 3.1. (Proven in Appendix D)  $s(t)$  specified in Eq. (4) has Fourier transform
$$
S (\iota \omega) = \underbrace {\frac {T \sin (\omega T)}{2 \pi \omega} + \frac {\sin^ {2} \left(\frac {\omega T}{2}\right)}{\pi \omega^ {2}}} _ {\operatorname {R e} (S (\iota \omega))} + \iota \underbrace {\left[ \frac {\sin (\omega T)}{2 \pi \omega^ {2}} - \frac {T \cos (\omega T)}{2 \pi \omega} \right]} _ {\operatorname {I m} (S (\iota \omega))} \tag {5}
$$
While the Fourier transform of  $-[t]_{+}$  is unbounded as  $\omega \to 0$ , here,  $S(\iota \omega)$  is bounded everywhere.
Computation and sampling of Fourier features Once we compute  $S(\omega)$  using Eq. (5), we use Eq. (3) to compute  $\sin(q, x)$  as follows:
$$
\operatorname {s i m} (q, x) = \sum_ {k \in [ K ]} \int_ {- \infty} ^ {\infty} \left[ \operatorname {R e} \left(S \left(\iota \omega_ {k}\right)\right) + \iota \operatorname {I m} \left(S \left(\iota \omega_ {k}\right)\right) \right] e ^ {\iota \omega_ {k} \left(q [ k ] - x [ k ]\right)} d \omega_ {k} \tag {6}
$$
Now, we define  $S_{q}(\iota \omega)$  and  $S_{x}(\iota \omega)$ , the query and corpus specific Fourier representations:
$$
\boldsymbol {S} _ {q} (\iota \omega_ {k}) = \left[ u _ {k} \sqrt {| \operatorname {R e} (S (\iota \omega_ {k})) |} \left[ \cos (\omega_ {k} \boldsymbol {q} [ k ]), \sin (\omega_ {k} \boldsymbol {q} [ k ]) \right], \right.
$$
$$
\left. v _ {k} \sqrt {\left| \operatorname {I m} \left(S \left(\iota \omega_ {k}\right)\right) \right|} \left[ - \sin \left(\omega_ {k} \boldsymbol {q} [ k ]\right), \cos \left(\omega_ {k} \boldsymbol {q} [ k ]\right) \right] \right]
$$
$$
\boldsymbol {S} _ {x} (\iota \omega_ {k}) = \left[ \sqrt {| \operatorname {R e} (S (\iota \omega_ {k})) |} \left[ \cos (\omega_ {k} \boldsymbol {x} [ k ]), \sin (\omega_ {k} \boldsymbol {x} [ k ]) \right], \right.
$$
$$
\left. \sqrt {\left| \operatorname {I m} \left(S \left(\iota \omega_ {k}\right)\right) \right|} \left[ \cos \left(\omega_ {k} \boldsymbol {x} [ k ]\right), \sin \left(\omega_ {k} \boldsymbol {x} [ k ]\right) \right] \right] \tag {7}
$$
Here,  $u_{k} = \mathrm{sign}(\mathrm{Re}(S(\iota \omega_{k})))$ ,  $v_{k} = \mathrm{sign}(\mathrm{Im}(S(\iota \omega_{k})))$ . They ensure that the dot-product  $S_{q}(\iota \omega_{k})^{\top}S_{x}(\iota \omega_{k})$  equals to the real part of the integrand in the RHS of Eq. (6). Since the dominance similarity  $\mathrm{sim}(q,x)$  is a real quantity, the imaginary part of the RHS integrates to zero. Therefore, using the dot product of the vectors  $S_{q}(\iota \omega_{k})$  and  $S_{x}(\iota \omega_{k})$ , which are purely real, we can express