CrossEncoder based on answerdotai/ModernBERT-base
This is a Cross Encoder model finetuned from answerdotai/ModernBERT-base on the ms_marco dataset using the sentence-transformers library. It computes scores for pairs of texts, which can be used for text reranking and semantic search.
Model Details
Model Description
- Model Type: Cross Encoder
- Base model: answerdotai/ModernBERT-base
- Maximum Sequence Length: 8192 tokens
- Number of Output Labels: 1 label
- Supported Modality: Text
- Training Dataset:
- ms_marco
Model Sources
- Documentation: Sentence Transformers Documentation
- Documentation: Cross Encoder Documentation
- Repository: Sentence Transformers on GitHub
- Hugging Face: Cross Encoders on Hugging Face
Full Model Architecture
CrossEncoder(
(0): Transformer({'transformer_task': 'sequence-classification', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'logits'}}, 'module_output_name': 'scores', 'architecture': 'ModernBertForSequenceClassification'})
)
Usage
Direct Usage (Sentence Transformers)
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-msmarco-v1.1-ModernBERT-base-bce")
# Get scores for pairs of inputs
pairs = [
['define ransom', 'Full Definition of RANSOM. transitive verb. 1. : to deliver especially from sin or its penalty. 2. : to free from captivity or punishment by paying a price. — ran·som·er noun. See ransom defined for English-language learners. rescue, deliver, redeem, ransom, reclaim, save mean to set free from confinement or danger. rescue implies freeing from imminent danger by prompt or vigorous action.'],
['what does atlas copco do', 'Atlas Copco is a Swedish industrial company that was founded in 1873. It manufactures industrial tools and equipment. The Atlas Copco Group is a global industrial group of companies headquartered in Nacka, Sweden. In 2014, global revenues totalled SEK 94 billion, and the company employed more than 44,000 people. 1 2009 – Atlas Copco is the first company to get a compressor certified for 100 percent energy recovery by the TUEV tüv (Institute German Technical Monitoring). association'],
['two situations in which dna fingerprinting is useful', 'Paternity and Maternity This is also a well known use for DNA fingerprinting. This is the test used to find out who is the father of a baby or children. Every individual has a VNTR pattern which is inherited from their parents.'],
['sustainable business strategy definition', 'Jupiterimages/Brand X Pictures/Getty Images. A business strategy defines how a company intends to operate in its markets. As environmental awareness has grown over the recent decades, businesses of all forms are being forced to incorporate more sustainable approaches to carrying out their activities.'],
['how do you determine salinity', 'RSS Feeds. When we measure the salinity of water, we look at how much dissolved salt is in the water, or the concentration of salt in the water. Concentration is the amount (by weight) of salt in water and can be expressed in parts per million (ppm). Here are the classes of water:'],
]
scores = model.predict(pairs)
print(scores)
# [0.2587 0.4132 0.1375 0.1348 0.0626]
# Or rank different texts based on similarity to a single text
ranks = model.rank(
'define ransom',
[
'Full Definition of RANSOM. transitive verb. 1. : to deliver especially from sin or its penalty. 2. : to free from captivity or punishment by paying a price. — ran·som·er noun. See ransom defined for English-language learners. rescue, deliver, redeem, ransom, reclaim, save mean to set free from confinement or danger. rescue implies freeing from imminent danger by prompt or vigorous action.',
'Atlas Copco is a Swedish industrial company that was founded in 1873. It manufactures industrial tools and equipment. The Atlas Copco Group is a global industrial group of companies headquartered in Nacka, Sweden. In 2014, global revenues totalled SEK 94 billion, and the company employed more than 44,000 people. 1 2009 – Atlas Copco is the first company to get a compressor certified for 100 percent energy recovery by the TUEV tüv (Institute German Technical Monitoring). association',
'Paternity and Maternity This is also a well known use for DNA fingerprinting. This is the test used to find out who is the father of a baby or children. Every individual has a VNTR pattern which is inherited from their parents.',
'Jupiterimages/Brand X Pictures/Getty Images. A business strategy defines how a company intends to operate in its markets. As environmental awareness has grown over the recent decades, businesses of all forms are being forced to incorporate more sustainable approaches to carrying out their activities.',
'RSS Feeds. When we measure the salinity of water, we look at how much dissolved salt is in the water, or the concentration of salt in the water. Concentration is the amount (by weight) of salt in water and can be expressed in parts per million (ppm). Here are the classes of water:',
]
)
# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]
Evaluation
Metrics
Cross Encoder Reranking
- Datasets:
NanoMSMARCO_R100,NanoNFCorpus_R100andNanoNQ_R100 - Evaluated with CrossEncoderRerankingEvaluator with these parameters:
{ "at_k": 10, "always_rerank_positives": true }
| Metric | NanoMSMARCO_R100 | NanoNFCorpus_R100 | NanoNQ_R100 |
|---|---|---|---|
| map | 0.4889 (-0.0007) | 0.3263 (+0.0653) | 0.5004 (+0.0808) |
| mrr@10 | 0.4798 (+0.0023) | 0.5073 (+0.0075) | 0.5073 (+0.0806) |
| ndcg@10 | 0.5577 (+0.0172) | 0.3438 (+0.0187) | 0.5555 (+0.0548) |
Cross Encoder Nano BEIR
- Dataset:
NanoBEIR_R100_mean - Evaluated with CrossEncoderNanoBEIREvaluator 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.4385 (+0.0485) |
| mrr@10 | 0.4981 (+0.0301) |
| ndcg@10 | 0.4856 (+0.0303) |
Training Details
Training Dataset
ms_marco
- Dataset: ms_marco
- Size: 666,193 training samples
- Columns: query, passage, and label
- Approximate statistics based on the first 100 samples:
query passage label type string string int modality text text details min: 5 tokensmean: 9.21 tokensmax: 19 tokens min: 39 tokensmean: 94.57 tokensmax: 163 tokens 0: ~85.58%1: ~14.42% - Samples:
query passage label how did the vietnam war contributed to the war powers resolution The War Powers Act is a reaction to the Vietnam War. Congress passed it in 1973 when the United States withdrew from combat operations in Vietnam after more than a decade. The War Powers Act attempted to correct what Congress and the American public saw as excessive war-making powers in the hands of the president. Congress was also attempting to correct a mistake of its own. 0 what is Fra Angelico contribution renaissance art Fra Angelico Facts. Fra Angelico was an early Italian Renaissance artist and a monk, considered to be one of the most talented fresco painters of his time. He was born Guido di Pietro in approximately 1395 at Rupecanina in Mugello, but nothing is known of his parents. 1 what is mederma made of Mederma is made from a patented formula which combines unique ingredients such as Cepalin, centella asiatica leaf extract and hyaluronic acid. Cepalin is the main active ingredient of the product and is an onion extract that has been known to soothe the skin from inflammation and irritation. 1 While this will not do much in terms of the reduction of stretch marks, softer skin will be less likely to crack or show the wear of agedness. 2 Unfortunately, such a positive trait is not what most consumers would be primarily looking for when purchasing Mederma. 1 - Loss: BinaryCrossEntropyLoss with these parameters:
{ "activation_fn": "torch.nn.modules.linear.Identity", "pos_weight": null }
Evaluation Dataset
ms_marco
- Dataset: ms_marco
- Size: 10,000 evaluation samples
- Columns: query, passage, and label
- Approximate statistics based on the first 100 samples:
query passage label type string string int modality text text details min: 4 tokensmean: 8.66 tokensmax: 16 tokens min: 37 tokensmean: 93.02 tokensmax: 170 tokens 0: ~87.50%1: ~12.50% - Samples:
query passage label define ransom Full Definition of RANSOM. transitive verb. 1. : to deliver especially from sin or its penalty. 2. : to free from captivity or punishment by paying a price. — ran·som·er noun. See ransom defined for English-language learners. rescue, deliver, redeem, ransom, reclaim, save mean to set free from confinement or danger. rescue implies freeing from imminent danger by prompt or vigorous action. 0 what does atlas copco do Atlas Copco is a Swedish industrial company that was founded in 1873. It manufactures industrial tools and equipment. The Atlas Copco Group is a global industrial group of companies headquartered in Nacka, Sweden. In 2014, global revenues totalled SEK 94 billion, and the company employed more than 44,000 people. 1 2009 – Atlas Copco is the first company to get a compressor certified for 100 percent energy recovery by the TUEV tüv (Institute German Technical Monitoring). association 1 two situations in which dna fingerprinting is useful Paternity and Maternity This is also a well known use for DNA fingerprinting. This is the test used to find out who is the father of a baby or children. Every individual has a VNTR pattern which is inherited from their parents. 0 - Loss: BinaryCrossEntropyLoss with these parameters:
{ "activation_fn": "torch.nn.modules.linear.Identity", "pos_weight": null }
Training Hyperparameters
Non-Default Hyperparameters
per_device_train_batch_size: 32per_device_eval_batch_size: 32learning_rate: 2e-05num_train_epochs: 1warmup_steps: 0.1seed: 12fp16: Trueload_best_model_at_end: Trueddp_find_unused_parameters: False
All Hyperparameters
do_predict: Falseprediction_loss_only: Trueper_device_train_batch_size: 32per_device_eval_batch_size: 32gradient_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: Nonewarmup_ratio: Nonewarmup_steps: 0.1log_level: passivelog_level_replica: warninglog_on_each_node: Truelogging_nan_inf_filter: Trueenable_jit_checkpoint: Falsesave_on_each_node: Falsesave_only_model: Falserestore_callback_states_from_checkpoint: Falseuse_cpu: Falseseed: 12data_seed: Nonebf16: Falsefp16: Truebf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonelocal_rank: -1ddp_backend: Nonedebug: []dataloader_drop_last: Truedataloader_num_workers: 0dataloader_prefetch_factor: Nonedisable_tqdm: Falseremove_unused_columns: Truelabel_names: Noneload_best_model_at_end: Trueignore_data_skip: Falsefsdp: []fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}accelerator_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: Nonegroup_by_length: Falselength_column_name: lengthproject: huggingfacetrackio_space_id: trackioddp_find_unused_parameters: Falseddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falsedataloader_pin_memory: Truedataloader_persistent_workers: Falseskip_memory_metrics: Truepush_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_for_metrics: []eval_do_concat_batches: Trueauto_find_batch_size: Falsefull_determinism: Falseddp_timeout: 1800torch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Noneinclude_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: Trueuse_cache: Falseprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}
Training Logs
| Epoch | Step | Training Loss | Validation Loss | NanoMSMARCO_R100_ndcg@10 | NanoNFCorpus_R100_ndcg@10 | NanoNQ_R100_ndcg@10 | NanoBEIR_R100_mean_ndcg@10 |
|---|---|---|---|---|---|---|---|
| -1 | -1 | - | - | 0.0186 (-0.5218) | 0.2940 (-0.0310) | 0.0428 (-0.4579) | 0.1185 (-0.3369) |
| 0.0001 | 1 | 0.7090 | - | - | - | - | - |
| 0.0961 | 1000 | 0.3989 | - | - | - | - | - |
| 0.1000 | 1041 | - | 0.3921 | 0.1024 (-0.4380) | 0.2928 (-0.0322) | 0.1595 (-0.3411) | 0.1849 (-0.2705) |
| 0.1921 | 2000 | 0.3664 | - | - | - | - | - |
| 0.2000 | 2082 | - | 0.3561 | 0.4520 (-0.0884) | 0.2777 (-0.0474) | 0.4784 (-0.0223) | 0.4027 (-0.0527) |
| 0.2882 | 3000 | 0.3434 | - | - | - | - | - |
| 0.3000 | 3123 | - | 0.3514 | 0.5371 (-0.0033) | 0.3322 (+0.0072) | 0.5049 (+0.0042) | 0.4581 (+0.0027) |
| 0.3843 | 4000 | 0.3414 | - | - | - | - | - |
| 0.4000 | 4164 | - | 0.3446 | 0.5558 (+0.0154) | 0.3071 (-0.0180) | 0.5070 (+0.0063) | 0.4566 (+0.0012) |
| 0.4804 | 5000 | 0.3380 | - | - | - | - | - |
| 0.5 | 5205 | - | 0.3402 | 0.5577 (+0.0172) | 0.3438 (+0.0187) | 0.5555 (+0.0548) | 0.4856 (+0.0303) |
| 0.5764 | 6000 | 0.3345 | - | - | - | - | - |
| 0.6001 | 6246 | - | 0.3391 | 0.5382 (-0.0022) | 0.3244 (-0.0006) | 0.5858 (+0.0851) | 0.4828 (+0.0274) |
| 0.6725 | 7000 | 0.3337 | - | - | - | - | - |
| 0.7001 | 7287 | - | 0.3360 | 0.5464 (+0.0060) | 0.3210 (-0.0040) | 0.5506 (+0.0500) | 0.4727 (+0.0173) |
| 0.7686 | 8000 | 0.3309 | - | - | - | - | - |
| 0.8001 | 8328 | - | 0.3373 | 0.5479 (+0.0075) | 0.3173 (-0.0077) | 0.5507 (+0.0501) | 0.4720 (+0.0166) |
| 0.8646 | 9000 | 0.3265 | - | - | - | - | - |
| 0.9001 | 9369 | - | 0.3313 | 0.5658 (+0.0254) | 0.3079 (-0.0172) | 0.5695 (+0.0688) | 0.4811 (+0.0257) |
| 0.9607 | 10000 | 0.3256 | - | - | - | - | - |
| -1 | -1 | - | - | 0.5577 (+0.0172) | 0.3438 (+0.0187) | 0.5555 (+0.0548) | 0.4856 (+0.0303) |
- The bold row denotes the saved checkpoint.
Training Time
- Training: 1.6 hours
- Evaluation: 20.4 minutes
- Total: 1.9 hours
Framework Versions
- Python: 3.12.13
- Sentence Transformers: 6.0.1
- Transformers: 5.0.0
- PyTorch: 2.10.0+cu128
- Accelerate: 1.13.0
- Datasets: 5.0.0
- Tokenizers: 0.22.2
Additional Resources
- Training and Finetuning Reranker Models with Sentence Transformers: the end-to-end guide for training or finetuning Cross Encoder (reranker) models.
- Multimodal Embedding & Reranker Models with Sentence Transformers: use text, image, audio, and video reranker models through the same API.
- Training and Finetuning Multimodal Embedding & Reranker Models with Sentence Transformers: training multimodal Cross Encoders.
Citation
BibTeX
Sentence Transformers
@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",
}