Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 17
How to use kwondw/reranker-ModernBERT-base-gooaq-bce with sentence-transformers:
from sentence_transformers import CrossEncoder
model = CrossEncoder("kwondw/reranker-ModernBERT-base-gooaq-bce")
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)This is a Cross Encoder model finetuned from answerdotai/ModernBERT-base using the sentence-transformers library. It computes scores for pairs of texts, which can be used for text reranking and semantic search.
CrossEncoder(
(0): Transformer({'transformer_task': 'sequence-classification', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'logits'}}, 'module_output_name': 'scores', 'architecture': 'ModernBertForSequenceClassification'})
)
First install the Sentence Transformers library:
pip install -U sentence-transformers
Then you can load this model and run inference.
from sentence_transformers import CrossEncoder
# Download from the 🤗 Hub
model = CrossEncoder("kwondw/reranker-ModernBERT-base-gooaq-bce")
# Get scores for pairs of inputs
pairs = [
['what to spend my nectar points on?', "There are lots of different places and ways you can spend your points. You can spend straight from your card by swiping it at Sainsbury's, Vue Cinemas and Argos or you can spend them online at nectar.com on great things like holidays, hotels and days out."],
['what to spend my nectar points on?', "If you have already registered for Online Services, just log in to see your points balance. For detailed points transactions, go to Membership Rewards page and click on 'Your points Account' and then 'My Points' at the top of the page."],
['what to spend my nectar points on?', 'The SDIP authorized insurance rate increase are as follows: 1 point=25%, 2 points=45%, 3 points=65%, 4 points=90%, 5 points=120%, 6 points=150%, 7 points=180%, 8 points=220%, 9 points=260%, 10 points=300%, 11 points=350%, and 12 insurance points equals a 400% increase in your insurance premiums, ouch!'],
['what to spend my nectar points on?', 'To redeem your Amex Blue Sky points, log in to your account via the Amex travel portal. At the checkout, there will be an option to pay with points. Points are worth 1 cent each toward flights and 0.7 cents each toward other travel costs.'],
['what to spend my nectar points on?', 'Yes, TD rewards points are worth $0.005 each, and must be redeemed in increments of 10,000, at a value of $50 per 10,000 points.'],
]
scores = model.predict(pairs)
print(scores)
# [9.7463e-01 2.7169e-02 1.4214e-03 5.0407e-03 4.4422e-04]
# Or rank different texts based on similarity to a single text
ranks = model.rank(
'what to spend my nectar points on?',
[
"There are lots of different places and ways you can spend your points. You can spend straight from your card by swiping it at Sainsbury's, Vue Cinemas and Argos or you can spend them online at nectar.com on great things like holidays, hotels and days out.",
"If you have already registered for Online Services, just log in to see your points balance. For detailed points transactions, go to Membership Rewards page and click on 'Your points Account' and then 'My Points' at the top of the page.",
'The SDIP authorized insurance rate increase are as follows: 1 point=25%, 2 points=45%, 3 points=65%, 4 points=90%, 5 points=120%, 6 points=150%, 7 points=180%, 8 points=220%, 9 points=260%, 10 points=300%, 11 points=350%, and 12 insurance points equals a 400% increase in your insurance premiums, ouch!',
'To redeem your Amex Blue Sky points, log in to your account via the Amex travel portal. At the checkout, there will be an option to pay with points. Points are worth 1 cent each toward flights and 0.7 cents each toward other travel costs.',
'Yes, TD rewards points are worth $0.005 each, and must be redeemed in increments of 10,000, at a value of $50 per 10,000 points.',
]
)
# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]
gooaq-devCrossEncoderRerankingEvaluator with these parameters:{
"at_k": 10,
"always_rerank_positives": false
}
| Metric | Value |
|---|---|
| map | 0.7842 (+0.1739) |
| mrr@10 | 0.7827 (+0.1773) |
| ndcg@10 | 0.8182 (+0.1499) |
NanoMSMARCO_R100, NanoNFCorpus_R100 and NanoNQ_R100CrossEncoderRerankingEvaluator with these parameters:{
"at_k": 10,
"always_rerank_positives": true
}
| Metric | NanoMSMARCO_R100 | NanoNFCorpus_R100 | NanoNQ_R100 |
|---|---|---|---|
| map | 0.4839 (-0.0056) | 0.3422 (+0.0812) | 0.6052 (+0.1856) |
| mrr@10 | 0.4753 (-0.0022) | 0.5542 (+0.0544) | 0.6189 (+0.1922) |
| ndcg@10 | 0.5681 (+0.0277) | 0.3908 (+0.0658) | 0.6657 (+0.1651) |
NanoBEIR_R100_meanCrossEncoderNanoBEIREvaluator with these parameters:{
"dataset_names": [
"msmarco",
"nfcorpus",
"nq"
],
"dataset_id": "sentence-transformers/NanoBEIR-en",
"rerank_k": 100,
"at_k": 10,
"always_rerank_positives": true
}
| Metric | Value |
|---|---|
| map | 0.4771 (+0.0870) |
| mrr@10 | 0.5495 (+0.0814) |
| ndcg@10 | 0.5415 (+0.0862) |
question, answer, and label| question | answer | label | |
|---|---|---|---|
| type | string | string | int |
| modality | text | text | |
| details |
|
|
|
| question | answer | label |
|---|---|---|
what to spend my nectar points on? |
There are lots of different places and ways you can spend your points. You can spend straight from your card by swiping it at Sainsbury's, Vue Cinemas and Argos or you can spend them online at nectar.com on great things like holidays, hotels and days out. |
1 |
what to spend my nectar points on? |
If you have already registered for Online Services, just log in to see your points balance. For detailed points transactions, go to Membership Rewards page and click on 'Your points Account' and then 'My Points' at the top of the page. |
0 |
what to spend my nectar points on? |
The SDIP authorized insurance rate increase are as follows: 1 point=25%, 2 points=45%, 3 points=65%, 4 points=90%, 5 points=120%, 6 points=150%, 7 points=180%, 8 points=220%, 9 points=260%, 10 points=300%, 11 points=350%, and 12 insurance points equals a 400% increase in your insurance premiums, ouch! |
0 |
BinaryCrossEntropyLoss with these parameters:{
"activation_fn": "torch.nn.modules.linear.Identity",
"pos_weight": 5
}
per_device_train_batch_size: 64num_train_epochs: 1learning_rate: 2e-05warmup_steps: 0.1fp16: Trueper_device_eval_batch_size: 64load_best_model_at_end: Trueseed: 12dataloader_num_workers: 2per_device_train_batch_size: 64num_train_epochs: 1max_steps: -1learning_rate: 2e-05lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 0.1optim: adamw_torch_fusedoptim_args: Noneweight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08optim_target_modules: Nonegradient_accumulation_steps: 1average_tokens_across_devices: Truemax_grad_norm: 1.0label_smoothing_factor: 0.0bf16: Falsefp16: Truebf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonegradient_checkpointing: Falsegradient_checkpointing_kwargs: Nonetorch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Noneuse_liger_kernel: Falseliger_kernel_config: Noneuse_cache: Falseneftune_noise_alpha: Nonetorch_empty_cache_steps: Noneauto_find_batch_size: Falselog_on_each_node: Truelogging_nan_inf_filter: Trueinclude_num_input_tokens_seen: nolog_level: passivelog_level_replica: warningdisable_tqdm: Falseproject: huggingfacetrackio_space_id: Nonetrackio_bucket_id: Nonetrackio_static_space_id: Noneper_device_eval_batch_size: 64prediction_loss_only: Trueeval_on_start: Falseeval_do_concat_batches: Trueeval_use_gather_object: Falseeval_accumulation_steps: Noneinclude_for_metrics: []batch_eval_metrics: Falsesave_only_model: Falsesave_on_each_node: Falseenable_jit_checkpoint: Falsepush_to_hub: Falsehub_private_repo: Nonehub_model_id: Nonehub_strategy: every_savehub_always_push: Falsehub_revision: Noneload_best_model_at_end: Trueignore_data_skip: Falserestore_callback_states_from_checkpoint: Falsefull_determinism: Falseseed: 12data_seed: Noneuse_cpu: Falseaccelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}parallelism_config: Nonedataloader_drop_last: Falsedataloader_num_workers: 2dataloader_pin_memory: Truedataloader_persistent_workers: Falsedataloader_prefetch_factor: Noneremove_unused_columns: Truelabel_names: Nonetrain_sampling_strategy: randomlength_column_name: lengthddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falseddp_static_graph: Noneddp_backend: Noneddp_timeout: 1800fsdp: Nonefsdp_config: Nonedeepspeed: Nonedebug: []skip_memory_metrics: Truedo_predict: Falseresume_from_checkpoint: Nonewarmup_ratio: Nonelocal_rank: -1prompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | gooaq-dev_ndcg@10 | NanoMSMARCO_R100_ndcg@10 | NanoNFCorpus_R100_ndcg@10 | NanoNQ_R100_ndcg@10 | NanoBEIR_R100_mean_ndcg@10 |
|---|---|---|---|---|---|---|---|
| -1 | -1 | - | 0.1149 (-0.5534) | 0.0212 (-0.5192) | 0.2526 (-0.0724) | 0.0288 (-0.4719) | 0.1009 (-0.3545) |
| 0.0002 | 1 | 1.3195 | - | - | - | - | - |
| 0.0438 | 200 | 1.1767 | - | - | - | - | - |
| 0.0876 | 400 | 1.0007 | - | - | - | - | - |
| 0.1095 | 500 | - | 0.7463 (+0.0779) | 0.4619 (-0.0785) | 0.3117 (-0.0133) | 0.5694 (+0.0688) | 0.4477 (-0.0077) |
| 0.1314 | 600 | 0.6751 | - | - | - | - | - |
| 0.1752 | 800 | 0.6153 | - | - | - | - | - |
| 0.2190 | 1000 | 0.5813 | 0.7963 (+0.1279) | 0.5554 (+0.0150) | 0.3518 (+0.0267) | 0.6018 (+0.1012) | 0.5030 (+0.0476) |
| 0.2628 | 1200 | 0.5345 | - | - | - | - | - |
| 0.3066 | 1400 | 0.5544 | - | - | - | - | - |
| 0.3285 | 1500 | - | 0.8035 (+0.1351) | 0.5196 (-0.0208) | 0.3772 (+0.0522) | 0.6118 (+0.1111) | 0.5029 (+0.0475) |
| 0.3504 | 1600 | 0.5324 | - | - | - | - | - |
| 0.3942 | 1800 | 0.5199 | - | - | - | - | - |
| 0.4380 | 2000 | 0.5015 | 0.8045 (+0.1362) | 0.5731 (+0.0326) | 0.3638 (+0.0387) | 0.6564 (+0.1558) | 0.5311 (+0.0757) |
| 0.4818 | 2200 | 0.4899 | - | - | - | - | - |
| 0.5256 | 2400 | 0.4703 | - | - | - | - | - |
| 0.5475 | 2500 | - | 0.8030 (+0.1346) | 0.5821 (+0.0417) | 0.3820 (+0.0569) | 0.6695 (+0.1688) | 0.5445 (+0.0892) |
| 0.5694 | 2600 | 0.4863 | - | - | - | - | - |
| 0.6132 | 2800 | 0.4823 | - | - | - | - | - |
| 0.6570 | 3000 | 0.4656 | 0.8066 (+0.1382) | 0.5458 (+0.0054) | 0.3882 (+0.0632) | 0.6386 (+0.1379) | 0.5242 (+0.0688) |
| 0.7008 | 3200 | 0.4689 | - | - | - | - | - |
| 0.7446 | 3400 | 0.4595 | - | - | - | - | - |
| 0.7665 | 3500 | - | 0.8146 (+0.1462) | 0.5861 (+0.0456) | 0.3904 (+0.0654) | 0.6578 (+0.1572) | 0.5448 (+0.0894) |
| 0.7884 | 3600 | 0.4484 | - | - | - | - | - |
| 0.8322 | 3800 | 0.4597 | - | - | - | - | - |
| 0.876 | 4000 | 0.4482 | 0.8182 (+0.1499) | 0.5681 (+0.0277) | 0.3908 (+0.0658) | 0.6657 (+0.1651) | 0.5415 (+0.0862) |
| 0.9198 | 4200 | 0.4488 | - | - | - | - | - |
| 0.9636 | 4400 | 0.4548 | - | - | - | - | - |
| 0.9855 | 4500 | - | 0.8168 (+0.1484) | 0.5612 (+0.0208) | 0.4006 (+0.0755) | 0.6864 (+0.1858) | 0.5494 (+0.0940) |
| 1.0 | 4566 | - | 0.8166 (+0.1482) | 0.5640 (+0.0236) | 0.4006 (+0.0755) | 0.6838 (+0.1832) | 0.5495 (+0.0941) |
| -1 | -1 | - | 0.8182 (+0.1499) | 0.5681 (+0.0277) | 0.3908 (+0.0658) | 0.6657 (+0.1651) | 0.5415 (+0.0862) |
@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",
}
Base model
answerdotai/ModernBERT-base