PyTerrier components for T5 ranking
Project description
PyTerrier_t5
This is the PyTerrier plugin for the Mono and Duo T5 ranking approaches [Nogueira21].
Note that this package only supports scoring from a pretrained models (like this one).
Installation
This repostory can be installed using Pip.
pip install --upgrade git+https://github.com/terrierteam/pyterrier_t5.git
Building T5 pipelines
You can use MonoT5 just like any other text-based re-ranker. By default, it uses a MonoT5 model previously trained on MS MARCO passage ranking training queries.
import pyterrier as pt
from pyterrier_t5 import MonoT5ReRanker, DuoT5ReRanker
monoT5 = MonoT5ReRanker() # loads castorini/monot5-base-msmarco by default
duoT5 = DuoT5ReRanker() # loads castorini/duot5-base-msmarco by default
dataset = pt.get_dataset("irds:vaswani")
bm25 = pt.BatchRetrieve(pt.get_dataset("vaswani").get_index(), wmodel="BM25")
mono_pipeline = bm25 >> pt.text.get_text(dataset, "text") >> monoT5
duo_pipeline = mono_pipeline % 5 >> duoT5 # apply a rank cutoff of 5 from monoT5 since duoT5 is too costly to run over the full result list
Note that both approaches require the document text to be included in the dataframe (see pt.text.get_text).
MonoT5ReRanker and DuoT5ReRanker have the following options:
model(default:'castorini/monot5-base-msmarco'for mono,'castorini/duot5-base-msmarco'for duo). HGF model name. Defaults to a version trained on MS MARCO passage ranking.tok_model(default:'t5-base'). HGF tokenizer name.batch_size(default:4). How many documents to process at the same time.text_field(default:text). The dataframe attribute in which the document text is stored.verbose(default:True). Show progress bar.
Examples
Checkout out the notebooks, even on Colab:
Implementation Details
We use a PyTerrier transformer to score documents using a T5 model.
Sequences longer than the model's maximum of 512 tokens are silently truncated. Consider splitting long texts into passages and aggregating the results (examples).
References
- Ronak Pradeep, Rodrigo Nogueira, and Jimmy Lin. The Expando-Mono-Duo Design Pattern for Text Ranking withPretrained Sequence-to-Sequence Models. https://arxiv.org/pdf/2101.05667.pdf
- Craig Macdonald, Nicola Tonellotto. Declarative Experimentation inInformation Retrieval using PyTerrier. Craig Macdonald and Nicola Tonellotto. In Proceedings of ICTIR 2020. https://arxiv.org/abs/2007.14271
Credits
- Sean MacAvaney, University of Glasgow
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyterrier_t5-0.2.0.tar.gz.
File metadata
- Download URL: pyterrier_t5-0.2.0.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad1b116c9f04c1b36a90479d5b235b546c849cd9a2944b3548e62de7c2da051d
|
|
| MD5 |
7f36e2f407f4f9e6026b0dd9add92b8c
|
|
| BLAKE2b-256 |
193f0fa11bb347621d2043aab04feec054f2b8d46923c2158bf64b943f75e780
|
File details
Details for the file pyterrier_t5-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pyterrier_t5-0.2.0-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53cae0b51b085c8a41ee5747043f8bc1c9f16081ee4f889c66d99d482ed68491
|
|
| MD5 |
8e2f9638297b9b54e7f3e91a043d3e7a
|
|
| BLAKE2b-256 |
2d36b0140d13b3c8ffe3c8a4f37a452def5771ddeec7aaa204a41aacadcdb405
|