Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Hugging Face 24 min read How-to mediumAdept

Training and Finetuning Reranker Models with Sentence Transformers

Sentence Transformers can finetune reranker (cross-encoder) models on domain data. The guide covers each training component: dataset loading and column-format rules, hard-negative mining with mine_hard_negatives, loss functions such as BinaryCrossEntropyLoss and CachedMultipleNegativesRankingLoss, training arguments, evaluators and the CrossEncoderTrainer. A small ModernBERT-base reranker finetuned on GooAQ with mined hard negatives outperforms the 13 most commonly used public rerankers on that evaluation data, including models 4x larger. The large variant beats all general-purpose rerankers tested there, which makes the case for domain finetuning in retrieve-and-rerank pipelines.

Related posts

  • Introducing the Ettin Reranker Family

    Hugging Face mediumAdept

    Six Sentence Transformers CrossEncoder rerankers (17M to 1B parameters) built on the Ettin ModernBERT encoders are released with their data and full training recipe. They were distilled with pointwise MSE on mxbai-rerank-large-v2 scores. On MTEB(eng, v2) Retrieval, top-100 reranked across six embedders, the 1B model matches its 1.54B teacher (0.6114 vs 0.6115 NDCG@10). The 17M beats the legacy ms-marco-MiniLM-L12-v2 by +0.051, and the 150M edges out Qwen3-Reranker-0.6B. The architecture uses a plain AutoModel with CLS pooling, which ablations found beat mean pooling, plus a small dense head, enabling unpadded Flash Attention 2 for 1.7x-8.3x speedups over fp32+SDPA with 8K context.

  • Training and Finetuning Embedding Models with Sentence Transformers

    Hugging Face mediumAdept

    Sentence Transformers v3 trains and finetunes embedding models through a SentenceTransformerTrainer that combines Hugging Face datasets, a loss function, optional training arguments and evaluators. Finetuning matters because each task needs its own notion of similarity. Dataset column order must match the chosen loss's inputs, with an optional "label" or "score" column, and extraneous columns must be removed. A worked example finetunes MPNet on AllNLI triplets with MultipleNegativesRankingLoss and a no-duplicates batch sampler, and evaluates with TripletEvaluator and EmbeddingSimilarityEvaluator on STSb.

  • Training and Finetuning Multi-Vector Embedding Models with Sentence Transformers

    Hugging Face mediumAdept

    Sentence Transformers v6.0 adds a MultiVectorEncoder model type for ColBERT-style late-interaction retrieval, with a full training stack covering models, datasets, losses, training arguments, evaluators and the trainer. A guide walks through finetuning on MIRIAD medical question-passage pairs. The resulting mLateOn-medical model, trained in 14.5 hours on one RTX 3090, beats every general-purpose dense, sparse, lexical and multi-vector retriever the author tested. Key findings: '-unsupervised' checkpoints taken before supervised finetuning adapt to a new domain better than finished ones, which barely improved or regressed. Lifting the 180–512 token document caps matters too, since truncation cost up to 0.24 NDCG@10 on long passages. A punctuation skiplist shrinks the index by 9.6% with a slight quality gain, and CachedMultiVectorMultipleNegativesRankingLoss allows large effective batch sizes.

  • Train and Fine-Tune Sentence Transformers Models

    Hugging Face mediumAdept

    Sentence Transformers models map text to fixed-size embeddings by running a pre-trained Transformer and pooling its token embeddings, and training them depends on matching the dataset format to the right loss. Four common formats map to specific losses: labeled pairs (ContrastiveLoss, SoftmaxLoss, CosineSimilarityLoss), unlabeled positive pairs (MultipleNegativesRankingLoss), class-labeled sentences (batch triplet losses), and unlabeled triplets (TripletLoss). A worked example builds a distilroberta-base model, trains it on QQP triplets with TripletLoss via the legacy `fit` API, and pushes it to the Hugging Face Hub. The guide is marked outdated: since v3.0, SentenceTransformerTrainer replaces this API.

  • Training and Finetuning Multimodal Embedding & Reranker Models with Sentence Transformers

    Hugging Face mediumAdept

    Finetuning Qwen3-VL-Embedding-2B with Sentence Transformers for Visual Document Retrieval raised NDCG@10 from 0.888 to 0.947. On the author's evaluation data, that beats every tested VDR model, including models up to 4x larger. The walkthrough covers each training component: loading VLM or Router-composed multimodal models, formatting image/text triplet datasets, CachedMultipleNegativesRankingLoss with mini_batch_size=1 so a batch size of 64 fits in GPU memory via gradient caching, MatryoshkaLoss for truncatable embeddings (near-peak quality at 512 dims), training arguments, and an InformationRetrievalEvaluator built with hard negatives. It also extends the same approach to training multimodal rerankers.

The quest for software engineering knowledge.

Look:
Layout: