PECOS - Predictions for Enormous and Correlated Output Spaces
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.
Extreme Multi-label Ranking and Classification
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
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.
Requirements and Installation
- Python (>=3.6)
- Pip (>=19.3)
- Ubuntu 16.04, 18.04 and 20.04
- Amazon Linux 2
Installation from Wheel
PECOS can be installed using pip as follows:
pip3 install libpecos
Installation from Source
Prerequisite builder tools
- 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'
Install and develop locally
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 shape
N by Din
SciPy CSR format
- instance-to-label matrix
Y, of shape
N by Lin
SciPy CSR format
Some toy data matrices are available in the
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): >>> y_tst_pred = model.predict(X_tst[i], threads=1)
If you find PECOS useful, please consider citing our papers.
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
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.