PECOS 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.
-
X-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 the PECOS paper (Yu et al., 2020).- fast real-time inference in C++
- can handle 100MM output space
-
X-Transformer (
pecos.xmc.xtransformer
): a Transformer matcher 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 using a linear ranker as predictions. See technical details in X-Transformer paper (Chang et al., 2020) and latest SOTA results in the PECOS paper (Yu et al., 2020).- easy to extend with many pre-trained Transformer models from huggingface transformers.
- one of the State-of-the-art in deep learning based XMC methods.
-
text2text application (
pecos.apps.text2text
): an easy-to-use text classification pipeline (with X-Linear backend) that supports n-gram TFIDF vectorization, classification, and ensemble predictions.
- Python (>=3.6)
- Pip (>=19.3)
See other dependencies in setup.py
You should install PECOS in a virtual environment.
If you're unfamiliar with Python virtual environments, check out the user guide.
- Ubuntu 16.04, 18.04 and 20.04
- Amazon Linux 2
PECOS can be installed using pip as follows:
pip3 install libpecos
- For Ubuntu (16.04, 18.04, 20.04):
apt-get update && apt-get install -y build-essential git python3 python3-distutils python3-venv
- For Amazon Linux 2:
yum -y install python3 python3-devel python3-distutils python3-venv && yum -y install groupinstall 'Development Tools'
git clone https://github.com/amzn/pecos
cd pecos
pip3 install --editable ./
To have a glimpse of how PECOS works, here is a quick tour of using PECOS API for the XMR problem.
The eXtreme Multi-label Ranking (XMR) problem is defined by two matrices
- instance-to-feature matrix
X
, of shapeN by D
inSciPy CSR format
- instance-to-label matrix
Y
, of shapeN by L
inSciPy CSR format
Some toy data matrices are available in the tst-data
folder.
PECOS constructs a hierarchical label tree and learns linear models recursively (e.g., XR-Linear):
>>> from pecos.xmc.xlinear.model import XLinearModel
>>> from pecos.xmc import Indexer, 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
>>> from pecos.utils import smat_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)
>>> for i in range(X_tst.shape[0]):
>>> y_tst_pred = model.predict(X_tst[i], threads=1)
If you find PECOS useful, please consider citing our papers.
-
PECOS: Prediction for Enormous and Correlated Output Spaces (Yu et al., 2020) [bib]
-
Accelerating Inference for Sparse Extreme Multi-Label Ranking Trees (Etter et al., 2021) [bib]
-
Label Disentanglement in Partition-based Extreme Multilabel Classification (Liu et al., 2021) [bib]
-
Enabling Efficiency-Precision Trade-offs for Label Trees in Extreme Classification (Baharav et al., 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]
Copyright (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 at
http://www.apache.org/licenses/LICENSE-2.0
Unless 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.