Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 18
How to use kiel2/KielEmbed-Rerank with sentence-transformers:
from sentence_transformers import CrossEncoder
model = CrossEncoder("kiel2/KielEmbed-Rerank")
query = "Which planet is known as the Red Planet?"
passages = [
"Venus is often called Earth's twin because of its similar size and proximity.",
"Mars, known for its reddish appearance, is often referred to as the Red Planet.",
"Jupiter, the largest planet in our solar system, has a prominent red spot.",
"Saturn, famous for its rings, is sometimes mistaken for the Red Planet."
]
scores = model.predict([(query, passage) for passage in passages])
print(scores)A high-performance Cross-Encoder reranker fine-tuned from BAAI/bge-reranker-base.
This is a Cross Encoder model fine-tuned from BAAI/bge-reranker-base using the sentence-transformers library. It evaluates query-document text pairs jointly to compute precise relevance scores for semantic search and multi-stage retrieval pipelines.
CrossEncoder(
(0): Transformer({'transformer_task': 'sequence-classification', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'logits'}}, 'module_output_name': 'scores', 'architecture': 'BertForSequenceClassification'})
)
UsageDirect Usage (Sentence Transformers)First, install the Sentence Transformers library:Bashpip install -U sentence-transformers
Then load your deployed model and run inference:Pythonfrom sentence_transformers import CrossEncoder
# Load your custom reranker from the Hugging Face Hub
model = CrossEncoder("kiel/KielEmbed-Rerank")
# Get relevance scores for pairs of inputs (query, document)
pairs = [
[
'" The public is understandably losing patience with these unwanted phone calls , unwanted intrusions , " he said at a White House ceremony .',
'" While many good people work in the telemarketing industry , the public is understandably losing patience with these unwanted phone calls , unwanted intrusions , " Mr. Bush said .'
],
[
'Federal agent Bill Polychronopoulos said it was not known if the man , 30 , would be charged .',
'Federal Agent Bill Polychronopoulos said last night the man involved in the Melbourne incident had been unarmed .'
],
]
scores = model.predict(pairs)
print(scores)
# Alternatively, rank an array of candidate texts against a single query
ranks = model.rank(
'The public is losing patience with unwanted phone calls.',
[
'While many good people work in telemarketing, the public is losing patience with unwanted intrusions.',
'Federal agents reported an unarmed suspect in the downtown incident.',
'Corporate earnings reports will be released at the close of the fiscal year.'
]
)
print(ranks)
Training DetailsTraining DatasetKiel Reranker CorpusSize: 5,000 training samplesColumns: text1, text2, and labelDataset Statistics:Text 1: Min: 15 tokens | Mean: 33.25 tokens | Max: 58 tokensText 2: Min: 16 tokens | Mean: 33.05 tokens | Max: 52 tokensLabel Distribution: Class 0 (~34.62%), Class 1 (~65.38%)Loss Function: BinaryCrossEntropyLoss with parameters:JSON{
"activation_fn": "torch.nn.modules.linear.Identity",
"pos_weight": null
}
Training HyperparametersPer Device Train Batch Size: 4Gradient Accumulation Steps: 8 (Effective batch size = 32)Learning Rate: 2e-05Number of Epochs: 1Warmup Steps: 0.1Mixed Precision: FP16 EnabledOptimizer: adamw_torch_fusedTraining LogsEpochStepTraining Loss0.16251.75220.32500.41950.48750.35220.641000.36460.81250.36390.961500.3551Total Training Time: 5.2 minutesFramework VersionsPython: 3.13.15Sentence Transformers: 5.7.0Transformers: 5.16.1PyTorch: 2.11.0+cu128Accelerate: 1.14.0Datasets: 4.8.5Tokenizers: 0.23.1Additional ResourcesTraining and Finetuning Reranker Models with Sentence Transformers: Comprehensive guide for training custom Cross-Encoders.CitationBibTeXCode snippet@inproceedings{reimers-2019-sentence-bert,
title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
author = "Reimers, Nils and Gurevych, Iryna",
booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
month = "11",
year = "2019",
publisher = "Association for Computational Linguistics",
url = "[https://arxiv.org/abs/1908.10084](https://arxiv.org/abs/1908.10084)",
}
Base model
BAAI/bge-reranker-base