🦖 Rax: Learning-to-Rank using JAX
Rax is a Learning-to-Rank library written in JAX. Rax provides off-the-shelf implementations of ranking losses and metrics to be used with JAX. It provides the following functionality:
- Ranking losses (
rax.*_loss):rax.softmax_loss,rax.pairwise_logistic_loss, ... - Ranking metrics (
rax.*_metric):rax.mrr_metric,rax.ndcg_metric, ... - Transformations (
rax.*_t12n):rax.approx_t12n,rax.gumbel_t12n, ...
Ranking
A ranking problem is different from traditional classification/regression problems in that its objective is to optimize for the correctness of the relative order of a list of examples (e.g., documents) for a given context (e.g., a query). Rax provides support for ranking problems within the JAX ecosystem. It can be used in, but is not limited to, the following applications:
- Search: ranking a list of documents with respect to a query.
- Recommendation: ranking a list of items given a user as context.
- Question Answering: finding the best answer from a list of candidates.
- Dialogue System: finding the best response from a list of responses.
Synopsis
In a nutshell, given the scores and labels for a list of items, Rax can compute various ranking losses and metrics:
import jax.numpy as jnp
import rax
scores = jnp.array([2.2, -1.3, 5.4]) # output of a model.
labels = jnp.array([1.0, 0.0, 0.0]) # indicates doc 1 is relevant.
rax.ndcg_metric(scores, labels) # computes a ranking metric.
# 0.63092977
rax.pairwise_hinge_loss(scores, labels) # computes a ranking loss.
# 2.1
All of the Rax losses and metrics are purely functional and compose well with
standard JAX transformations. Additionally, Rax provides ranking-specific
transformations so you can build new ranking losses. An example is
rax.approx_t12n, which can be used to transform any (non-differentiable)
ranking metric into a differentiable loss. For example:
loss_fn = rax.approx_t12n(rax.ndcg_metric)
loss_fn(scores, labels) # differentiable approx ndcg loss.
# -0.63282484
jax.grad(loss_fn)(scores, labels) # computes gradients w.r.t. scores.
# [-0.01276882 0.00549765 0.00727116]
Installation
See https://github.com/google/jax#installation for instructions on installing JAX.
We suggest installing the latest stable version of Rax by running:
$ pip install rax
Examples
See the examples/ directory for complete examples on how to use Rax.
Citing Rax
If you use Rax, please consider citing our paper:
@inproceedings{jagerman2022rax,
title = {Rax: Composable Learning-to-Rank using JAX},
author = {Rolf Jagerman and Xuanhui Wang and Honglei Zhuang and Zhen Qin and
Michael Bendersky and Marc Najork},
year = {2022},
booktitle = {Proceedings of the 28th ACM SIGKDD International Conference on Knowledge Discovery \& Data Mining}
}
Metadata
Release files for rax 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rax-0.4.0.tar.gz | 60.4 kB | Without provenance | Details for rax-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rax-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for rax-0.4.0-py3-none-any.whl |
Total release size: 140.3 kB
Release files / rax-0.4.0.tar.gz
| Download URL | rax-0.4.0.tar.gz |
|---|---|
| Size | 60.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1d85164c8bbf712566798b6ac04a40a49a471a6dce235692c051ffa70a2589da
|
|
BLAKE2b-256 checksum How to use checksums |
644d38472764ff89fecad4f4eb81cabf1c29c2cab02a843baa979c7797a0db22
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.11.11
|
Release files / rax-0.4.0-py3-none-any.whl
| Download URL | rax-0.4.0-py3-none-any.whl |
|---|---|
| Size | 79.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9cab65339c1191a3f200d406f9d6e141fa1d6410f696e4cf6a8869d1487a565c
|
|
BLAKE2b-256 checksum How to use checksums |
b7d6b274635c0cfb1925fc828dfb6fe7f3acdfda04d41e0bda04389f44836dd4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.11.11
|
Security for rax 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.