Skip to main content

PyTorch Learning to Rank (LTR)

This is a library for Learning to Rank (LTR) with PyTorch. The goal of this library is to support the infrastructure necessary for performing LTR experiments in PyTorch.

This is a fork of the original pytorchltr. It add fix and updates to allow it to work with Python >=3.10.

Installation

In your virtualenv simply run:

pip install pytorchltr2

Note that this library requires Python 3.10 or higher.

Documentation

Original documentation is available here.

Example

See examples/01-basic-usage.py for a more complete example including evaluation

import torch
from pytorchltr.datasets import Example3
from pytorchltr.loss import PairwiseHingeLoss

# Load dataset
train = Example3(split="train")
collate_fn = train.collate_fn()

# Setup model, optimizer and loss
model = torch.nn.Linear(train[0].features.shape[1], 1)
optimizer = torch.optim.SGD(model.parameters(), lr=0.1)
loss = PairwiseHingeLoss()

# Train for 3 epochs
for epoch in range(3):
    loader = torch.utils.data.DataLoader(train, batch_size=2, collate_fn=collate_fn)
    for batch in loader:
        xs, ys, n = batch.features, batch.relevance, batch.n
        l = loss(model(xs), ys, n).mean()
        optimizer.zero_grad()
        l.backward()
        optimizer.step()

Dataset Disclaimer

This library provides utilities to automatically download and prepare several public LTR datasets. We cannot vouch for the quality, correctness or usefulness of these datasets. We do not host or distribute these datasets and it is ultimately your responsibility to determine whether you have permission to use each dataset under its respective license.

Citing

If you find this software useful for your research, please cite the publication for the original pytorchltr.

@inproceedings{jagerman2020accelerated,
    author = {Jagerman, Rolf and de Rijke, Maarten},
    title = {Accelerated Convergence for Counterfactual Learning to Rank},
    year = {2020},
    publisher = {Association for Computing Machinery},
    address = {New York, NY, USA},
    booktitle = {Proceedings of the 43rd International ACM SIGIR Conference on Research and Development in Information Retrieval},
    doi = {10.1145/3397271.3401069},
    series = {SIGIR’20}
}

Release files for pytorchltr2 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytorchltr2 0.2.3
File Size Uploaded
pytorchltr2-0.2.3.tar.gz 16.5 kB Details

Release files / pytorchltr2-0.2.3.tar.gz

Download URL pytorchltr2-0.2.3.tar.gz
Size 16.5 kB
Tags Source
SHA-256 checksum
How to use checksums
be6506a84438b402ebe5ed5e371768973d452a308d6cfc197ae6c5a581cf1599
BLAKE2b-256 checksum
How to use checksums
0114168c1fa4097a5349394c5a037f6f1412ee89331c2985df99026abaca064f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 21, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.3 This release

1 release file

0.2.2

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page