End-to-End Learning to Index and Search in Large Output Spaces
Abstract
Extreme multi-label classification (XMC) is a popular framework for solving many real-world problems that require accurate prediction from a very large number of potential output choices.
A popular approach for dealing with the large label space is to arrange the labels into a shallow tree-based index and then learn an
ML model to efficiently search this index via beam search.
Existing methods initialize the tree index by clustering the label space into a few mutually exclusive clusters based on pre-defined features and keep it fixed throughout the training procedure.
This approach results in a sub-optimal indexing structure over the label space and limits the search performance to the quality of choices made during the initialization of the index.
In this paper, we propose a novel method ELIAS which relaxes the tree-based index to a specialized weighted graph-based index which is learned end-to-end with the final task objective.
More specifically, ELIAS models the discrete cluster-to-label assignments in the existing tree-based index as soft learnable parameters that are learned jointly with the rest of the ML model.
ELIAS achieves state-of-the-art performance on several large-scale extreme classification benchmarks with millions of labels.
In particular, ELIAS can be up to 2.5% better at precision@ 1 and up to 4% better at recall@ 100 than existing XMC methods.
A PyTorch implementation of ELIAS along with other resources is available at https://github.com/nilesh2797/ELIAS.
Introduction
Many real-world problems require making accurate predictions from a large number of potential output choices.
For example, search advertising aims to find the most relevant ads to a given search query from a large corpus of ads [26, 14], open-domain question answering requires finding the right answers to a given question from a large collection of text documents [8, 29], and product recommendation requires recommending similar or related products from a large product catalog, based on past searches and interactions by users.
eXtreme Multi-label Classification (XMC) is a popular framework for solving such problems [4], which formulates these problems as a multi-label classification task with very large number of labels; here each output choice is treated as a separate label.
A label ℓ is often parameterized by its one-versus-all classifier vector w ℓ and the relevance between label ℓ and input x is formulated as w Tℓ ϕ ( x ) , where ϕ is an encoding function which maps an input x to its vector representation.
[Figure]
Evaluating w Tℓ ϕ ( x ) for every label l in an XMC task can get computationally expensive since the number of labels could easily be upwards of millions.
To reduce the complexity, most existing methods employ a search index that efficiently shortlists a small number of labels for an input query and the relevance scores are only evaluated on these shortlisted labels.
The quality of the search index plays a pivotal role in the accuracy of these methods since a label ℓ outside the shortlist will be directly discarded, even if it can be correctly captured by its classifier vector w ℓ .
Moreover, the label classifier w ℓ is a function of the quality of the index as during training, the label classifiers are learned with negative sampling based on the search index.
Therefore, how to improve the quality of the search index becomes a key challenge in the XMC problem.
There are two main formulations of the search index: 1) partition-based approach [25, 31, 7, 18, 32] and 2) approximate nearest neighbor search (ANNS) based approach [15, 10, 13, 9].
In partitionbased approach, labels are first arranged into a tree-based index by partitioning the label space into mutually exclusive clusters and then a ML model is learned to route a given instance to a few relevant clusters.
In an ANNS-based approach, a fixed, black-box ANNS index is learned on pre-defined label embeddings.
Given an input embedding, this index is then used to efficiently query a small set of nearest labels based on some distance/similarity between the input and label embeddings.
Both of these approaches suffer from a critical limitation that the index structure is fixed after it’s initialized.
This decoupling of the search index from the rest of the ML model training prevents the search index from adapting with the rest of the model during training, which leads to sub-optimal performance.
To overcome this challenge, we propose a novel method called ELIAS:
E nd-to-end L earning to I ndex a nd S earch, which jointly learns the search index along with the rest of the ML model for multi-label classification in large output spaces.
In particular, as illustrated in Fig. 1, ELIAS generalizes the widely used partition tree-based index to a sparsely connected weighted graph-based index.
ELIAS models the discrete cluster-to-label assignments in the existing partition based approaches as soft learnable parameters that are learned end-to-end with the encoder and classification module to optimize the final task objective.
Moreover, because ELIAS uses a graph-based arrangement of labels instead of a tree-based arrangement, a label can potentially be assigned to multiple relevant clusters.
This helps to better serve labels with a multi-modal input distribution [22].
Through extensive experiments we demonstrate that ELIAS achieves state-of-the-art results on multiple large-scale XMC benchmarks.
Notably, ELIAS can be up to 2.5% better at precision@ 1 and up to 4% better at recall@100 than existing XMC methods.
ELIAS’s search index can be efficiently implemented on modern GPUs to offer fast inference times on million scale datasets.
In particular,
ELIAS offers sub-millisecond prediction latency on a dataset with 3 million labels on a single GPU.
Related Work
One-vs-all (OVA) methods : OVA methods consider classification for each label as an independent binary classification problem.
In particular, an OVA method learns L (number of classes) independent label classifiers [ w l ] Ll =1 , where the job of each classifier w l is to distinguish training points of label l from the rest of the training points.
At prediction time, each label classifier is evaluated and the labels are ranked according to classifier scores.
Traditional OVA methods like DiSMEC [2], ProXML [3], and PPDSparse [30] represent each input instance by their sparse bag-of-word features and learn sparse linear classifiers by massively parallelizing over multiple machines.
OVA methods achieve promising results on XMC benchmarks but suffer from huge computational complexity because of their linear scaling with number of labels.
Subsequent XMC methods borrow the same building blocks of an OVA approach but overcome the computational overhead by employing some form of search index to efficiently shortlist only a few labels during training and prediction.
Partition based methods : Many XMC methods such as Parabel [25], Bonsai [19], XR-Linear [32],
AttentionXML [31], X-Transformer [28], XR-Transformer [33], LightXML [18] follow this approach where the label space is partitioned into a small number of mutually exclusive clusters, and then an
ML model is learned to route a given instance to a few relevant clusters.
A popular way to construct clusters is to perform balanced k -means clustering recursively using some pre-defined input features.
Traditional methods like Parabel, Bonsai, and XR-Linear represent their input by sparse bag-of-word features and learn sparse linear classifiers with negative sampling performed based on the search index.
With the advancement of deep learning in NLP, recent deep learning based XMC methods replace sparse bag-of-word input features with dense embeddings obtained from a deep encoder.
In particular, AttentionXML uses a BiLSTM encoder while X-Transformer, XR-Transformer, and
LightXML use deep transformer models such as BERT [11] to encode the raw input text.
In addition to dense embeddings, the state-of-the-art XR-Transformer method uses a concatenation of dense embedding and sparse bag-of-word features to get a more elaborate representation of the input, thus mitigating the information loss in text truncation in transformers.
ANNS based methods : Methods like SLICE [15], DeepXML [10], and GLaS [13] utilize approximate nearest neighbor search (ANNS) structure over pre-defined label representations to efficiently shortlist labels.
In particular, SLICE represents each input instance by its FastText [24] embedding and uses the mean of a label’s training points as a surrogate embedding for that label.
It further constructs an HNSW [23] graph (a popular ANNS method) over these surrogate label embeddings.
For a given input, the HNSW graph is queried to efficiently retrieve nearest indexed labels based on the cosine similarity between the input and label embedding.
DeepXML extends SLICE by learning an MLP text encoder on a surrogate classification task instead of using a fixed FastText model to obtain input embeddings.
GLaS takes a different approach and learns label classifiers with random negative sampling.
After the model is trained, it constructs an ANNS index to perform fast maximum inner product search (MIPS) directly on the learned label classifiers.
Learning search index : There has been prior works [21, 1] that model different types of standard data structures with neural networks.
A recent paper [27] models the search index in information retrieval systems as a sequence to sequence model where all the parameters of the search index is encoded in the parameters of a big transformer model.
In a more similar spirit to our work, another recent paper [22] attempts to learn overlapping cluster partitions for XMC tasks by assigning each label to multiple clusters.
Even though it serves as a generic plug-in method to improve over any existing partition based XMC method, it still suffers from the following shortcomings: 1) label assignments are not learned end-to-end with the task objective; instead, it alternates between finding the right model given the fixed label assignments and then finding the right label assignments given the fixed model, 2) all labels are assigned to a pre-defined number of clusters with equal probability and get duplicated in each assigned cluster, which results in increased computational complexity of the method.
ELIAS: End-to-end Learning to Index and Search
The multi-label classification problem can be formulated as following: given an input x ∈ X , predict y ∈ { 0 , 1 } L where y is a sparse L dimensional vector with y ℓ = 1 if and only if label ℓ is relevant to input x .
Here, L denotes the number of distinct labels - note that y can have multiple non-zero entries resulting in multiple label assignments to input x .
The training dataset is given in the form of { ( x i , y i ) :
i = 1 , ..., N } .
XMC methods address the case where the label space ( L ) is extremely large (in the order of few hundred thousands to millions).
All deep learning based XMC methods have the following three key components:
Deep encoder ϕ : X → R D which maps the input x to a D -dimensional dense embedding through a differentiable function.
For text input, a popular choice of ϕ is the BERT [11] encoder where each input x is represented as a sequence of tokens.
[Figure]
Search Index I : X → R L shortlists K labels along with a score assigned to each shortlisted label for a given input x .
More specifically, ˆ y
= I ( x ) is a sparse real valued vector with only K ( ≪ L ) non-zero entries and ˆ y ℓ ̸ = 0 implies that label ℓ is shortlisted for input x with shortlist relevance score ˆ y ℓ .
As illustrated in Figure 1, many partition based methods [18, 33] formulate their index as a label tree derived by hierarchically partitioning the label space into C clusters and then learn classifier vectors ˆ W C
=
[ ˆ w c ]
Cc =1 ( ˆ w c ∈ R D ) for each cluster which is used to select only a few clusters for a given input.
More specifically, given the input x , the relevance of cluster c to input x is quantified by cluster relevance scores
ˆ s c
= ˆ w Tc ϕ
( x ) .
The top- b clusters based on these scores are selected and all labels inside the shortlisted clusters are returned as the shortlisted labels, where b ( ≪ C ) is a hyperparameter denoting the beam-size.
Label classifiers
W L = [ w ℓ ]
Lℓ =1 where w ℓ ∈ R D represents the classifier vector for label ℓ and w Tℓ ϕ
( x ) represents the label relevance score of label ℓ for input x .
As explained above, w Tℓ ϕ ( x ) is only computed for a few shortlisted labels obtained from the search index I .
3.1 ELIAS Index
ELIAS formulates its label index as a specialized weighted graph between a root node ∅ , C cluster nodes C
= { c } Cc =1 and L label nodes Y = { ℓ } Lℓ =1 .
As illustrated in Figure 2, all cluster nodes are connected to the root node and all label nodes are sparsely connected to few cluster nodes.
ELIAS parameterizes the cluster-to-label edge assignments by a learnable adjacency matrix A =
[ a c,ℓ ] C × L , where the scalar parameter a c,ℓ denotes the edge importance between cluster c and label ℓ .
Note that A can be very large for XMC datasets and using a dense A will incur O ( CL ) cost in each forward pass which can be computationally prohibitive for large-scale datasets.
To mitigate this we restrict A to be a row-wise sparse matrix i.e. ∥ a i ∥ 0 ≤ κ where ∥ .
∥ 0 represents the ℓ 0 norm, a i represents the i th row of A and κ is a hyper-parameter which controls the sparsity of A .
During training, only the non-zero entries of A is learned and the zero entries do not participate in any calculation.
We defer the details of how we initialize the sparsity structure of A to Section 3.4.
Existing partition based XMC methods can be thought of as a special case of this formulation by adding additional restrictions that 1) each label is connected to exactly one cluster node, and 2) all cluster-to-label connections have equal importance.
Moreover, existing methods initialize the cluster-to-label adjacency matrix A beforehand based on clustering over pre-defined features and keep it fixed throughout the training procedure.
ELIAS overcomes these shortcomings by enabling the model to learn the cluster-to-label edge importance.
3.2 Forward Pass
ELIAS trains the entire model, including the deep encoder ϕ , the search index parameters ˆ W C , A and the label classifiers W L in an end-to-end manner.
We now describe the details of the forward pass of ELIAS.
Text representation : An input x is embedded by the encoder ϕ into a dense vector representation ϕ ( x ) .
In particular, we use BERT-base [11] as the encoder and represent ϕ ( x ) by the final layer’s
CLS token vector.
Query search index : Recall that the goal of the search index I is to efficiently compute a shortlist of labels ˆ y ∈ R L , where ˆ y is a sparse real valued vector with K ( ≪ L ) non-zero entries and ˆ y ℓ ̸ =implies that label ℓ is shortlisted for input x with shortlist score ˆ y ℓ .
Similar to existing methods,
ELIAS achieves this by first shortlisting a small subset of clusters ˆ C ⊂ C based on cluster relevance scores defined by ˆ w Tc ϕ ( x ) .
But unlike existing methods which simply return the union of the fixed label set assigned to each shortlisted cluster, ELIAS shortlists the top- K labels based on the soft cluster-to-label assignments and backpropagates the loss feedback to each of the shortlisted paths.
More specifically, ELIAS defines the cluster relevance scores
ˆ s C ∈ R C as:
[Equation]
Here hyperparameter α is multiplied by the softmax scores to allow multiple clusters to get high relevance scores.
Intuitively, α controls how many effective clusters can simultaneously activate for a given input (in practice, we keep α ≈ 10 ).
Given cluster relevance scores ˆ s C , we define set C topb as the top b clusters with the highest cluster relevance scores, where b ( ≪ C ) is the beam size hyperparameter.
In the training phase, we further define a parent set C parent to guarantee that the correct labels of x are present in the shortlist.
More specifically, for each positive label of x , we include the cluster with the strongest edge connection to l in C parent .
The shortlisted set ˆ C is defined as the union of these two sets and the selection process can be summarized as follows:
[Equation]
After shortlisting a small subset of clusters ˆ C , all potential edges of shortlisted clusters are explored and a set ˆ P of explored paths is constructed, where ˆ P = {∅ → c → ℓ : c ∈ ˆ C and a c,ℓ > 0 } .
Furthermore, each path ∅ → c → ℓ ∈ ˆ P is assigned a path score ˆ s ∅ ,c,ℓ , where the path score ˆ s ∅ ,c,ℓ is expressed as the product of cluster relevance score ˆ s c (defined by Eqn. 1) and edge score ˆ s c,ℓ which quantifies the probability of label ℓ getting assigned to cluster c and is defined in terms of the learnable edge weight parameter a c,ℓ as follows:
[Equation]
a
[Equation]
[Figure]
Defining edge scores
ˆ s c,ℓ in such a manner allows modelling the desired probability distribution of label assignment to a cluster, where a few relevant labels are assigned to a particular cluster with probability 1, and all other labels have probability 0.
Hyperparameter β controls how many effective labels can get assigned to a cluster, we choose β ≈ L/C .
Figure 3 empirically confirms that the trained model indeed learns the desired edge score distribution with most of the probability concentrated on a few labels and the rest of the labels getting assigned low probability.
Moreover, this formulation also prevents labels with high softmax scores from overpowering edge assignments because as per 5, a relevant label ℓ for cluster c gets positive feedback for a c,ℓ only if a normc,ℓ < 1 /β , otherwise a c,ℓ does not participate in the calculation of ˆ s c,ℓ .
This allows clusters to learn balanced label assignments.
Note that, because of the assumption that A is a row-wise sparse matrix, Eqn.can be computed efficiently in O ( κ ) instead of O ( L ) time.
Since there can be multiple paths in ˆ P which reach a particular label ℓ , ELIAS defines shortlist score ˆ y ℓ for label ℓ by the maximum scoring path in ˆ P that reaches ℓ , i.e.
[Equation]
Finally, only the top- K entries in ˆ y are retained and the resulting vector is returned as the shortlist for input x .
Evaluating label classifiers : label classifiers [ w ℓ ]
Lℓ =1 are evaluated for the K non-zero labels in ˆ y and the final relevance score between label ℓ and input x is returned as p ℓ = σ ( w Tℓ ϕ ( x )) ∗ ˆ y ℓ , here σ is the sigmoid function.
3.3 Loss
ELIAS is trained on a combination of classification and shortlist loss where the shortlist loss encourages correct labels to have high shortlist scores ( ˆ y ℓ ) and classification loss encourages positive labels in the shortlist to have high final score ( p ℓ ) and negative labels in the shortlist to have low final score.
More specifically, the final loss L is defined as L =
L c + λ L s , where λ is a hyperparameter and classification loss L c is defined as binary cross entropy loss over shortlisted labels
[Equation]
shortlist loss L s is defined as negative log likelihood loss over the positive labels
[Equation]
3.4 Staged Training
Previous sub-sections described the ELIAS framework for learning the index graph along with the
ML model in an end-to-end manner.
Although, in principle one can optimize the network with the given loss function from a random initialization but we highlight a few key challenges in doing so: 1)
Optimization challenge : because of the flexibility in the network to assign a label node to various clusters, it becomes hard for a label to get confidently assigned to only a few relevant clusters.
As a result, the model is always chasing a moving target and for a given input it is not able to be sure about any single path; 2) Computational challenge : the full cluster-label adjacency matrix A can be very large for large datasets and will incur O ( CL ) cost in each forward pass if implemented in dense form.
To address these challenges we train the ELIAS model in two stages.
In the first stage, we only train the encoder ϕ , cluster classifiers ˆ W C , and label classifiers W L keeping A fixed and assigned based on traditional balanced partitions.
We then utilize the stage-1 trained model to initialize the sparse adjacency matrix A .
In the second stage, we take the initialized A and rest of the stagemodel, and jointly train the full model ϕ, ˆ W C , W L , A .
Stage 1 : In stage 1 training, similar to existing partition-based XMC methods, we partition the label space into C mutually exclusive clusters by performing balanced k -means clustering over pre-defined label features.
The adjacency matrix induced by these clusters is then used as fixed assignment for A .
Keeping A fixed, we train the rest of the model (i.e. ϕ, ˆ W C , W L ) on the loss described in
Section 3.3.
More details on clustering are provided in Section C.1 in the Appendix.
Initializing A : As highlighted before, to overcome the O ( CL ) cost associated with a full adjacency matrix A , we want to restrict A to be a row-wise sparse matrix.
In other words, we want to restrict each cluster to choose from a candidate subset of κ labels instead of the whole label set.
Intuitively, in order for the model to learn anything meaningful, the candidate subset for each cluster should contain approximately similar labels.
To achieve this, we utilize the stage 1 model to first generate an approximate adjacency matrix
A ′
and then select the top- κ entries in each row of A ′ as non-zero entries for A .
More specifically, we first identify top- b matched clusters for each training point x i by computing the cluster matching matrix M =
[ m i,c ] N × C as:
[Equation]
where ˆ s ic represents the cluster relevance score and C itopb represents the set of top- b clusters for i th training point x i .
After computing M , we define the approximate adjacency matrix A ′
=
[ a ′ c,ℓ ] C × L = M T Y , where Y =
[ y 1 , ..., y i , ..., y N ] T .
The element a ′ c,ℓ essentially denotes the weighted count of how many times the cluster c got placed in top- b positions for positive training points of label ℓ .
Finally, the top κ elements in each row of A ′ are selected as the non-zero parameters of A , i.e.
[Equation]
We choose a large enough κ to provide the model enough degree of freedom to learn cluster-tolabel assignments.
In particular, κ ∼ 10 × L/C works well across datasets without adding any computational burden.
For efficient implementation on GPUs, we store matrix A in the form of two tensors, one storing the non-zero indices and the other storing the values corresponding to those non-zero indices.
Stage 2 :
In stage 2 training, we initialize A as described above, and ϕ , ˆ W C from stage 1 model.
We then train the full ELIAS model (i.e. ϕ, ˆ W C , W L , A ) end-to-end to optimize the loss defined in
Section 3.3.
3.5 Sparse Ranker
State-of-the-art XMC methods like XR-Transformer [33] and X-Transformer [7] utilize high capacity sparse classifiers learned on the concatenated sparse bag-of-word features and dense embedding obtained from the deep encoder for ranking their top predictions.
Because of the high capacity, sparse classifiers are able to represent head labels more elaborately than dense classifiers.
Moreover, bag-ofwords representation is able to capture the full input document instead of the truncated document that the deep encoder receives.
[Figure]
To compare fairly with such methods, we explore an enhanced variant of ELIAS represented by ELIAS ++, which additionally learns a sparse ranker that re-ranks the top 100 predictions of
ELIAS.
In particular, the sparse ranker takes the concatenated sparse bag-of-word and dense embedding input features and learns sparse linear classifiers on the top 100 label predictions made from the trained ELIAS model for each training point.
Because these sparse classifiers are only trained on 100 labels per training point, they can be quickly trained by parallel linear solvers like LIBLINEAR [12].
We use the open-source
PECOS 2 [32] library to train and make predictions with the sparse ranker.
During prediction, the top 100 predictions are first made by
ELIAS and then the learned sparse ranker is evaluated on these top 100 predictions.
We empirically observe that the scores returned by ELIAS and sparse ranker are not well calibrated across different label regimes.
As shown in Figure 4, the sparse ranker underestimates scores on tail labels while ELIAS scores are more balanced across all label regimes.
To correct this score mis-calibration, we learn a simple score calibration module which consists of a standard decision tree classifier 3 that takes both of these scores and the training frequency of the label as input and predicts a single score denoting the label relevance.
The score calibration module is learned on a small validation set of 5,000 points.
More details on the sparse ranker are in
Appendix Section C.2.
3.6 Time Complexity Analysis
The time complexity for processing a batch of n data-points is O ( n ( T bert + Cd + bκ + Kd ))
where
T bert represents the time complexity of the bert encoder, C represents the number of clusters in index,
[Table]
d is the embedding dimension, b is the beam size, κ is the row-wise sparsity of cluster-to-label adjacency matrix A , and K is the number of labels shortlisted for classifier evaluation.
Assuming
C =
O ( √ L ) , κ = O ( L/C )
=
O ( √ L ) and K
= O ( √ L ) , the final time complexity comes out to be O ( n ( T bert + √ L (2 d + b ))) .
Empirical prediction and training times on benchmark datasets are reported in Table 6 of the Appendix.
Experimental Results
Experimental Setup We conduct experiments on three standard full-text extreme classification datasets: Wikipedia-500K, Amazon-670K, Amazon-3M and one short-text dataset: LF-AmazonTitles131K which only contains titles of Amazon products as input text.
For Wikipedia-500K, Amazon670K, and Amazon-3M, we use the same experimental setup (i.e. raw input text, sparse features and train-test split) as existing deep XMC methods [31, 33, 18, 7].
For LF-AmazonTitles-131K, we use the experimental setup provided in the extreme classification repository [5].
Comparison to existing XMC methods is done by standard evaluation metrics of precision@ K (P@ K = 1 , 3 , 5 ) and its propensity weighted variant (PSP@ K = 1 , 3 , 5 ) [16].
We also compare competing methods and baselines with ELIAS at recall@ K (R@ K = 10 , 20 , 100 ) evaluation to illustrate the superior shortlisting performance of ELIAS’s search index.
More details on the experimental setup and dataset statistics are presented in Appendix Section B.
Implementation details Similar to existing XMC methods, we take an ensemble of 3 models with different initial clustering of label space to report final numbers.
For efficient implementation on GPU, the raw input sequence is concatenated to 128 tokens for full-text datasets and 32 tokens for short-text dataset.
Number of clusters C for each dataset is chosen to be the same as LightXML which selects
C ∼ L/ 100 .
We keep the shortlist size hyperparameter K fixed to 2000 which is approximately same as the number of labels existing partition based methods shortlist assuming beam-size b =
[Table] [Table]
and the number of labels per cluster = 100 .
AdamW [20] optimizer is used to train the whole model with weight decay applied only to non-gain and non-bias parameters.
Optimization update for label classifiers W L is performed with high accumulation steps (i.e. optimization update is performed at every k training steps, where k = 10 ) since updating W L every step is a computational bottleneck and only few parameters inside W L gets updated in each optimization step anyway.
More details and hyperparameters for each dataset are presented in Appendix Section B.
Comparison on XMC benchmarks Table 1 compares our method with leading XMC methods such as DiSMEC [2], Parabel [25], XR-Linear [32], Bonsai [19], Slice [15], Astec [10], GlaS [13],
AttentionXML [31], LightXML [18], XR-Transformer [33], and Overlap-XMC [22].
Most baseline results are obtained from their respective papers when available and otherwise taken from results reported in [31, 33] and extreme classification repository [5].
To allow fair comparison among methods that use the same form of input representation, we distinguish methods that use only sparse bag-of-word input features by ( s ) superscript, methods that use only dense embedding based input features by ( d ) superscript, and methods that use both sparse + dense features by ( s + d ) superscript.
ELIAS ++ which uses sparse + dense features achieves state-of-the-art performance on all datasets at precision values while being either the best or second best method at propensity scored precision on most datasets.
The dense embedding based ELIAS ( d ) consistently outperforms existing dense embedding based XMC methods by significant margin and on many occasions achieves gains over previous state-of-the-art methods which use both sparse + dense features.
Comparison with brute-force OvA baseline To establish the classification performance that could have been achieved if there was no sampling performed by the shortlisting procedure, we implement the brute-force one-versus-all baseline BERT-OvA which consists of BERT encoder followed by a fully connected linear classification layer and is trained and inferred in one-versus-all fashion without any sampling.
We follow the same training procedures as ELIAS for this baseline.
Table 2 compares the OvA baseline with ELIAS and leading deep XMC methods such as AttentionXML, LightXML and a dense version of XR-Transformer which uses only dense embeddings, under single model (i.e. no ensemble) setup for direct comparison.
Existing deep XMC methods do not compare well against the OvA model especially at recall@100 but ELIAS matches and sometimes even marginally outperforms, the brute-force OvA baseline while enjoying faster training and inference speed due to the search index.
Component wise ablation of ELIAS Table 3 presents a build-up ablation of performance gains made by different components of ELIAS.
The stage 1 model which fixes its adjacency matrix by clustering labels into mutually exclusive clusters performs similarly to existing single model XMC methods.
Allowing the model to learn the adjacency matrix A in stage 2 improves recall by up to 7% and precision by up to 2.5% over the stage 1 model.
Adding the sparse ranker and score-calibration module further improves model performance on top predictions but the gains diminish as we increase prediction set size.
Finally, the ensemble of 3 models improves performance at all evaluation metrics which is a well observed behaviour with all XMC methods.
[Figure]
Recall comparison Next, we compare the recall capabilities of existing methods with ELIAS.
The left plot in Figure 5 plots the recall at different prediction set size for all competing methods and
ELIAS.
ELIAS strictly outperforms existing methods at all prediction set sizes and in particular, can be up to 4% better at recall@ 100 than the next best method.
To further investigate which label regimes benefit most from ELIAS’s search index we plot the decile wise contribution to recall@100 for each method.
As we can see, ELIAS improves recall performance over existing methods in each label decile but the most improvement come from the top 2 deciles representing the most popular labels.
We hypothesize that because the popular labels are likely to have multi-modal input distribution, existing partition based methods which assign a label to only one cluster fail to perform well on these multi-modal labels.
Section C.4 contains additional discussion and results to support this claim.
Conclusion and Discussions
In this paper, we propose ELIAS, which extends the widely used partition tree based search index to a learnable graph based search index for extreme multi-label classification task.
Instead of using a fixed search index, ELIAS relaxes the discrete cluster-to-label assignments in the existing partition based approaches as soft learnable parameters.
This enables the model to learn a flexible index structure, and it allows the search index to be learned end-to-end with the encoder and classification module to optimize the final task objective.
Empirically, ELIAS achieves state-of-the-art performance on several large-scale extreme classification benchmarks with millions of labels.
ELIAS can be up to 2.5% better at precision@ 1 and up to 4% better at recall@ 100 than existing XMC methods.
This work primarily explores many-shot and few-shot scenarios where some training supervision is available for each label (output).
It would be interesting to see how we can adapt the proposed solution to zero-shot scenarios where there is no training supervision available for the labels.
One potential approach could be to parameterize the cluster-to-label adjacency matrix as a function of cluster and label features instead of free learnable scalars.
Furthermore, one limitation of the proposed solution is that it learns a shallow graph structure over label space; this may not be ideal for scaling the method to billion-scale datasets.
It would be exciting to explore how one can extend ELIAS to learn deep graph structures.
A Potential Negative Societal Impact
Our method proposes to learn efficient data structure for accurate prediction in large-output space.
It helps existing large-scale retrieval systems used in various online applications to efficiently produce more accurate results.
To the best of our knowledge, this poses no negative impacts on society.
B Experimental Details B.1 ELIAS Hyperparameters
ELIAS’s hyperparameters include,
• max-len : denotes the maximum sequence length of input for the BERT encoder.
As per standard XMC practices, for full-text dataset we choose 128 and for short-text we choose• C : denotes number of clusters in the index graph, we use same values as LightXML [18] and X-Transformer [6] for fair comparison • α : multiplicative hyperparameter used in Equation 1, controls effective number of clusters that can get activated for a given input • β : multiplicative hyperparameter used in Equation 5, controls effective number of labels that can get assigned to a particular cluster • κ : controls the row-wise sparsity of adjacency matrix A , we choose κ ≈ 10 × L/C • λ : controls importance of classification loss L c and shortlist loss L s in the final loss L , we choose λ by doing grid search over the smallest dataset LF-AmazonTitles-131K • K : denotes the shortlist size, label classifiers are only evaluated on top- K shortlisted labels.
We choose K = 2000 which is approximately same as the number of labels existing partition based methods shortlist assuming beam-size b = 20 and number of labels per cluster =
• b : denotes the beam size, similar to existing partition based methods we use b =• num-epochs : denotes the total number of epochs (i
e. including stage 1 and stage 2 training) • LR W , LR ϕ : We empirically observe that the network trains faster when we decouple the initial learning rates of the transformer encoder ( LR ϕ ) with rest of the model ( LR W ).
We choose a much smaller values for LR ϕ and a relatively larger value for LR W • bsz : denotes the batch-size of the mini-batches used during training
[Table]
B.2 Datasets
LF-AmazonTitles-131K :
A product recommendation dataset where input is the title of the product and labels are other related products to the given input.
“LF-*” datasets additionally contain label features i.e. a label is not just an atomic id, label features which describe a label are also given.
For this paper, we don’t utilize these additional label features and compare ELIAS to only methods which don’t utilize label features either.
Notably, even though ELIAS doesn’t use label features it achieves very competitive performance with methods which use the label features in their model.
Amazon-670K : A product recommendation dataset where input is a textual description of a query product and labels are other related products for the query.
Wikipedia-500K : A document tagging dataset where input consists of full text of a wikipedia page and labels are wikipedia tags relevant to that page.
[ROOT]
Clusters
[Figure]
Stage
[Figure]
Initialize
[Figure]
Stage
Labels Labels
Amazon-3M : A product recommendation dataset where input is a textual description of a query product and labels are other co-purchased products for the query.
B.3 Evaluation Metrics
We use standard Precision@ K (P@ K ), propensity weighted variant of Precision (PSP@ K ), and
Recall@ K (R@ K ) evaluation metrics for comparing ELIAS to baseline methods.
For a single
[Table]
data-point i , these evaluation metrics can be formally defined as:
[Equation]
Where, y i =
[ y il ] Ll =1 , y l ∈ { 0 , 1 } represents the ground truth label vector, p represents the propensity score vector [17], ∥ .
∥ 0 represents the ℓ 0 norm, and rank ( j ) denotes the index of j th highest ranked label in prediction vector of input i .
C More on ELIAS C.1 Additional Training Details
Figure 6 illustrates the evolution of ELIAS’s search index graph over different stages of training.
In stage 1, label to cluster assignments are pre-determined and fixed by clustering all labels into C clusters.
Then, rest of the ML model i.e. ϕ, W C , W L is trained.
The model obtained after stagetraining is used to initialize the row-wise sparse adjacency matrix A as described in Section 3.4.
In stage 2, the non-zero entries in the sparse adjacency matrix A along with the rest of the ML model is trained jointly to optimize the task objective.
The clustering procedure used in stage 1 can be described as follows:
We first obtain a static representation ψ ( x i ) for each training point x i as:
[Equation]
Here, [ ] represents the concatenation operator, bow ( x i ) represents the sparse bag-of-words representation of x i and ϕ ( x i ) represents the deep encoder representation of x i .
Next we define label centroids µ l for each label as:
[Equation]
We then cluster all labels into C clusters by recursively performing balanced 2 -means [25] over label centroids { µ l } Ll =1 .
This gives us a clustering matrix C ∈ R C × L , where C c,l = 1 iff label l got assigned to cluster c .
Note that, a label is assigned to only one cluster and each cluster gets assigned equal number of labels.
We assign this clustering matrix C to the label-cluster adjacency matrix A and keep it frozen during the stage 1 training i.e. only parameters ϕ, W C , W L are trained on the loss defined in Section 3.3.
C.2 Additional Sparse Ranker Details
In this subsection we describe the training and prediction procedure of sparse ranker in more detail.
Training Sparse Ranker : Let ¯ Y i
= { ¯ y ij } 100 j =1 denote the set of top 100 predictions made by trained
ELIAS model for training point x i .
Similar to the representation used for clustering label space in
[Table]
stage 1 training, sparse ranker represents the input x i with the static representation ψ ( x i ) as:
[Equation]
It learns sparse linear classifiers ¯ W = { ¯ w l } Ll =1 , where ¯ w l ∈ R D ′ and D ′ is the dimensionality of ψ , on loss ¯ L defined as following:
[Equation]
Because these classifiers are only trained on O (100) labels per point, the complexity of ¯ L is only
O (100 × N ) .
Such sparse linear classifiers can be efficiently trained with second order parallel linear solvers like LIBLINEAR [12] on CPU.
In particular, even on the largest Amazon-3M dataset with 3 million labels, training sparse ranker only takes about an hour on a standard CPU machine with 48 cores.
Predicting with Sparse Ranker : Similar to training, we first get top 100 predictions ¯ Y i from ELIAS model for each data point x i .
Sparse classifiers are evaluated on each ( x i , l ) pair where l ∈ ¯ Y i .
Let the score of ELIAS for the pair ( x i , l ) be p il and score of sparse ranker be q il = σ ( ¯ w Tl ψ ( x i )) .
Ideally we would like the final score to be some combination of p il and q il but as observed in Section 3.5, these two scores are not very well calibrated across different label regimes.
To correct this issue, we learn a score calibration module T which consists of a standard decision tree classifier 4 trained on a small validation set of 5000 data points.
In particular, let the validation set be { ( x i , y i ) } 5000 i =1 and ¯ Y
i denote the set of top 100 predictions made by ELIAS on validation point x i .
Training data points for the score calibration module consists of all pairs (cid:83) 5000 i =1 (cid:83)
l ∈ ¯ Y i ( x i , l ) , where the input vector of a data point is a 4 dimensional vector ( p il , q il , p il ∗ q il , f l ) and the target output is y il .
Here, f l denotes the training frequency (i.e. number of training points) of label l .
During prediction, the final score for a pair ( x i , l ) is returned as T ( p il , q il , p il ∗ q il , f l ) + p il ∗ q il .
C.3 Practical Implementation and Resources Used
Many of the design choices for ELIAS’s formulation is made to enable efficient implementation of the search index on GPU.
For example, the row-wise sparsity constraint allows storing and operating the sparse adjacency matrix as two 2D tensors, which is much more efficient to work with on a GPU than a general sparse matrix.
We implement the full ELIAS model excluding the sparse ranker component in PyTorch.
Sparse ranker is implemented using LIBLINEAR utilities provided in PECOS 5 library.
All experiments are run on a single A6000 GPU.
Even on the largest dataset Amazon-3M withmillion labels, prediction latency of single ELIAS model is about 1 ms per data point and training time is 50 hours.
C.4 Additional Results
Table 7a reports the final accuracy numbers with different λ on Amazon-670K dataset.
With a very small λ the loss only focuses on the classification objective which leads to significantly worse R@ performance.
Increasing λ improves the overall performance up to a certain point, after that the performance saturates and starts degrading slowly.
Table 7b reports the effect of choosing different κ
(row-wise sparsity parameter) to the final model performance on Amazon-670K dataset.
We notice that the model performance increases up to a certain value of κ , after that the model performance (specially P@1) saturates and starts degrading slowly.
[Table]
Due to lack of space in the main paper
[Table]
the full component ablation table is reported here in Table
[Table]
D Analysis of learned index
Table 9a reports the final accuracy numbers of ELIAS-1 ( d ) model on Amazon-670K after threshold based pruning of the learned cluster-to-label assignments (i.e. for a particular threshold we remove all edges in the learned A which has smaller weight than the threshold).
These results indicate that about ∼ 84% edges can be pruned without hurting the model performance.
Similarly, table 9b reports the final accuracy numbers of ELIAS-1 ( d ) model on Amazon-670K after top- K based pruning of the learned cluster-to-label assignments (i.e. we retain only top- K label assignments per cluster).
Figure 7a plots the fraction of edges of the stage 1 tree that still remain in the learned adjacency matrix A after thresholding at various cutoff thresholds (i.e. for a threshold we only retain entries in which are greater than and evaluate how many edges of stage 1 tree remains).
on Amazon-670K dataset.
The plot reveals that almost ∼ 60% stage 1 cluster assignments remain in the learned A with good confidence.
Figure 7b plots the distribution of the average number of clusters assigned to a label for each label decile (decile 1 represents the head most decile and decile 10 represents the tail most decile).
We say that a label l is assigned to a cluster c iff the weight a c,l in the learned adjacency
[Table]
matrix A is greater than 0 .
This demonstrates a clear trend that head labels get assigned to more number of clusters than tail labels
[Table]
[Figure] [Figure]
[Figure] [Figure]
10 Deciles (decreasing frequency)
A v e r a g e nu m b e r o f c l u s t e r s
Average clusters assigned in each decile
[Figure]
In Figure 8 and 9, we qualitatively compare the training point distributions of labels which get assigned to multiple clusters and labels which get assigned to only one cluster by plotting TSNE plots of the training points of such labels and their assigned clusters.
We say that a label l is assigned to a cluster c iff the weight a c,l in the learned adjacency matrix A is greater than 0 .
These plots indicate that labels assigned to multiple clusters often have training points with a more multi-modal distribution than the labels which get assigned to only one cluster.