CrossEncoder based on cross-encoder/ms-marco-MiniLM-L6-v2
This is a Cross Encoder model finetuned from cross-encoder/ms-marco-MiniLM-L6-v2 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: cross-encoder/ms-marco-MiniLM-L6-v2
- Maximum Sequence Length: 512 tokens
- Number of Output Labels: 1 label
- Supported Modality: Text
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': 'BertForSequenceClassification'})
)
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("cross_encoder_model_id")
# Get scores for pairs of inputs
pairs = [
['skill: manage health care staff', 'skill: manage healthcare staff'],
['skill: manage health care staff', 'skill: manage staff'],
['skill: manage health care staff', 'skill: manage physiotherapy staff'],
['skill: manage health care staff', 'skill: work with nursing staff'],
['skill: manage health care staff', 'skill: manage chiropractic staff'],
]
scores = model.predict(pairs)
print(scores)
# [ 8.8912 5.1062 0.8043 -2.9487 -4.7649]
# Or rank different texts based on similarity to a single text
ranks = model.rank(
'skill: manage health care staff',
[
'skill: manage healthcare staff',
'skill: manage staff',
'skill: manage physiotherapy staff',
'skill: work with nursing staff',
'skill: manage chiropractic staff',
]
)
# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]
Training Details
Training Dataset
Unnamed Dataset
- Size: 60,646 training samples
- Columns: sentence_A, sentence_B, and label
- Approximate statistics based on the first 100 samples:
sentence_A sentence_B label type string string float modality text text details min: 7 tokensmean: 8.14 tokensmax: 11 tokens min: 6 tokensmean: 7.94 tokensmax: 15 tokens min: 0.0mean: 0.22max: 1.0 - Samples:
sentence_A sentence_B label skill: manage security systems skill: manage technical security systems 1.0 skill: manage security systems skill: Physical access management software 0.0 skill: manage security systems skill: manage theft prevention 0.0 - Loss: BinaryCrossEntropyLoss with these parameters:
{ "activation_fn": "torch.nn.modules.linear.Identity", "pos_weight": null }
Evaluation Dataset
Unnamed Dataset
- Size: 7,845 evaluation samples
- Columns: sentence_A, sentence_B, and label
- Approximate statistics based on the first 100 samples:
sentence_A sentence_B label type string string float modality text text details min: 6 tokensmean: 9.23 tokensmax: 14 tokens min: 6 tokensmean: 8.06 tokensmax: 16 tokens min: 0.0mean: 0.21max: 1.0 - Samples:
sentence_A sentence_B label skill: manage health care staff skill: manage healthcare staff 1.0 skill: manage health care staff skill: manage staff 0.0 skill: manage health care staff skill: manage physiotherapy staff 0.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: 32num_train_epochs: 2learning_rate: 2e-05warmup_steps: 0.1per_device_eval_batch_size: 64load_best_model_at_end: True
All Hyperparameters
per_device_train_batch_size: 32num_train_epochs: 2max_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: Falsebf16_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: 42data_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: 0dataloader_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: []fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}deepspeed: 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: {}
Training Logs
| Epoch | Step | Training Loss | Validation Loss |
|---|---|---|---|
| 0.0105 | 20 | 0.4434 | - |
| 0.0211 | 40 | 0.3695 | - |
| 0.0316 | 60 | 0.4175 | - |
| 0.0422 | 80 | 0.3651 | - |
| 0.0527 | 100 | 0.3550 | - |
| 0.0633 | 120 | 0.2564 | - |
| 0.0738 | 140 | 0.3148 | - |
| 0.0844 | 160 | 0.3065 | - |
| 0.0949 | 180 | 0.2168 | - |
| 0.1055 | 200 | 0.2779 | - |
| 0.1160 | 220 | 0.2502 | - |
| 0.1266 | 240 | 0.2487 | - |
| 0.1371 | 260 | 0.2225 | - |
| 0.1477 | 280 | 0.2132 | - |
| 0.1582 | 300 | 0.2196 | - |
| 0.1688 | 320 | 0.2416 | - |
| 0.1793 | 340 | 0.2146 | - |
| 0.1899 | 360 | 0.2103 | - |
| 0.2004 | 380 | 0.2316 | - |
| 0.2110 | 400 | 0.1414 | - |
| 0.2215 | 420 | 0.1354 | - |
| 0.2321 | 440 | 0.2388 | - |
| 0.2426 | 460 | 0.1878 | - |
| 0.2532 | 480 | 0.2923 | - |
| 0.2637 | 500 | 0.1698 | - |
| 0.2743 | 520 | 0.2065 | - |
| 0.2848 | 540 | 0.2076 | - |
| 0.2954 | 560 | 0.1686 | - |
| 0.3059 | 580 | 0.1466 | - |
| 0.3165 | 600 | 0.1967 | - |
| 0.3270 | 620 | 0.1739 | - |
| 0.3376 | 640 | 0.1586 | - |
| 0.3481 | 660 | 0.1643 | - |
| 0.3586 | 680 | 0.1649 | - |
| 0.3692 | 700 | 0.1957 | - |
| 0.3797 | 720 | 0.1126 | - |
| 0.3903 | 740 | 0.1942 | - |
| 0.4008 | 760 | 0.1857 | - |
| 0.4114 | 780 | 0.1599 | - |
| 0.4219 | 800 | 0.1404 | - |
| 0.4325 | 820 | 0.1432 | - |
| 0.4430 | 840 | 0.1714 | - |
| 0.4536 | 860 | 0.1774 | - |
| 0.4641 | 880 | 0.1646 | - |
| 0.4747 | 900 | 0.1716 | - |
| 0.4852 | 920 | 0.1744 | - |
| 0.4958 | 940 | 0.1547 | - |
| 0.5063 | 960 | 0.1190 | - |
| 0.5169 | 980 | 0.1737 | - |
| 0.5274 | 1000 | 0.1498 | - |
| 0.5380 | 1020 | 0.1351 | - |
| 0.5485 | 1040 | 0.1340 | - |
| 0.5591 | 1060 | 0.1334 | - |
| 0.5696 | 1080 | 0.1688 | - |
| 0.5802 | 1100 | 0.1553 | - |
| 0.5907 | 1120 | 0.1284 | - |
| 0.6013 | 1140 | 0.1384 | - |
| 0.6118 | 1160 | 0.1417 | - |
| 0.6224 | 1180 | 0.1331 | - |
| 0.6329 | 1200 | 0.1357 | - |
| 0.6435 | 1220 | 0.1476 | - |
| 0.6540 | 1240 | 0.1187 | - |
| 0.6646 | 1260 | 0.1369 | - |
| 0.6751 | 1280 | 0.1726 | - |
| 0.6857 | 1300 | 0.1220 | - |
| 0.6962 | 1320 | 0.1233 | - |
| 0.7068 | 1340 | 0.1379 | - |
| 0.7173 | 1360 | 0.1255 | - |
| 0.7278 | 1380 | 0.1263 | - |
| 0.7384 | 1400 | 0.1243 | - |
| 0.7489 | 1420 | 0.1194 | - |
| 0.7595 | 1440 | 0.1317 | - |
| 0.7700 | 1460 | 0.1322 | - |
| 0.7806 | 1480 | 0.1139 | - |
| 0.7911 | 1500 | 0.1016 | - |
| 0.8017 | 1520 | 0.1082 | - |
| 0.8122 | 1540 | 0.1113 | - |
| 0.8228 | 1560 | 0.1484 | - |
| 0.8333 | 1580 | 0.1252 | - |
| 0.8439 | 1600 | 0.1252 | - |
| 0.8544 | 1620 | 0.0860 | - |
| 0.8650 | 1640 | 0.1465 | - |
| 0.8755 | 1660 | 0.1169 | - |
| 0.8861 | 1680 | 0.1665 | - |
| 0.8966 | 1700 | 0.0927 | - |
| 0.9072 | 1720 | 0.1403 | - |
| 0.9177 | 1740 | 0.1346 | - |
| 0.9283 | 1760 | 0.1278 | - |
| 0.9388 | 1780 | 0.1512 | - |
| 0.9494 | 1800 | 0.1228 | - |
| 0.9599 | 1820 | 0.0820 | - |
| 0.9705 | 1840 | 0.1385 | - |
| 0.9810 | 1860 | 0.1249 | - |
| 0.9916 | 1880 | 0.0771 | - |
| 1.0 | 1896 | - | 0.2885 |
| 1.0021 | 1900 | 0.1246 | - |
| 1.0127 | 1920 | 0.0834 | - |
| 1.0232 | 1940 | 0.0928 | - |
| 1.0338 | 1960 | 0.1047 | - |
| 1.0443 | 1980 | 0.1013 | - |
| 1.0549 | 2000 | 0.1367 | - |
| 1.0654 | 2020 | 0.1177 | - |
| 1.0759 | 2040 | 0.1104 | - |
| 1.0865 | 2060 | 0.1156 | - |
| 1.0970 | 2080 | 0.1107 | - |
| 1.1076 | 2100 | 0.1239 | - |
| 1.1181 | 2120 | 0.0928 | - |
| 1.1287 | 2140 | 0.1123 | - |
| 1.1392 | 2160 | 0.0981 | - |
| 1.1498 | 2180 | 0.0918 | - |
| 1.1603 | 2200 | 0.0929 | - |
| 1.1709 | 2220 | 0.0964 | - |
| 1.1814 | 2240 | 0.0999 | - |
| 1.1920 | 2260 | 0.0948 | - |
| 1.2025 | 2280 | 0.0977 | - |
| 1.2131 | 2300 | 0.0937 | - |
| 1.2236 | 2320 | 0.0905 | - |
| 1.2342 | 2340 | 0.1046 | - |
| 1.2447 | 2360 | 0.0903 | - |
| 1.2553 | 2380 | 0.1002 | - |
| 1.2658 | 2400 | 0.0634 | - |
| 1.2764 | 2420 | 0.1276 | - |
| 1.2869 | 2440 | 0.0983 | - |
| 1.2975 | 2460 | 0.1514 | - |
| 1.3080 | 2480 | 0.1091 | - |
| 1.3186 | 2500 | 0.0984 | - |
| 1.3291 | 2520 | 0.1446 | - |
| 1.3397 | 2540 | 0.0891 | - |
| 1.3502 | 2560 | 0.0997 | - |
| 1.3608 | 2580 | 0.0897 | - |
| 1.3713 | 2600 | 0.1158 | - |
| 1.3819 | 2620 | 0.1042 | - |
| 1.3924 | 2640 | 0.0834 | - |
| 1.4030 | 2660 | 0.1244 | - |
| 1.4135 | 2680 | 0.0717 | - |
| 1.4241 | 2700 | 0.0789 | - |
| 1.4346 | 2720 | 0.0775 | - |
| 1.4451 | 2740 | 0.1169 | - |
| 1.4557 | 2760 | 0.0759 | - |
| 1.4662 | 2780 | 0.1031 | - |
| 1.4768 | 2800 | 0.0942 | - |
| 1.4873 | 2820 | 0.1100 | - |
| 1.4979 | 2840 | 0.0814 | - |
| 1.5084 | 2860 | 0.1017 | - |
| 1.5190 | 2880 | 0.0832 | - |
| 1.5295 | 2900 | 0.0681 | - |
| 1.5401 | 2920 | 0.1088 | - |
| 1.5506 | 2940 | 0.1194 | - |
| 1.5612 | 2960 | 0.1051 | - |
| 1.5717 | 2980 | 0.0660 | - |
| 1.5823 | 3000 | 0.0876 | - |
| 1.5928 | 3020 | 0.0641 | - |
| 1.6034 | 3040 | 0.1041 | - |
| 1.6139 | 3060 | 0.0909 | - |
| 1.6245 | 3080 | 0.1020 | - |
| 1.6350 | 3100 | 0.0623 | - |
| 1.6456 | 3120 | 0.0977 | - |
| 1.6561 | 3140 | 0.0823 | - |
| 1.6667 | 3160 | 0.0918 | - |
| 1.6772 | 3180 | 0.0737 | - |
| 1.6878 | 3200 | 0.1105 | - |
| 1.6983 | 3220 | 0.1102 | - |
| 1.7089 | 3240 | 0.0758 | - |
| 1.7194 | 3260 | 0.0988 | - |
| 1.7300 | 3280 | 0.1055 | - |
| 1.7405 | 3300 | 0.1039 | - |
| 1.7511 | 3320 | 0.0713 | - |
| 1.7616 | 3340 | 0.0994 | - |
| 1.7722 | 3360 | 0.1194 | - |
| 1.7827 | 3380 | 0.0682 | - |
| 1.7932 | 3400 | 0.1194 | - |
| 1.8038 | 3420 | 0.0759 | - |
| 1.8143 | 3440 | 0.1356 | - |
| 1.8249 | 3460 | 0.0955 | - |
| 1.8354 | 3480 | 0.0868 | - |
| 1.8460 | 3500 | 0.1171 | - |
| 1.8565 | 3520 | 0.1222 | - |
| 1.8671 | 3540 | 0.1119 | - |
| 1.8776 | 3560 | 0.1066 | - |
| 1.8882 | 3580 | 0.1188 | - |
| 1.8987 | 3600 | 0.0545 | - |
| 1.9093 | 3620 | 0.1170 | - |
| 1.9198 | 3640 | 0.0706 | - |
| 1.9304 | 3660 | 0.1086 | - |
| 1.9409 | 3680 | 0.0872 | - |
| 1.9515 | 3700 | 0.1013 | - |
| 1.9620 | 3720 | 0.0906 | - |
| 1.9726 | 3740 | 0.1357 | - |
| 1.9831 | 3760 | 0.0644 | - |
| 1.9937 | 3780 | 0.0636 | - |
| 2.0 | 3792 | - | 0.3205 |
- The bold row denotes the saved checkpoint.
Training Time
- Training: 4.4 minutes
- Evaluation: 4.6 seconds
- Total: 4.5 minutes
Framework Versions
- Python: 3.13.13
- Sentence Transformers: 5.5.0
- Transformers: 5.8.1
- PyTorch: 2.12.0
- Accelerate: 1.14.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",
}