
Hugging Face Blog
· 1 min read
Training and Finetuning Reranker Models with Sentence Transformers
Sentence Transformers is a Python library for using and training embedding and reranker models for a wide range of applications, such as retrieval augmented generation, semantic search, semantic textual similarity, paraphrase mining, and more. In this blogpost, I'll show you how to use it to finetune a reranker model (also known as a cross-encoder) that beats all existing options on exactly your data. This method can also train extremely strong new reranker models from scratch.
Finetuning reranker models involves several components: datasets, loss functions, training arguments, evaluators, and the trainer class itself. I'll have a look at each of these components, accompanied by practical examples of how they can be used for finetuning strong reranker models.
Lastly, in the Evaluation section, I'll show you that my small finetuned tomaarsen/reranker-ModernBERT-base-gooaq-bce reranker model that I trained alongside this blogpost easily outperforms the 13 most commonly used public reranker models on my evaluation dataset. It even beats models that are 4x bigger.
Repeating the recipe with a bigger base model results in tomaarsen/reranker-ModernBERT-large-gooaq-bce, a reranker model that blows all existing general-purpose reranker models out of the water on my data.
If you're interested in finetuning embedding models instead, then consider reading through my prior Training and Finetuning Embedding Models with Sentence Transformers blogpost as well.
Table of Contents
- What are Reranker models?
- Why Finetune?
- Training Components
- Dataset
- Data on the Hugging Face Hub
- Local Data (CSV, JSON, Parquet, Arrow, SQL)
- Local Data that requires pre-processing
- Dataset Format
- Hard Negatives Mining
- Loss Function
- Training Arguments
- Evaluator
- CrossEncoderCorrelationEvaluator with STSb
- CrossEncoderRerankingEvaluator with GooAQ mined negatives
- Trainer
- Callbacks
- Multi-Dataset Training
- Training Tips
- Evaluation
- Additional Resources
- Training Examples
- Documentation
What are Reranker models?
Dataset
Click to see the outputs of this script.Click to see the Evaluation Script & datasets
Original source
This story was published by Hugging Face Blog. SyncAI.news shows a preview; the complete article is on the publisher's site.
Read the full story on huggingface.co


