CrossEncoder based on microsoft/MiniLM-L12-H384-uncased
This is a Cross Encoder model finetuned from microsoft/MiniLM-L12-H384-uncased on the msmarco 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: microsoft/MiniLM-L12-H384-uncased
- Maximum Sequence Length: 512 tokens
- Number of Output Labels: 1 label
- Supported Modality: Text
- Training Dataset:
- Language: en
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("kwondw/reranker-MiniLM-L12-H384-uncased-msmarco-margin-mse")
# Get scores for pairs of inputs
pairs = [
['cost for laminate flooring per square foot', 'Average Price Range. Cheap laminate flooring starts at less than $1 per square foot and can cost as much as $5 per square foot. The average laminate flooring costs from $2.40-$4 per square foot.The price is determined, as it is with most products, by the quality of the material.A major part of that quality is the thickness of the wear layer.: There will be some variation in prices regionally and the final amount will depend on the size and complexity of the project, that said the average cost to install laminate flooring is $1.40 to $2.20 per square foot.'],
['what county is south daytona, fl in?', 'South Daytona, Florida. South Daytona is a city in Volusia County, Florida, United States. The population was 12,252 at the 2010 census.'],
['when was donkey kong released', 'Donkey Kong (ã\x83\x89ã\x83³ã\x82\xadã\x83¼ã\x82³ã\x83³ã\x82°, DonkÄ« Kongu, [dõÅ\x8b.kiË\x90 kõÅ\x8b.É¡uÍ\x8d]) is a series of video games featuring the adventures of a gorilla character called Donkey Kong, conceived by Shigeru Miyamoto in 1981. The franchise mainly comprises two different game genres, plus spin-off titles of various genres.'],
['causes of compartment syndrome of tibia', 'Both acute exertional compartment syndrome and anterior tibial stress fractures are rare causes of leg pain in young athletes. As demonstrated by this case, their combined presentation can pose a diagnostic dilemma.'],
['how many years of college to be a dental hygienist', "Education and Qualifications. To become a dental hygienist, you'll need either a 2- or 4-year degree in dental hygiene. Most programs are two years long and lead to an associate's degree. They are offered through community colleges and technical colleges."],
]
scores = model.predict(pairs)
print(scores)
# [1. 1. 0.9998 0.991 1. ]
# Or rank different texts based on similarity to a single text
ranks = model.rank(
'cost for laminate flooring per square foot',
[
'Average Price Range. Cheap laminate flooring starts at less than $1 per square foot and can cost as much as $5 per square foot. The average laminate flooring costs from $2.40-$4 per square foot.The price is determined, as it is with most products, by the quality of the material.A major part of that quality is the thickness of the wear layer.: There will be some variation in prices regionally and the final amount will depend on the size and complexity of the project, that said the average cost to install laminate flooring is $1.40 to $2.20 per square foot.',
'South Daytona, Florida. South Daytona is a city in Volusia County, Florida, United States. The population was 12,252 at the 2010 census.',
'Donkey Kong (ã\x83\x89ã\x83³ã\x82\xadã\x83¼ã\x82³ã\x83³ã\x82°, DonkÄ« Kongu, [dõÅ\x8b.kiË\x90 kõÅ\x8b.É¡uÍ\x8d]) is a series of video games featuring the adventures of a gorilla character called Donkey Kong, conceived by Shigeru Miyamoto in 1981. The franchise mainly comprises two different game genres, plus spin-off titles of various genres.',
'Both acute exertional compartment syndrome and anterior tibial stress fractures are rare causes of leg pain in young athletes. As demonstrated by this case, their combined presentation can pose a diagnostic dilemma.',
"Education and Qualifications. To become a dental hygienist, you'll need either a 2- or 4-year degree in dental hygiene. Most programs are two years long and lead to an associate's degree. They are offered through community colleges and technical colleges.",
]
)
# [{'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.6055 (+0.1160) | 0.3550 (+0.0940) | 0.6762 (+0.2566) |
| mrr@10 | 0.5978 (+0.1203) | 0.6030 (+0.1032) | 0.6895 (+0.2628) |
| ndcg@10 | 0.6684 (+0.1279) | 0.4159 (+0.0909) | 0.7250 (+0.2243) |
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.5456 (+0.1555) |
| mrr@10 | 0.6301 (+0.1621) |
| ndcg@10 | 0.6031 (+0.1477) |
Training Details
Training Dataset
msmarco
- Dataset: msmarco at 2a16a97
- Size: 500,000 training samples
- Columns: score, query, positive, and negative
- Approximate statistics based on the first 100 samples:
score query positive negative type float string string string modality text text text details min: 1.61mean: 13.55max: 21.63 min: 4 tokensmean: 8.98 tokensmax: 13 tokens min: 24 tokensmean: 81.15 tokensmax: 237 tokens min: 23 tokensmean: 78.24 tokensmax: 171 tokens - Samples:
score query positive negative 6.981858521699905 symptoms of shingles on back The earliest symptoms of shingles, which include headache, fever, and malaise, are nonspecific, and may result in an incorrect diagnosis. These symptoms are commonly followed by sensations of burning pain, itching, hyperesthesia (oversensitivity), or paresthesia (pins and needles: tingling, pricking, or numbness). Shingles is caused by the varicella-zoster virus, the virus that also causes chickenpox. In a person who has been exposed to chickenpox -- or its vaccine -- the virus never really goes away.It can lie dormant in the body's nerves.f you have shingles symptoms, get treatment now and you may avoid permanent nerve pain. Shingles, a viral infection of the nerve roots, affects 1 million people in the U.S each year. Most people recover from their bout, but for as many as 50% of those over age 60 who have not been treated, the pain doesn't go away. 18.709746996561687 uuww airport Vnukovo International Airport. Vnukovo International Airport (Russian: междÑнаÑоднÑй аÑÑопоÑÑ Ð²Ð½Ñково; IPA: [ËvnukÉvÉ]) (IATA: VKO, ICAO: UUWW), is a dual-runway international airport located 28 kilometres (17 mi) southwest of the centre of Moscow, Russia. Javascript is currently disabled in your browser. Arrivals& Departures Timetable Budgetflightsout ofBrussels Airport To & fromBrussels Airport Parking at the airport Worldwidebudget flights &city trips Informationon air trafficto & fromBrussels Airport Shops,bars &restaurants Baggage&TravelInfo.avascript is currently disabled in your browser. Arrivals& Departures Timetable Budgetflightsout ofBrussels Airport To & fromBrussels Airport Parking at the airport Worldwidebudget flights &city trips Informationon air trafficto & fromBrussels Airport Shops,bars &restaurants Baggage&TravelInfo. 9.210955460866293 what is a hepatitis b surface antibody test This test looks for hepatitis B surface antigens in your blood. The test is used to find out whether you have a recent or long-standing infection from the hepatitis B virus (HBV). HBV has proteins called antigens on its surface that cause your immune system to make antibodies. Blood tests for hepatitis C include the following: 1 Screening test for antibodies to the hepatitis C virus. A screening blood test will show whether you have developed antibodies to the hepatitis C virus. A positive antibody test means you were exposed to the hepatitis C virus at some point. - Loss: MarginMSELoss with these parameters:
{ "activation_fn": "torch.nn.modules.linear.Identity" }
Evaluation Dataset
msmarco
- Dataset: msmarco at 2a16a97
- Size: 10,000 evaluation samples
- Columns: score, query, positive, and negative
- Approximate statistics based on the first 100 samples:
score query positive negative type float string string string modality text text text details min: -1.07mean: 13.75max: 21.54 min: 5 tokensmean: 9.12 tokensmax: 18 tokens min: 26 tokensmean: 78.65 tokensmax: 166 tokens min: 25 tokensmean: 73.67 tokensmax: 176 tokens - Samples:
score query positive negative 17.243099629878998 cost for laminate flooring per square foot Average Price Range. Cheap laminate flooring starts at less than $1 per square foot and can cost as much as $5 per square foot. The average laminate flooring costs from $2.40-$4 per square foot.The price is determined, as it is with most products, by the quality of the material.A major part of that quality is the thickness of the wear layer.: There will be some variation in prices regionally and the final amount will depend on the size and complexity of the project, that said the average cost to install laminate flooring is $1.40 to $2.20 per square foot. We created the most comprehensive flooring installation calculator on the internet. Weâve broken it down to the following: Step 1 â Laminate Type. Step 2 â Location, Square Footage, Materials, and Labor. Step 3 â Old Flooring and New Flooring. Step 4 â Get your calculation. Put it all together and we give you the most accurate flooring calculation available. 15.025473694006603 what county is south daytona, fl in? South Daytona, Florida. South Daytona is a city in Volusia County, Florida, United States. The population was 12,252 at the 2010 census. Driving distance from Ocala, FL to Daytona Beach, FL. The total driving distance from Ocala, FL to Daytona Beach, FL is 78 miles or 126 kilometers. Your trip begins in Ocala, Florida. It ends in Daytona Beach, Florida. 19.3864418665568 when was donkey kong released Donkey Kong (ãã³ãã¼ã³ã³ã°, DonkÄ« Kongu, [dõÅ.kiË kõÅ.É¡uÍ]) is a series of video games featuring the adventures of a gorilla character called Donkey Kong, conceived by Shigeru Miyamoto in 1981. The franchise mainly comprises two different game genres, plus spin-off titles of various genres. ⢠Overfeeding a donkey or feeding it the wrong diet can be fatal. ⢠Overfeeding can result a crippling disease called laminitis of the hooves. ⢠Obesity is also a consequence of overfeeding. ⢠Once obese it is difficult to get a donkey back to normal weight because they require so few calories to sustain themselves. - Loss: MarginMSELoss with these parameters:
{ "activation_fn": "torch.nn.modules.linear.Identity" }
Training Hyperparameters
Non-Default Hyperparameters
per_device_train_batch_size: 16num_train_epochs: 1learning_rate: 8e-06warmup_steps: 0.1fp16: Trueper_device_eval_batch_size: 16load_best_model_at_end: Trueseed: 12dataloader_num_workers: 2dataloader_persistent_workers: True
All Hyperparameters
per_device_train_batch_size: 16num_train_epochs: 1max_steps: -1learning_rate: 8e-06lr_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: 16prediction_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: Truedataloader_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: {}
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.0571 (-0.4833) | 0.2602 (-0.0648) | 0.0366 (-0.4641) | 0.1180 (-0.3374) |
| 0.0000 | 1 | 10.5990 | - | - | - | - | - |
| 0.032 | 1000 | 14.1334 | - | - | - | - | - |
| 0.064 | 2000 | 10.7750 | - | - | - | - | - |
| 0.096 | 3000 | 8.2282 | - | - | - | - | - |
| 0.128 | 4000 | 7.5857 | - | - | - | - | - |
| 0.16 | 5000 | 7.6998 | 7.2268 | 0.6103 (+0.0699) | 0.4113 (+0.0863) | 0.7143 (+0.2136) | 0.5786 (+0.1233) |
| 0.192 | 6000 | 7.5407 | - | - | - | - | - |
| 0.224 | 7000 | 6.6533 | - | - | - | - | - |
| 0.256 | 8000 | 6.3815 | - | - | - | - | - |
| 0.288 | 9000 | 6.0625 | - | - | - | - | - |
| 0.32 | 10000 | 5.7674 | 5.1869 | 0.6309 (+0.0905) | 0.4054 (+0.0804) | 0.7280 (+0.2274) | 0.5881 (+0.1327) |
| 0.352 | 11000 | 5.6975 | - | - | - | - | - |
| 0.384 | 12000 | 5.6018 | - | - | - | - | - |
| 0.416 | 13000 | 5.4275 | - | - | - | - | - |
| 0.448 | 14000 | 5.3066 | - | - | - | - | - |
| 0.48 | 15000 | 5.1923 | 4.7864 | 0.6604 (+0.1200) | 0.4208 (+0.0958) | 0.7186 (+0.2179) | 0.5999 (+0.1446) |
| 0.512 | 16000 | 5.0914 | - | - | - | - | - |
| 0.544 | 17000 | 5.0233 | - | - | - | - | - |
| 0.576 | 18000 | 4.8260 | - | - | - | - | - |
| 0.608 | 19000 | 4.7843 | - | - | - | - | - |
| 0.64 | 20000 | 4.6837 | 3.9526 | 0.6684 (+0.1279) | 0.4159 (+0.0909) | 0.7250 (+0.2243) | 0.6031 (+0.1477) |
| 0.672 | 21000 | 4.7339 | - | - | - | - | - |
| 0.704 | 22000 | 4.5955 | - | - | - | - | - |
| 0.736 | 23000 | 4.5098 | - | - | - | - | - |
| 0.768 | 24000 | 4.5284 | - | - | - | - | - |
| 0.8 | 25000 | 4.4547 | 3.8360 | 0.6501 (+0.1097) | 0.4178 (+0.0927) | 0.7125 (+0.2119) | 0.5935 (+0.1381) |
| 0.832 | 26000 | 4.4747 | - | - | - | - | - |
| 0.864 | 27000 | 4.4769 | - | - | - | - | - |
| 0.896 | 28000 | 4.3455 | - | - | - | - | - |
| 0.928 | 29000 | 4.5034 | - | - | - | - | - |
| 0.96 | 30000 | 4.2892 | 4.0615 | 0.6478 (+0.1073) | 0.4092 (+0.0842) | 0.7201 (+0.2195) | 0.5924 (+0.1370) |
| 0.992 | 31000 | 4.2995 | - | - | - | - | - |
| 1.0 | 31250 | - | 3.8921 | 0.6574 (+0.1170) | 0.4094 (+0.0843) | 0.7192 (+0.2185) | 0.5953 (+0.1400) |
| -1 | -1 | - | - | 0.6684 (+0.1279) | 0.4159 (+0.0909) | 0.7250 (+0.2243) | 0.6031 (+0.1477) |
- The bold row denotes the saved checkpoint.
Training Time
- Training: 1.4 hours
Framework Versions
- Python: 3.12.13
- Sentence Transformers: 5.6.0
- Transformers: 5.13.1
- PyTorch: 2.11.0+cu128
- Accelerate: 1.14.0
- Datasets: 4.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",
}
MarginMSELoss
@misc{hofstätter2021improving,
title={Improving Efficient Neural Ranking Models with Cross-Architecture Knowledge Distillation},
author={Sebastian Hofstätter and Sophia Althammer and Michael Schröder and Mete Sertkan and Allan Hanbury},
year={2021},
eprint={2010.02666},
archivePrefix={arXiv},
primaryClass={cs.IR}
}