Views
No views yet
rerankers package. After installing the package using pip install rerankers[transformers], the following code can be used as a minimal working example:1from rerankers import Reranker
2import torch
3
4query = "O futebol é uma paixão nacional"
5docs = [
6 "O futebol é superestimado e não deveria receber tanta atenção.",
7 "O futebol é uma parte essencial da cultura brasileira e une as pessoas.",
8]
9
10ranker = Reranker(
11 "unicamp-dl/monoptt5-base",
12 inputs_template="Pergunta: {query} Documento: {text} Relevante:",
13 dtype=torch.float32 # or bfloat16 if supported by your GPU
14)
15
16results = ranker.rank(query, docs)
17
18print("Classification results:")
19for result in results:
20 print(result)
21
22# Loading T5Ranker model unicamp-dl/monoptt5-base
23# No device set
24# Using device cuda
25# Using dtype torch.float32
26# Loading model unicamp-dl/monoptt5-base, this might take a while...
27# Using device cuda.
28# Using dtype torch.float32.
29# T5 true token set to ▁Sim
30# T5 false token set to ▁Não
31# Returning normalised scores...
32# Inputs template set to Pergunta: {query} Documento: {text} Relevante:
33
34# Classification results:
35# document=Document(text='O futebol é uma parte essencial da cultura brasileira e une as pessoas.', doc_id=1, metadata={}) score=0.8186910152435303 rank=1
36# document=Document(text='O futebol é superestimado e não deveria receber tanta atenção.', doc_id=0, metadata={}) score=0.008028557524085045 rank=2rerankers GitHub repository.@misc{piau2024ptt5v2,
title={ptt5-v2: A Closer Look at Continued Pretraining of T5 Models for the Portuguese Language},
author={Marcos Piau and Roberto Lotufo and Rodrigo Nogueira},
year={2024},
eprint={2406.10806},
archivePrefix={arXiv},
primaryClass={id='cs.CL' full_name='Computation and Language' is_active=True alt_name='cmp-lg' in_archive='cs' is_general=False description='Covers natural language processing. Roughly includes material in ACM Subject Class I.2.7. Note that work on artificial languages (programming languages, logics, formal systems) that does not explicitly address natural-language issues broadly construed (natural-language processing, computational linguistics, speech, text retrieval, etc.) is not appropriate for this area.'}
}