{'fraction_non_alphanumeric': 0.03436259373621526, 'fraction_numerical': 0.01129245699161888, 'mean_word_length': 4.599160286490491, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Scalable Gaussian Processes for Supervised Hashing

We propose a flexible procedure for large-scale image search by hash functions with kernels. Our method treats binary codes and pairwise semantic similarity as latent and observed variables, respectively, in a probabilistic model based on Gaussian processes for binary classification. We present an efficient inference algorithm with the sparse pseudo-input Gaussian process (SPGP) model and parallelization. Experiments on three large-scale image dataset demonstrate the effectiveness of the proposed hashing method, Gaussian Process Hashing (GPH), for short binary codes and the datasets without predefined classes in comparison to the state-of-the-art supervised hashing methods.


Introduction
As the size of online image datasets gets larger, the problem of image retrieval has attracted more attention from researchers in computer vision, machine learning, and information retrieval. Considering an image dataset with millions of images, image retrieval becomes a seemingly intractable problem for exhaustive similarity search algorithms due to their linear time complexity. Although k-d trees are useful data structures for low-dimensional nearest neighbor search, they are not as applicable to high-dimensional image descriptors. Hashing methods, which encode high-dimensional descriptors into compact binary strings, are attractive alternatives due to their sublinear time search complexity and efficient storage capacity. Methods for learning binary codes can be roughly grouped into two categories: Unsupervised hashing where binary codes are designed to preserve similarity in the original feature space; and supervised hashing where binary codes are constructed to capture semantic similarity between images.
Unsupervised hashing techniques can be categorized as data independent and dependent schemes. Locality Sensitive Hashing (LSH) [5] is the most widely known data-independent hashing technique, which has also been extended to hashing with kernels (KLSH) [9]. Notable data-dependent hashing methods are Spectral Hashing (SH) [25], Principal Component Analysis based Hashing (PCAH) [26] and Iterative Quantization (ITQ) [6]. Unfortunately, unsupervised hashing methods unavoidably suffer from the semantic gap, which is the difference between low-level image descriptors and highlevel semantic representation of an image, when they are employed for image retrieval. Therefore, most recent unsupervised methods [24,21,19] focus on multimodal data to bridge this gap by utilizing both textual and visual features. Yildirim and Jacobs [27] propose an integrative model based on Indian Buffet Process (IBP) to connect features in different modalities by common abstract features. In our previous work [19], we utilize this model for multimodal retrieval.
Supervised Hashing methods usually rely on pairwise labels, where +1 and −1 indicate that two points are similar and dissimilar, respectively. Furthermore, some methods use 0 for points which are neighbors in the metric space without being semantically similar. Supervised Hashing with Kernels (KSH) [13] tries to minimize the Hamming distances between similar pairs and simultaneously maximize them for dissimilar pairs using inner products of binary codes. FastHash [12] employs decision trees as hash functions and a GraphCut based method for the same type of optimization problem. Minimal loss hashing (MLH) [17] uses a structured SVM framework to generate binary codes. Supervised Hashing with latent factor models (LFH) [28] uses latent factors for learning binary codes in a probabilistic framework. Supervised discrete hashing (SDH) [22] learns binary codes based on linear classification. The main problem of most supervised hashing methods is overfitting to training data. Despite different formulations, many supervised hashing methods in practice find one binary string pattern for each class and the same binary hash code is assigned to all images in one class.
The Gaussian process is an elegant model based on Bayesian nonparametrics for nonlinear regression and classification. Similar to SVM, which is employed in [21,17], binary Gaussian process classification (GPC) model [10] can be utilized for hashing in a Bayesian framework. In this paper, we propose a supervised hashing method with kernels based on the GPC model, so we call the proposed approach Gaussian Process Hashing (GPH). Unlike LFH, which first optimizes latent factors independently from image features and then learns a weight matrix to map these features to the latent factors, we use a fully probabilistic approach for learning binary codes from data. In the GPH model, the variables corresponding to the binary classes in the original GPC model become latent variables and a new level of variables that correspond to the pairwise similarity between data points is integrated into the model. Averaging over nonlinear classification models by Gaussian processes is our motivation behind the GPH model to overcome the overfitting problem of supervised hashing. Our contributions can be summarized as follows: • We propose a flexible Bayesian nonparametric model based on binary Gaussian process classification for supervised learning of binary codes with better generalization. • We utilize the GPC predictive distribution to define a hash function by means of hyperplanes with kernels. • We developed a scalable parallel inference algorithm for the proposed model using a sparse approximation to the GPC model via a hybrid approach combining MCMC and message passing.
The rest of the paper is organized as follows: Section 2 describes the GPH. The inference algorithm for the method is explained in Section 3. Section 4 demonstrates performance evaluation and also the comparison of our method with the state-of-the-art supervised hashing methods, and Section 5 provides conclusions regarding the proposed method.

Problem Definition
Given a set of data points X = {x 1 , . . . , x n }, each x i ∈ R d , hashing aims to find a function H that maps data points from R d to m-dimensional Hamming space with respect to some optimization criteria. Let S = {s il } denote the set of similarity labels for pairs of data points where s il = +1 if x i and x l are similar and s il = −1 otherwise, then a desirable hash function yields a smaller Hamming distance between H(x i ) and H(x l ) when s il = +1 and a larger one when s il = −1.

A Probabilistic Approach
The hash function H can be modeled as a latent function that builds a bridge between X and S, i.e. the observed data D = {X , S}. Let Y be a random binary matrix of size n × m where Y ij = h j (x i ) and y j is the jth column of Y, i.e. shorthand for the values of the hash function. Then using Bayes' rule we can write Given the binary codes Y, the similarity labels S are assumed to be independent Bernoulli variables. Let V = YY , i.e. V il is the inner product of binary codes for sample i and sample l; then the joint likelihood factorizes as We use the probit model to define p(s il = +1|V il ) = Φ(σ y V il ) where Φ denotes the cumulative distribution function of the standard normal distribution and σ y > 0 is a scaling parameter. The individual likelihood terms can be written as p(s il |V il ) = Φ(σ y s il V il ) due to the symmetry of Φ around zero. Note that p(S|Y) is maximized when the columns of Y are orthogonal and images of the same semantic class have the same binary embeddings. The prior term of (1) can be designed as a Gaussian process model for binary classification as described in the following section.

The Gaussian Process Model for Binary Classification
In this section we briefly describe Gaussian Process Classification (GPC); for more details see [10,20,16]. The GPC model is a discriminative Bayesian classifier that models p(y|x) as a Bernoulli distribution for a given data point x. The class membership probability is characterized by an underlying latent function f (x). The value of the latent function is mapped into the unit interval by a sigmoid function σ : R → [0, 1] such that the probability p(y = +1 | x) becomes σ(f (x)). We again prefer the probit model p(y = +1 | x) = Φ(f (x)) due to analytical convenience of the inference algorithm.
In GPH, there exist m latent functions, one for each bit j in H, which are assumed to be a priori independent. Let F be a random real-valued matrix of size n × m where F ij = f j (x i ) and f j be the jth column of F i.e. shorthand for the values of the latent functions; then the binary codes Y are independent Bernoulli variables conditioned on F, so the joint likelihood factorizes as We place a zero mean Gaussian process prior on each latent function f j to obtain p(y j = +1 | x) = 1 2 for j = 1, . . . , m [10]. Note that the probability for each similarity label p(s il = +1 | x i , x l ) eventually becomes 1 2 as well. Through this stochastic process, each data point x i is associated with m random variables {f j (x i )} m j=1 . Considering the entire dataset X , we therefore have m independent multivariate Gaussian distributions. The joint distribution of latent function values for the jth bit is p(f j |X ) = N (f j |0, K) where the covariance matrix is constructed from a kernel function K il = k(x i , x l ) that depends on a set of kernel hyperparameters θ. In our experiments, we use the squared exponential covariance function with the isotropic distance measure of the form: f and are referred as the signal variance and the characteristic length-scale, respectively.
Given Θ = {σ y , θ}, we can compute the posterior distribution over the latent function values using the likelihood (3) and Bayes' rule as Unfortunately, neither the posterior p(F|D) nor the marginal likelihood p(D) can be computed analytically. Therefore, we approximate the posterior p(F|D) by joint Gaussian distributions q(F) = m j=1 N (f j |m j , A j ). Note that the approximate posterior distribution for each bit is independent of other bits. The details of the Gaussian approximation are presented in Section 3.

Predictions for Queries
The main purpose of hashing models is to predict binary codes for queries. Prediction at a query input x * is made by marginalizing out over F in the joint distribution p(F, F * |D, x * ). This can be done separately for each bit j similar to [10] because of the independence in the approximate posterior distribution: with mean and variance: is a vector of prior covariances between the query input x * and training inputs X . Finally, the approximate predictive distribution for each binary encoding is given as follows [20]: This probability is maximized for each binary encoding bŷ As a result, we introduce our hash function in the form of binary encodings using (6a): where w j = K −1 m j , for j = 1, . . . , m. Our has function consists of only multiplication between weight matrix W = [w 1 , . . . , w m ] and query kernel vector k * , and then sign operation. Consequently, our hash function does not contain the costly cumulative distribution function Φ.

Sparse Approximation
To accelerate training and query times, we employ a sparse approximation to the full Gaussian process known as the fully independent training conditional (FITC) approximation [1,23]. Let X = {x 1 , . . . ,x r }, eachx i ∈ R d , which might be a subset of X , and associated latent function values U, analogous to F. Then we obtain the FITC approximation for each bit j as below: where p(u j |X ) = N (u j |0, K uu ). Marginalizing over the exact prior on u j in the final expression yields where Q ab = K au K −1 uu K ub for j = 1, . . . , m. The computations of the FITC approximation for binary classification are explained thoroughly in [15]. We can define binary encodings similar to those of (9) for the FITC model as well. However, the hyperplanes w j ∈ R r and k * will be defined between the query input x * and inducing inputsX since training data and queries are conditionally independent given U in the FITC approximation. Therefore, the communication between them is established through the bottleneck of inducing inputs [15]. Similarly, we employ a sparse set in place of all pairwise similarities, S, in (2). We randomly sample t images, called representatives, from the dataset and use the pairwise similarities only between those representatives and the entire training set. The sparse similarity set is denoted byS. By these sparsity changes, the time complexity of Gaussian process hashing is reduced from O(n 3 m) to O nm(r 2 + t) . The graphical model of our hashing approach with sparse approximation is shown in Figure 1.

Inference
We follow the inference approach from [3], which is a hybrid of message passing and Gibbs sampling. This technique has some advantages over a compound inference regarding convergence and efficiency. Our inference algorithm alternates between two phases: • Updating site parameters of the approximate distribution by Expectation Propagation (EP) [14] for each bit j in parallel, and • Sampling each entry of Y by Gibbs sampling.
The main idea behind the EP algorithm is to minimize the Kullback-Leibler (KL) divergence, which is achieved by matching of moments, at each step by adjusting site parameters. The details of EP are presented broadly by Gelman et al. [4]. In the first phase of our inference algorithm, the problem is reduced to Gaussian process classification since we know the values of the binary matrix Y thanks to the Gibbs sampler. Therefore, we adopt the new scalable inference scheme by Hernandez-Lobato and Hernandez-Lobato [7], which is defined in a distributed and stochastic fashion, for the FITC model. We apply that scalable EP algorithm in a serial and stochastic setting for a full update of site parameters for each bit j in parallel.
In the second phase, we sample each Y ij bit-by-bit using (2) via where Y −ij denotes entries of Y other than Y ij and q \ij (Y ij ) denotes a tilted distribution for approximating the posterior from the FITC model; and the probability q \ij (Y ij ) has the form Φ(γ ij Y ij ) where γ ij is a site parameter computed by the scalable EP algorithm (See [7] for details). The likelihood p(S|Y) is given in (2) for the full version S.
Our hashing method is illustrated in Figure 2 for m = 2 on a two-dimensional sample dataset of 200 points with 4 equal-sized classes and 30 inducing points randomly selected from the dataset.

Experiments
We compared the retrieval performance of our hashing method with several state-of-the-art supervised hashing techniques including CCA-ITQ [6], KSH [13], FastHash [12] and SDH [22]. The public codes provided by the authors are used with their suggested parameters unless otherwise specified.  Figure 2: From left to right; a sample dataset of 4 classes indicated by color and shape X , inducing points marked with red circlesX , the predictive probability distribution for the first binary encoding p(y * 1 |D, x * ) and for the second encoding p(y * 2 |D, x * ). The binary codes Y by the Gibbs sampler are indicated by filled and empty shapes for +1 and −1, respectively.
The experiments were performed on three image datasets, namely, CIFAR-10, MNIST and NUS-WIDE datasets in the MATLAB environment on a machine with a 2.8 GHz Intel Core i7 CPU and 16GB RAM.

Datasets and Experimental Setup
The CIFAR-10 dataset [8], which is a labeled subset of the 80M tiny images dataset, has 60,0000 images from 10 classes. There are 50,000 training and 10,000 test images in the dataset. We used a GIST descriptor [18] of 512 dimensions to represent each image. The MNIST dataset [11] contains 28×28 pixel images of handwritten digits from '0' to '9'. The dataset hash a training set of 60,000 examples and a test set of 10,000 examples. The third dataset, NUS-WIDE [2], includes 269,648 images and associated semantic labels of 81 concepts from Flickr such as dog, flower, street, and dancing. The dataset is split into 161,789 training images and 107,859 test images. As [22], we consider two images as semantically similar if there exists at least one common associated concept. We used a 500-dimensional bag-of-words representation where the codebook is generated from SIFT descriptors. All datasets were first centered at zero and then each point vector was normalized to unit length.
For NUS-WIDE, we constructed a reduced test set by sampling 10,000 images associated with any of the most frequent 21 labels for all methods. For the KSH method, we uniformly sampled 5,000 images from the training sets of each dataset because the computational complexity of this approach does not allow it to be trained on the entire datasets as we do with other methods (Table 1). Similarly, the tree depth of FastHash was set to 2 due to its longer test time (Table 1). FastHash was not trained on that dataset due to its large memory requirements. GPH and KSH were used on pairwise similarities on the NUS-WIDE dataset while SDH and CCA-ITQ were trained on label information on that dataset. The 2 loss version of SDH was employed in our experiments since there exist no predefined classes for the NUS-WIDE dataset. We uniformly sampled 1000 inducing points (anchor points) from the training set of each dataset. These points were shared by all hashing methods with kernels (GPH, KSH, and SDH) in training. All these methods used an RBF kernel with a kernel width adjusted specifically for each dataset by cross-validation for each method with a kernel.
Hash functions learned from a subset of a large-scale image dataset can be used for computing the binary codes for the entire dataset. Next, these binary codes can be utilized for efficient large-scale image search in the Hamming space [5]. Therefore, generalization ability of supervised hashing techniques is critical for the retrieval performance.
For GPH, we adjusted the hyperparameters σ f and σ y by cross-validation on the training set. However, the performance is usually maximized at σ y = 2/m. For all datasets, 5,000 representative images were randomly selected forS. The scalable EP algorithm was run in a stochastic fashion with a block size of 1,000 images. The binary codes Y were initialized randomly. The GPH inference algorithm was executed until convergence or at most 50 sweeps. In learning hash functions by the GPH model, we observe that the Gibbs sampler for Y rapidly converges after assigning discriminative binary codes to all classes. The rest of the inference algorithm focuses on training GPs with the scalable EP algorithm on these fixed binary codes. A pattern of binary codes emerges even for most values of σ y although some bit assignments might change during the inference algorithm.
After learning hash functions from training data, we computed binary codes for images in the test sets where each dataset contains 10,000 images. Retrieval performance was evaluated by leave-one-out validation on these images only. Each test image was used once as a query while the remaining test images were turned into a retrieval set. As overfitting is a common issue for supervised hashing, this methodology was employed to assess generalization performance of the hashing methods on images that were not used in training, analogous to new images being added to a database or an enormous dataset from which only a subset of images can be employed for learning hash functions.

Experimental Results
For each query, images were ranked concerning Hamming distances between their binary codes and that of the given query. Ground truth labels were defined by semantic similarity from either class labels or associated tag information. For quantitative analysis, we report retrieval performance in mean average precision (mAP) for all datasets in Figure 3. Precision-recall curves of all methods on the CIFAR-10 datasets are demonstrated in Figure 4 for different lengths of hash codes.
Our method GPH outperforms the state-of-the-art supervised hashing methods in terms of mAP for smaller binary codes (32-bits or shorter) on all datasets. Some methods perform better than GPH in some cases on the training set (data not shown); however, GPH outperforms on the independent set due to better generalization with the help of averaging over nonlinear classifiers. Although SDH performs well on the CIFAR-10 and MNIST datasets, its performance on the NUS-WIDE dataset where there are no predefined classes is poor. On the other hand, GPH performs the best on that dataset with a large margin. As the number of bits increases, the approximation error due to our assumption of conditional independence between GPs is growing as well. Therefore, the improvement in retrieval performance by longer codes for the GPH is moderate.
The comparative retrieval performance of our method is shown in Table 1 with different training and inducing set sizes along with the state-of-the-art methods on the CIFAR-10 dataset for 16-bit hash codes in terms of mAP and mean precision at Hamming radius 2. The execution times are reported for training and computing binary code of a single query using the learned hashing functions. Larger training and inducing sets provide better performance with longer execution time. The number of inducing points affects retrieval performance than training size. Note that the scale of the inducing set also affects the test time. Our method provides better performance in retrieval. Note that Table 1 shows the training time on a four-core machine and our method learns its hash function by a parallel algorithm. The training time in Table 1 can be improved by a computer with a larger number of nodes. Therefore, GPH is more efficient and effective in retrieval when binary codes are short. CCA-ITQ is the fastest method in the experiments; however, its performance is the worst in retrieval. On the other hand, SDH is the second most efficient method with relatively good retrieval performance. For testing, all kernel methods (GPH, SDH, and KSH) have a similar number of operations: Kernel vector computation, multiplication by weight matrix and kernel vector and finally sign operation. Therefore, they have similar test time per query. CCA-ITQ, which has no kernel computation, has faster test time. On the other hand, FastHash has longer test time due to its computations based on decision trees.

Conclusion
We proposed a supervised retrieval scheme based on Gaussian processes for classification. We developed an efficient inference algorithm for the proposed model. The experimental results on three real-world image datasets show that our method produces the best retrieval performance for smaller binary codes by preventing overfitting to training data.