{'fraction_non_alphanumeric': 0.03680427762924898, 'fraction_numerical': 0.012048192771084338, 'mean_word_length': 4.818585858585859, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Beyond One-hot Encoding: lower dimensional target embedding

Target encoding plays a central role when learning Convolutional Neural Networks. In this realm, One-hot encoding is the most prevalent strategy due to its simplicity. However, this so widespread encoding schema assumes a flat label space, thus ignoring rich relationships existing among labels that can be exploited during training. In large-scale datasets, data does not span the full label space, but instead lies in a low-dimensional output manifold. Following this observation, we embed the targets into a low-dimensional space, drastically improving convergence speed while preserving accuracy. Our contribution is two fold: (i) We show that random projections of the label space are a valid tool to find such lower dimensional embeddings, boosting dramatically convergence rates at zero computational cost; and (ii) we propose a normalized eigenrepresentation of the class manifold that encodes the targets with minimal information loss, improving the accuracy of random projections encoding while enjoying the same convergence rates. Experiments on CIFAR-100, CUB200-2011, Imagenet, and MIT Places demonstrate that the proposed approach drastically improves convergence speed while reaching very competitive accuracy rates.


Introduction
Convolutional Neural Networks lie at the core of the latest breakthroughs in large-scale image recognition [35,30], at present even surpassing human performance [20], applied to the classification of objects [15], faces [31], or scenes [51]. Due to its effectiveness and simplicity, one-hot encoding is still the most prevalent procedure for addressing such multi-class classification tasks: in essence, a function f : R p → Z n 2 is modeled, that maps image samples to a probability distribution over a discrete set of the n labels of target categories.
Unfortunately, when the output space grows, class labels do not properly span the full label space, mainly due to existing label cross-correlations. Consequently, one-hot encoding might result inadequate for fine-grained classification tasks, since the projection of the outputs into a higher dimensional (orthogonal) space dramatically increases the parameter space of computed models. In addition, for datasets with a large number of labels, the ratio of samples per label is typically reduced. This constitutes an additional challenge for training CNN models in large output spaces, and the reason of slow convergence rates [40].
In order to address the aforementioned limitations, output embeddings have been proposed as an alternative to the one-hot encoding for training in large output spaces [7]: depending on the specific classification task at hand, using different output embeddings captures different aspects of the structure of the output space. Indeed, since embeddings use weight sharing during training for finding simpler (and more natural) partitions of classes, the latent relationships between categories are included in the modeling process.
According to Akata et al. [2], output embeddings can be categorized as: • Data-independent embeddings, such as drawing rows or columns from a Hadamard matrix [21]: dataindependent embeddings produce strong baselines [16], since embedded classes are equidistant due to the lack of prior knowledge; • Embeddings based on a priori information, like attributes [1], or hierarchies [39]: unfortunately, learning from attributes requires expert knowledge or extra labeling effort and hierarchies require a prior understanding of a taxonomy of classes, and in addition, approaches that use textual data as prior do not guarantee visual similarity [16]; and • Learned embeddings, for capturing the semantic structure of word sequences (i.e. annotations) and images jointly [43]. The main drawbacks of learning output embeddings are the need of a high amount of data, and a slow training performance.
Thus, in cases where there exist high quality attributes, methods with prior information are preferred, while in cases of a known equidistant label space, data-independent embeddings are a more suitable alternative. Unfortunately, the architectural design of a model is bound to the particular choice among the above-mentioned embeddings. Thus, once a model is chosen and trained using an specific output embedding, it is hard to reuse it for another tasks requiring a different type of embedding.
In this paper, Error-Correcting Output Codes (ECOC) are proven to be a better alternative to one-hot encoding for image recognition, since ECOCs are a generalization of the three embedding categories [14], so a change in the ECOC matrix will not constitute a change in the chosen architecture. In addition, ECOCs naturally enable error-correction, low dimensional embedding spaces [6], and bias and variance error reduction [25].

Decoder
Softmax Loss Input Model Hierarchical Code Decoding Loss Decoding Matrix Figure 1: This paper proposes to replace the traditional one-hot output scheme of CNNs with a reduced scheme with at least log 2 (k) outputs. In addition, when using a hierarchical representation of the data labels, outputs show that the most discriminative attributes to split the target classes have been learned. In essence, a decoder computes the similarities of the "predicted code" in a "code-matrix", and subsequently the output label is then obtained through a softmax layer. The internal code representation is depicted in a tree structure, where each bit of the code corresponds to the actual learned partition from the data, from lower partition cost (aquatic) to higher (stripped).
Inspired by the latest advances on ECOCs, we circumvent one-hot encoding by integrating the Error-Correcting Output Codes into CNNs, as a generalization of output embedding. As a result, a best-ofboth-worlds approach is indeed proposed: compact outputs, data-based hierarchies, and error correction. Using our approach, training models in low-dimensional spaces drastically improves convergence speed in comparison to one-hot encoding. Figure 1 shows an overview of the proposed model.
The rest of the paper is organized as follows: Section 2 reviews the existing work most closely related to this paper. Section 3 presents the contribution of the proposed embedding technique, which is two fold: (i) we show that random projections of the label space are suitable for finding useful lower dimensional embeddings, while boosting dramatically convergence rates at zero computational cost; and (ii) In order to generate partitions of the label space that are more discriminative than the random encoding (which generates random partitions of the label space), we also propose a normalized eigenrepresentation of the class manifold to encode the targets with minimal information loss, thus improving the accuracy of random projections encoding while enjoying the same convergence rates. Subsequently, the experimental results on CIFAR-100 [26], CUB200-2011 [41], MIT Places [51], and ImageNet [35] presented in Section 4 show that our approach drastically improves convergence speed while maintaining a competitive accuracy. Lastly, Section 5 concludes the paper discussing how, when gradient sparsity on the output neurons is highly reduced, more robust gradient estimates and better representations can be found.

Related work
This section reviews those works on output embeddings most related to ours, in particular those using ECOC.
Output Embeddings Most of the related literature addresses the challenge of zero-shot learning, i.e. training a classifier in the absence of labels. Often, the proposed approaches take into account the attributes of objects [49,34,24,2] related to the different classes through well-known, shared object features.
Due to their computing efficiency based on a divide-and-conquer strategy, output embeddings have been also proven useful for those multi-class classification problems in which testing all possible class labels and hierarchical structures is not feasible [4,41,43,7]. Given a large output space, most labels are usually considered instances of a superior category e.g., sunflower and violet are flower plants. In this sense, the inherent hierarchical structure of the data makes divide-and-conquer hierarchical output spaces a suitable alternative to the traditionally flat 1-of-N classifiers. Likewise in the context of language processing, Mikolov et al. combine Huffman binary codes and hierarchical soft-max in order to map the most frequent codes to shorter paths in a tree [32].
Because output embeddings enforce weight sharing, they have been also used when the number of classes is rather large, with no clear inter-class boundaries, and a decaying ratio of the number of examples per class. In this context, in order to reduce the output space, Weston et al. proposed WSABIE, an online learning-to-rank algorithm to find an embedding for the labels based on images [44].
In the field of large-scale recognition, hierarchical approaches such as using tree-based priors [38], label relational graphs [11], CNN hierarchies [46], and HD-CNNs [47] have been proposed. For example in [29] binary hash codes are used for fast image retrieval. However, such hierarchical approaches need to be learned, and cannot be easily interchanged with other embeddings. In addition, for approaches learning codes as latent variables, to find the optimal ones in terms of class separability or error correction is not guaranteed [29]. Due to all this, ECOC constitute a better alternative for seamless integration with CNNs, as detailed next.
Error-Correcting Output Codes 1 ECOC have been applied in multiple fields such as medical imaging [5], face and facial-feature recognition [45,37], and segmentation of human limbs citesanchez2015hupba8k+. ECOCs are a generic divide-and-conquer framework that combines binary partitions to achieve multi-class recognition [12]. Their core property is the capability to correct errors of binary classifiers using redundancy, while reducing the bias and variance of the ensemble [25]. Advanced approaches propose to use them as intermediate representations [23].
ECOC consist of two main steps: coding and decoding. The coding step consists in assigning a codeword of arbitrary length k to each of the n classes. Codewords are organized in a "code matrix" M k,n ∈ {−1, 1}, where each column is a binary partition on the label space in meta-classes. Since there are many possible bi-partitions, the design of the code is central for obtaining discriminative ones. Indeed there are several approaches for generating ECOCs: Exhaustive codes [12], BCH codes [8], random codes [3], and circular ECOC [17] are few examples of methods that generate codes independently from the inherent structure of the data.
Although ECOCs can be data-independent and even randomly generated, they can also be learnt from data: Pujol et al. propose a discriminant ECOC approach based on hierarchical partitions of the output space [33]. Subsequently, Escalera et al. [13] proposed to split complex problems into easier subclasses, embedded as binary dichotomizers in the ECOC framework, easier to optimize. In [9], it is also shown Optimal continuous ECOCs can be found by gradient descent. Griffin & Perona [18] use trees to efficiently handle multi-class problems, which posteriorly Zhang et al. improved by finding optimal partitions with spectral ECOCs [50].
In the decoding step, a sample x can be decoded as the output of k binary classifiers {f 1 (x), f 2 (x), ..., f k (x)}. Given the predicted code, the class label y corresponds to the closest row in M k,n . The most common decoding methods are the Hamming and Euclidean distances but there are more sophisticated approaches such as probabilistic-based decoding, especially with ternary codes [14].
Inspired from latest ECOC advances, we propose to integrate output codes in large-scale deep learning problems. In this context, few approaches in the literature have been presented: in [10,11], CNNs are also used to directly predict the code bits for Optical Character recognition (OCR). We go a step further by: (i) showing that the convergence speed in large scale settings with millions of images can be dramatically improved; (ii) instead of directly predicting the code bits, we integrate the euclidean decoding with the cross-entropy loss, so that the network does not only optimize individual bits independently but also intercode distances, which results in error-correction.
Our approach enhances the convergence of CNNs using random codes, i.e. when the inter-class relationships are not considered. We achieve even lower error rates with data-dependent codes, due to using more efficient data partitions. Similarly, Yang et al. also used CNNs to integrate data-independent Hadamard Codes with the Euclidean loss [48]. But due to the efficiency of data-dependent codes, our encoding proposal is shown more efficient than [48], by halving the required CNN output size, and eliminating the need of training multiple CNNs to predict code chunks. Let's define the output of the last layer of a neural network as z l , with l the depth of the network. For the sake of clarity the identity non-linearity φ(·) is used so that z l = φ(z l ). Thus, given the weights of the previous layer Θ (l−1) , and the corresponding bias b (l−1) , z l can be computed as Θ (l−1) z (l−1) + b (l−1) .

Low dimensional target embedding
In our case, we reduce the output dimensionality of a CNN, i.e. the dimensionality of z l , from n (the number of classes) to k, an arbitrary number of partitions. Then, given a design matrix M n×k , where each row encodes a class label, the predicted class is obtained by finding the distance of the output with each row of the design matrix D = M − 1 z l , with 1 a column vector constituted by ones, and obtaining the label with argmin(D). Then, we seamlessly integrate our proposal in the traditional log-likelihood and softmax loss layer.

Embedding output codes in CNNs
Given a training set {x i , y i } i = 1 : s, of image-label pairs, CNNs constitute the state-of-the-art at finding good local minima by empirical risk minimization (ERM) using the cross-entropy as the loss function J by means of backpropagation [28]: ) ∈ R is the predicted label for the i th example and y i ∈ {0, 1} the ground truth label. Since cross-entropy requires probability distributions, the output of the network z l is fed to a softmax layer that assigns a probability score to each of the n possible classes: The derivative of the loss function J for gradient descent through backpropagation is known to be: The decoder is introduced between the output z l of the network and the softmax function h(z l ). Concretely, the negative normalized Euclidean distance D(z l |M) between z l and the rows in M is used, so that the output of the softmax represents the probability of the output of the CNN to be decoded as the i th , i ∈ {1, 2, 3.., n} output word.
We reformulate the softmax function h(z l ) as h(D( z l ||z l ||2 )), with the variable change of D( z l ||z l ||2 ) by D(U) (with U(z) the normalized vector). The derivative of the loss can be computed using the chain rule: .
We now calculate: Given eq. 1 and 2, it is possible to compute the derivative of the cross-entropy with the new decoding lossĴ: Provided the amount of computation that can be shared from the forward pass to the backward pass, this process does not slow-down the training phase. In fact, the cost is compensated by (i) the shrinkage of z, which also results in a reduction of the number of network parameters, and (ii) the increase of convergence speed.
The convergence speed increases because reducing the output layer results in parameter sharing, which produces more robust gradient estimates. The explanation is that the softmax function distributes the probabilities among a high number of neurons. Thus, the the gradient δJ = y i −ŷ i is zero for most outputs because y i = 1 only once in the ground truth vector, and E(ŷ j ) = 1 n . Given that the network is certain about the output i , the expected output for the rest of the outputs is even smaller E(ŷ j =i ) = 1−y i n−1 . In other words, output layers with huge number of outputs and smaller mini-batch size can only update the weights of few output units per iteration, since activation expected value is virtually zero. Thus, the gradients for these outputs are either zero or based on too few examples. This leads to noisy estimates to the real loss surface. As a result, reducing the output space with our method increases the ratio of activations per mini-batch, helping to obtain more robust gradient estimates and increasing convergence speed, reduces the mini-batch size, and thus the memory requirements.

Connections with Normalized Cuts
CNNs trained with our approach are robust and fast even when drawing codes from a normal distribution. The reason is the fact that random gaussian matrices tend to follow the coding properties described in the literature [12,19], such as row and column orthogonality. For most large datasets the label space follows a hierarchical structure and defining random partitions of the label space is rather unnatural. In order to find the most simple partitions we use an eigenrepresentation of the class manifold based on the class similarities found in the dataset. Concretely, solving the normalized cut (Ncut) problem on the class similarity graph is a way of obtaining n uncorrelated low-cost partitions, with n the number of classes [36]. The NCut can be approximated by solving the eigendecomposition of the normalized Laplacian of the class similarity matrix L M : where M is the class similarity matrix, D is the degree matrix, λ i are the eigenvalues in ascending order and v i , the corresponding eigenvectors i ∈ {0, 1, 2, ..., k}. Given that λ 0 = 0, the eigenvectors v i , i ∈ {1, ..., k} constitute the partitions ordered by the Ncut cost. As explained in [51], this kind of codes have desirable properties such as balancing, orthogonality, lower error bounds due to the separability maximization, and similarity preserving, i.e. similar classes have similar codes. We show that training CNNs to predict the embedded target, together with this data-based codes, exhibit lower error rates than using random codes. Contrary to [50], we do not threshold the eigenvectors so as to obtain a binary code but we interpret the values as likelihoods.
In the following section, we provide empirical evidence confirming that CNNs trained with our proposed methodology on CIFAR-100, CUB-200, MIT Places, and Imagenet have faster convergence rates (with comparable or better recognition rates), even with smaller mini-batch size, than their one-hot counterparts.

Experiments
To validate our approach, we perform a thorough analysis of the advantages of embedding output codes in CNN models over different state-of-the-art datasets. First, we describe the considered datasets, methods and evaluation.

Datasets
We first experiment the ImageNet 2012 Large-Scale Visual Recognition Challenge (ILSVRC-2012) [35] and the MIT Places-205 [51] datasets. ImageNet consists of 1.2M images, and 50K validation images with 10K object classes. MIT Places is constituted by 2.5M images from 205 scene categories for training, and 100 images for category for testing.

Methods and evaluation
We use standard state-of-the-art models to evaluate the contribution of the proposed target embedding procedure instead of comparing with state-of-the-art results on the considered datasets. Note that any model, including more recent and powerful state-of-the-art architectures, can benefit from our target embedding methodology.
As a proof of concept, we first validate data-independent codes on the Imagenet and MIT Places datasets. Concretely, we retrain with our approach the fc7 and fc8 layers of an Alexnet model [27] pre-trained on the respective datasets. Concretely, we randomly reinitialize their weights and train them using SGD with a global learning rate (lr) of 0.001, and the specific lr of the reinitialized layers is multiplied by 10.
Then, we demonstrate the advantages of data-dependent codes on the fine-grained CIFAR-100 and CUB-200 2011. For CIFAR-100, we use the cifar quick models found in the Caffe framework [22]. The network is initialized with noise sampled from a gaussian distribution, and the model is trained for 100 epochs. Fine-tuning on CUB-200 is performed with the same pre-trained model of the Imagenet experiments for 30 epochs, and the lr is divided by 10 after 15 epochs.
Experiments with the standard Alexnet CNN [27] (caffe version [22]) on Imagenet, and MIT Places, prove that CNNs trained with random codes and our approach show faster convergence rates than using one-hot encoding, especially for small mini-batch sizes, while matching one-hot in performance for bigger mini-batch sizes. Thus, the proposed data-dependent encoding approach performs better than using random codes for fine-grained datasets, with fuzzy inter-class boundaries, essentially because random codes alone do not take into account the correlation of attributes.

Random codes for faster convergence
Output encodings allow to embed sparse output spaces into compact representations. For instance, codes generated with the dense random strategy only need k = 10log(n) bits [3] to encode n classes. An inherent property of one-hot encoding is the output activation sparsity for huge output spaces. Given a randomly initialized CNN with one-hot encoding, provided that the output neurons follow a uniform distribution, the probability assigned to each class will be 1 n , n = #Classes, which tends to 0 for n → ∞. In the final stages of training, the situation will persist since just an extremely small ratio of the neurons activate, i.e. a small subset of the neurons show high probability for the predicted class while the residual probability mass is spread over a much larger number of neurons.
Thus, it can be coarsely estimated that the update probability of the parameters associated to an output neuron during an SGD step is related to the ratio ρ = bs n , with mini-batch size bs, being ρ = 256 · 10 3 for Alexnet trained on Imagenet, provided that p(Y = n i ) = p(Y = n j ), i = j. In other words, given a label,  sampling more images increases the probability of that label being in the set of samples, and drawing less samples than the number of labels ensures that at least n − s labels will not be seen during the update. Figure 2 shows the resulting validation accuracy when training Alexnet on the ILSVRC2012 and MIT Places for different mini-batches and a random code sampled from N (0, 1). As it can be seen, models trained with our approach converge faster than those trained with one-hot encoding.

Using data-based encodings
In order to adapt to fine-grained settings, i.e. with high inter-class correlations, and few examples per class, we propose to generate the output codes using the eigenvectors of the normalized Laplacian of the class similarity matrix. Since this eigendecomposition generates the most discriminating, hierarchical partitions based on the data, models trained with this data-dependent codes result in higher accuracy bounds than the random counterparts.
To confirm the aforementioned advantages of using data-dependent codes we choose to experiment on the well-established CIFAR-100 and CUB-200 2011 fine-grained datasets. see Fig. 3. We use CIFAR-100 for fast experimentation, and then we apply the best setting to CUB-200.    Table 1: Influence of code designs on CIFAR-100. Dense output encodings are more robust than One-hot to the loss of bits. As expected, data-based codes outperform the rest of encodings (50%), especially when no threshold is applied to binarize the code.  Figure 4: T-sne visualization on CIFAR-100 on the ten coarse categories for the hidden fc layer of a CNN trained with (a) one-hot encoding, (b) an output code generated with the dense random strategy, and (c) a data-based code.
2. Dense random [3]. Sampling the matrix with the most uncorrelated rows and columns from U(0, 1). 3. Gaussian. Sampling matrices from a normal distribution. 4. Data-based. Constructing the code matrix from the eigenvalues of the class similarity Laplacian.
Note that Gaussian and Data-based codes are composed of real numbers and a thresholding function should be applied for obtaining binary partitions. We test thresholding at zero and the median of the rows of the code matrix. Additionally, we test the raw values, interpreting them as the likelihood of the k th metaclass to be present in the n th class.
As it can be seen in table 1, output encodings are more robust, losing a smaller percentage of the accuracy when the number of code-bits are halved, while one-hot scales linearly with the number of bits, see 3a for a detailed analysis. In addition, data-based codes find the more discriminative partitions, resulting in better accuracy than the rest of the encodings. Moreover, keeping the raw values of the eigenvectors provides additional information about the likelihood of a metaclass to be present in a certain class, resulting in more robust predictions. Since output codes are based on binary partitions, they constrain the learning so that features are encoded to fall into hyperplanes. In figure 4 we show the 2D projection of those hyperplanes using t-sne. Note the higher overlapping of samples from different classes displayed on the target embedding space of 1-hot in comparison to dense and data-dependent alternatives. In particular, the proposed eigendecomposition of the output space shows a more discriminative splitting of the data samples according to their labels. CUB-200. Figure 5 shows that using small mini-batch sizes with data-based encodings largely outperforms the one-hot baseline for different code lengths when training a CNN on CUB-200 with data-dependent codes based on the raw eigenvalues of the class similarity matrix (best setting on CIFAR100). Moreover, in figure 3b, it can be seen that the data-based code matches the one-hot encoding with just the 25% of the bits. As expected, the first bits correspond to the most discriminative partitions ordered by cut cost. The class similarity matrix was built with the fc7 outputs of a pre-trained network, but any other would also work if it reflects the inter-class relationships. Figure 6 contains the confusion matrices for ten of the CUB-200 classes. Note that data-dependent encodings find low cost partitions, discriminating classes prone to be confused in the first stages of the hierarchy (the first encoding bits), and keeping those harder classification problems to the leafs. A comparison of one-hot, random and data-dependent encodings for the classification of "Fish crow" and "Grackle" is shown in figure 8.      Concretely, the first bit of the code, i.e. the partition with the lowest cut cost, is highly correlated with shape and size attributes (0.79). The sign of the PPC indicates the expected side of the bi-partition associated for the attribute. As expected, the PPC coefficient decreases in absolute value as the cut cost increases, since higher bits correspond to increasingly difficult partitions.
We lastly verify the correspondence of the metaclasses found with data-dependent encodings by computing the Pearson Correlation Coefficient (CCP) between the columns of the code-matrix and the attributes associated to each of the CUB-200 classes, see table 2.
As expected, the data-dependent code finds a high-level partition that already discriminates both classes. One-hot, instead acts directly at the class level, without being explicitly based on shared attributes. On the other hand, random codes, although also based on metaclasses (attributes), do not guarantee that those metaclasses are the most discriminative ones.

Conclusion
In this work, output codes are integrated with the training of deep CNNs on large-scale datasets. We found that CNNs trained on CIFAR-100, CUB200, Imagenet, and MIT Places using our approach show less sparsity at the output neurons. As a result, models trained with our approach showed more robust

Fish Crow
One-hot Random Data-dependent gradient estimates and faster convergence rates than those trained with the prevalent one-hot encoding at a small cost, especially for huge label spaces. As a side effect, CNNs trained with our approach can use smaller minibatch sizes, lowering the memory consumption. Moreover, we showed that training with datadependent codes based on eigenrepresentations of the class space allows for more efficient, hierarchical representations, achieving lower error rates than those trained with data-independent output codes.