Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 13
How to use chingackgook/reranker-ModernBERT-base-gooaq-bce with sentence-transformers:
from sentence_transformers import CrossEncoder
model = CrossEncoder("chingackgook/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.
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("chingackgook/reranker-ModernBERT-base-gooaq-bce")
# Get scores for pairs of texts
pairs = [
['how many days can i drive my car without mot?', "If your car fails its MOT you can only continue to drive it if the previous year's MOT is still valid - which might occur if you submitted the car for its test two weeks early. You can still drive it away from the testing centre or garage if no 'dangerous' problems were identified during the MOT."],
['how many days can i drive my car without mot?', '["Open File Explorer\', go to \'This PC\'. Check the status of the network drive. [00:11]", \'An error occurred while reconnecting or mapping Drive letter Z: to Network folder. [00:36]\', \'You can do either connect the drive (Map network drive) or Disconnect Network drive. [01:01]\', \'Disconnect Network Drive by this way. [01:28]\']'],
['what xbox 360 games are compatible with xbox 1?', "['0 day Attack on Earth.', '3D Ultra Minigolf.', 'A Kingdom for Keflings.', 'A World of Keflings.', 'Ace Combat 6: Fires of Liberation.', 'Aegis Wing.', 'Age of Booty.', 'Alan Wake (Tested by Digital Foundry)']"],
['what xbox 360 games are compatible with xbox 1?', "['1) Computer and Information Systems Managers.', '2) Computer and Information Research Scientists.', '3) Computer Network Architects.', '4) Software Development Engineer.', '5) Software Developers.', '6) Information Security Analysts.', '8) Computer Systems Analysts.']"],
['what does it mean when a guy asks for a picture of you?', 'He wants to confirm if he is talking to Priya or Angel Priya (I.e., if he is really talking to a girl or just a guy with fake profile) They are talking to you and want to see how you look. I found it normal but would say, be careful about whom do you share your picture with as they might misuse it. I hate this one.'],
]
scores = model.predict(pairs)
print(scores.shape)
# (5,)
# Or rank different texts based on similarity to a single text
ranks = model.rank(
'how many days can i drive my car without mot?',
[
"If your car fails its MOT you can only continue to drive it if the previous year's MOT is still valid - which might occur if you submitted the car for its test two weeks early. You can still drive it away from the testing centre or garage if no 'dangerous' problems were identified during the MOT.",
'["Open File Explorer\', go to \'This PC\'. Check the status of the network drive. [00:11]", \'An error occurred while reconnecting or mapping Drive letter Z: to Network folder. [00:36]\', \'You can do either connect the drive (Map network drive) or Disconnect Network drive. [01:01]\', \'Disconnect Network Drive by this way. [01:28]\']',
"['0 day Attack on Earth.', '3D Ultra Minigolf.', 'A Kingdom for Keflings.', 'A World of Keflings.', 'Ace Combat 6: Fires of Liberation.', 'Aegis Wing.', 'Age of Booty.', 'Alan Wake (Tested by Digital Foundry)']",
"['1) Computer and Information Systems Managers.', '2) Computer and Information Research Scientists.', '3) Computer Network Architects.', '4) Software Development Engineer.', '5) Software Developers.', '6) Information Security Analysts.', '8) Computer Systems Analysts.']",
'He wants to confirm if he is talking to Priya or Angel Priya (I.e., if he is really talking to a girl or just a guy with fake profile) They are talking to you and want to see how you look. I found it normal but would say, be careful about whom do you share your picture with as they might misuse it. I hate this one.',
]
)
# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]
gooaq-devCrossEncoderRerankingEvaluator with these parameters:{
"at_k": 10,
"always_rerank_positives": false
}
| Metric | Value |
|---|---|
| map | 0.2500 (-0.7500) |
| mrr@10 | 0.2500 (-0.7500) |
| ndcg@10 | 0.4307 (-0.5693) |
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.0358 (-0.4538) | 0.2903 (+0.0293) | 0.0379 (-0.3817) |
| mrr@10 | 0.0109 (-0.4666) | 0.5069 (+0.0070) | 0.0140 (-0.4127) |
| ndcg@10 | 0.0260 (-0.5145) | 0.2900 (-0.0350) | 0.0174 (-0.4833) |
NanoBEIR_R100_meanCrossEncoderNanoBEIREvaluator with these parameters:{
"dataset_names": [
"msmarco",
"nfcorpus",
"nq"
],
"rerank_k": 100,
"at_k": 10,
"always_rerank_positives": true
}
| Metric | Value |
|---|---|
| map | 0.1213 (-0.2688) |
| mrr@10 | 0.1772 (-0.2908) |
| ndcg@10 | 0.1111 (-0.3443) |
question, answer, and label| question | answer | label | |
|---|---|---|---|
| type | string | string | int |
| details |
|
|
|
| question | answer | label |
|---|---|---|
how many days can i drive my car without mot? |
If your car fails its MOT you can only continue to drive it if the previous year's MOT is still valid - which might occur if you submitted the car for its test two weeks early. You can still drive it away from the testing centre or garage if no 'dangerous' problems were identified during the MOT. |
1 |
how many days can i drive my car without mot? |
["Open File Explorer', go to 'This PC'. Check the status of the network drive. [00:11]", 'An error occurred while reconnecting or mapping Drive letter Z: to Network folder. [00:36]', 'You can do either connect the drive (Map network drive) or Disconnect Network drive. [01:01]', 'Disconnect Network Drive by this way. [01:28]'] |
0 |
what xbox 360 games are compatible with xbox 1? |
['0 day Attack on Earth.', '3D Ultra Minigolf.', 'A Kingdom for Keflings.', 'A World of Keflings.', 'Ace Combat 6: Fires of Liberation.', 'Aegis Wing.', 'Age of Booty.', 'Alan Wake (Tested by Digital Foundry)'] |
1 |
BinaryCrossEntropyLoss with these parameters:{
"activation_fn": "torch.nn.modules.linear.Identity",
"pos_weight": 1
}
eval_strategy: stepsper_device_train_batch_size: 16per_device_eval_batch_size: 16learning_rate: 2e-05num_train_epochs: 1warmup_ratio: 0.1seed: 12bf16: Truedataloader_num_workers: 4load_best_model_at_end: Trueoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 16per_device_eval_batch_size: 16per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 1eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 2e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 1max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: {}warmup_ratio: 0.1warmup_steps: 0log_level: passivelog_level_replica: warninglog_on_each_node: Truelogging_nan_inf_filter: Truesave_safetensors: Truesave_on_each_node: Falsesave_only_model: Falserestore_callback_states_from_checkpoint: Falseno_cuda: Falseuse_cpu: Falseuse_mps_device: Falseseed: 12data_seed: Nonejit_mode_eval: Falsebf16: Truefp16: Falsefp16_opt_level: O1half_precision_backend: autobf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonelocal_rank: 0ddp_backend: Nonetpu_num_cores: Nonetpu_metrics_debug: Falsedebug: []dataloader_drop_last: Falsedataloader_num_workers: 4dataloader_prefetch_factor: Nonepast_index: -1disable_tqdm: Falseremove_unused_columns: Truelabel_names: Noneload_best_model_at_end: Trueignore_data_skip: Falsefsdp: []fsdp_min_num_params: 0fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}fsdp_transformer_layer_cls_to_wrap: Noneaccelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}parallelism_config: Nonedeepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torch_fusedoptim_args: Noneadafactor: Falsegroup_by_length: Falselength_column_name: lengthproject: huggingfacetrackio_space_id: trackioddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falsedataloader_pin_memory: Truedataloader_persistent_workers: Falseskip_memory_metrics: Trueuse_legacy_prediction_loop: Falsepush_to_hub: Falseresume_from_checkpoint: Nonehub_model_id: Nonehub_strategy: every_savehub_private_repo: Nonehub_always_push: Falsehub_revision: Nonegradient_checkpointing: Falsegradient_checkpointing_kwargs: Noneinclude_inputs_for_metrics: Falseinclude_for_metrics: []eval_do_concat_batches: Truefp16_backend: autopush_to_hub_model_id: Nonepush_to_hub_organization: Nonemp_parameters: auto_find_batch_size: Falsefull_determinism: Falsetorchdynamo: Noneray_scope: lastddp_timeout: 1800torch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Noneinclude_tokens_per_second: Falseinclude_num_input_tokens_seen: noneftune_noise_alpha: Noneoptim_target_modules: Nonebatch_eval_metrics: Falseeval_on_start: Falseuse_liger_kernel: Falseliger_kernel_config: Noneeval_use_gather_object: Falseaverage_tokens_across_devices: Trueprompts: 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.4307 (-0.5693) | 0.0220 (-0.5184) | 0.2802 (-0.0448) | 0.0200 (-0.4806) | 0.1074 (-0.3479) |
| 0.25 | 1 | 0.7171 | - | - | - | - | - |
| -1 | -1 | - | 0.4307 (-0.5693) | 0.0260 (-0.5145) | 0.2900 (-0.0350) | 0.0174 (-0.4833) | 0.1111 (-0.3443) |
@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