Package: libpecos
PECOS - Predictions for Enormous and Correlated Output SpacesPECOS is a versatile and modular machine learning (ML) framework for fast learning and inference on problems with large output spaces, such as extreme multi-label ranking (XMR) and large-scale retrieval.
PECOS' design is intentionally agnostic to the specific nature of the inputs and outputs as it is envisioned to be a general-purpose framework for multiple distinct applications.Given an input, PECOS identifies a small set (10-100) of relevant outputs from amongst an extremely large (~100MM) candidate set and ranks these outputs in terms of relevance.FeaturesExtreme Multi-label Ranking and ClassificationX-Linear (pecos.xmc.xlinear): recursive linear models learning to traverse an input from the root of a hierarchical label tree to a few leaf node clusters, and return top-k relevant labels within the clusters as predictions. See more details in thePECOS paper (Yu et al., 2020).fast real-time inference in C++can handle 100MM output spaceXR-Transformer (pecos.xmc.xtransformer): Transformer based XMC framework that fine-tunes pre-trained transformers recursively on multi-resolution objectives. It can be used to generate top-k relevant labels for a given instance or simply as a fine-tuning engine for task aware embeddings. See technical details inXR-Transformer paper (Zhang et al., 2021).easy to extend with many pre-trained Transformer models fromhuggingface transformers.establishes the State-of-the-art on public XMC benchmarks.ANN Search with HNSW (pecos.ann.hnsw): a PECOS Approximated Nearest Neighbor (ANN) search module that implements the Hierarchical Navigable Small World Graphs (HNSW) algorithm (Malkov et al., TPAMI 2018).Supports both sparse and dense input featuresSIMD optimization for both dense/sparse distance computationSupports thread-safe graph construction in parallel on multi-core shared memory machinesSupports thread-safe Searchers to do inference in parallel, which reduces inference overheadRequirements and InstallationPython (3.7, 3.8, 3.9, 3.10)Pip (>=19.3)See other dependencies insetup.pyYou should install PECOS in avirtual environment.
If you're unfamiliar with Python virtual environments, check out theuser guide.Supporting PlatformsUbuntu 20.04 and 22.04Amazon Linux 2Installation from WheelPECOS can be installed using pip as follows:python3-mpipinstalllibpecosInstallation from SourcePrerequisite builder toolsFor Ubuntu (20.04, 22.04):sudoapt-getupdate&&sudoapt-getinstall-ybuild-essentialgitpython3python3-distutilspython3-venvFor Amazon Linux 2:sudoyum-yinstallpython3python3-develpython3-distutilspython3-venv&&sudoyum-ygroupinstall'Development Tools'One needs to install at least one BLAS library to compile PECOS, e.g.OpenBLAS:For Ubuntu (20.04, 22.04):sudoapt-getinstall-ylibopenblas-devFor Amazon Linux 2:sudoamazon-linux-extrasinstallepel-y
sudoyuminstallopenblas-devel-yInstall and develop locallygitclonehttps://github.com/amzn/pecoscdpecos
python3-mpipinstall--editable./Quick TourTo have a glimpse of how PECOS works, here is a quick tour of using PECOS API for the XMR problem.Toy ExampleThe eXtreme Multi-label Ranking (XMR) problem is defined by two matricesinstance-to-feature matrixX, of shapeN by DinSciPy CSR formatinstance-to-label matrixY, of shapeN by LinSciPy CSR formatSome toy data matrices are available in thetst-datafolder.PECOS constructs a hierarchical label tree and learns linear models recursively (e.g., XR-Linear):>>>frompecos.xmc.xlinear.modelimportXLinearModel>>>frompecos.xmcimportIndexer,LabelEmbeddingFactory# Build hierarchical label tree and train a XR-Linear model>>>label_feat=LabelEmbeddingFactory.create(Y,X)>>>cluster_chain=Indexer.gen(label_feat)>>>model=XLinearModel.train(X,Y,C=cluster_chain)>>>model.save("./save-models")After learning the model, we do prediction and evaluation>>>frompecos.utilsimportsmat_util>>>Yt_pred=model.predict(Xt)# print precision and recall at k=10>>>print(smat_util.Metrics.generate(Yt,Yt_pred))PECOS also offers optimized C++ implementation for fast real-time inference>>>model=XLinearModel.load("./save-models",is_predict_only=True)>>>foriinrange(X_tst.shape[0]):>>>y_tst_pred=model.predict(X_tst[i],threads=1)CitationIf you find PECOS useful, please consider citing the following paper:PECOS: Prediction for Enormous and Correlated Output Spaces (Yu et al., JMLR 2022)[bib]Some papers from PECOS team:Representer Points for Explaining Recommender Systems (Tsai et al., ICML 2023)[bib]PINA: Leveraging Side Information in eXtreme Multilabel Classification via Predicted Instance Neighborhood Aggregation (Chien et al., ICML 2023)[bib]Uncertainty Quantification in Extreme Classification (Jiang et al., SIGIR 2023)[bib]FINGER: Fast Inference for Graph-based Approximate Nearest Neighbor Search (Chen et al., WWW 2023)[bib]End-to-End Learning to Index and Search in Large Output Space (Gupta et al., NeurIPS 2022)[bib]Relevance under the Iceberg: Reasonable Prediction for Extreme Multi-label Classification (Jiang et al., SIGIR 2022)[bib]Extreme Zero-Shot Learning for Extreme Text Classification (Xiong et al., NAACL 2022)[bib]Node Feature Extraction by Self-Supervised Multi-scale Neighborhood Prediction (Chien et al., ICLR 2022)[bib]Accelerating Inference for Sparse Extreme Multi-Label Ranking Trees (Etter et al., WWW 2022)[bib]Fast Multi-Resolution Transformer Fine-tuning for Extreme Multi-label Text Classification (Zhang et al., NeurIPS 2021)[bib]Label Disentanglement in Partition-based Extreme Multilabel Classification (Liu et al., NeurIPS 2021)[bib]Enabling Efficiency-Precision Trade-offs for Label Trees in Extreme Classification (Baharav et al., CIKM 2021)[bib]Extreme Multi-label Learning for Semantic Matching in Product Search (Chang et al., KDD 2021)[bib]Session-Aware Query Auto-completion using Extreme Multi-label Ranking (Yadav et al., KDD 2021)[bib]Top-k eXtreme Contextual Bandits with Arm Hierarchy (Sen et al., ICML 2021)[bib]Taming pretrained transformers for extreme multi-label text classification (Chang et al., KDD 2020)[bib]LicenseCopyright (2021) Amazon.com, Inc.Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.