Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper
•
1908.10084
•
Published
•
9
This is a Cross Encoder model finetuned from microsoft/MiniLM-L12-H384-uncased using the sentence-transformers library. It computes scores for pairs of texts, which can be used for semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.
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("sentence_transformers_model_id")
# Get scores for pairs of texts
pairs = [
['how much should i pay for breast implants', 'Implant Fees. The cost of buying the implants themselves will influence the overall costs of the procedure. Silicone implants cost between $1,800 and $2,500 though this may go up to slightly over $3,000.Saline implants will cost anywhere between $1,200 and $1,600.The cost of implants varies due to size and manufacturer though there is usually not much of a difference.Anesthesia Fees. There are various options for your anesthesia and this will have a direct impact on the fee you will be charged.otal Costs of Brest Implants. With all the above factors taken into consideration, the total cost of breast implants generally are somewhere in the range of $5,000 and $15,000. However, it is best for your safety and peace of mind to avoid the lowest-charging surgeons and the ones charging very high fees.'],
['are merrell shoes lifetime warranty', "Best Answer: Regular shoes. If your horse doesn't have bad feet, don't put shoes on him. Shoes actually weaken the hooves due to a lack of circulation and the nail holes (they just make the hooves stronger while the shoes are on, once you take them off the hooves are weaker than they were at first).f your horse doesn't have bad feet, don't put shoes on him. Shoes actually weaken the hooves due to a lack of circulation and the nail holes (they just make the hooves stronger while the shoes are on, once you take them off the hooves are weaker than they were at first)."],
['what is the largest capacity dvd disc available', 'Insert a disc that contains files into the drive that is having the problem. Use a type of disc that is not being recognized in the drive. Good discs to use are game or software discs that were purchased from a store. Do not use music CDs. If the DVD drive can read CDs but not DVDs, insert a DVD movie.nsert a software CD (like a game or business software) into the CD/DVD drive and note what happens. If an AutoPlay window opens, the drive is able to read the disc. The data stored on the disc may still be bad, but an AutoPlay window proves that the drive can read data on the disc.'],
['weather in dead sea', "The higher above sea level you go, (for example, the tops of mountains,) the more separated and spaced out the molecules become, which causes cold weather. This is the ACCURATE answer to how elevation affects temperature. learned the answer to this in science this year, so don't worry, it is accurate: The higher above sea level/elevation you are, the colder the temperature becomes. The reas â\x80¦ on for this is because there are air molecules in the air bump closer together when you are lower above sea level-that creates warm weather."],
['who should not contribute to roth ira', 'You can contribute to a Roth at any age, even past retirement age, as long as youâ\x80\x99re still earning taxable income. A working spouse can also contribute to a Roth IRA on behalf of a nonworking spouse. For a 401(k), the 2014 contribution limit is $17,500, unless youâ\x80\x99re 50 or older, in which case the limit is $23,000.hen you can strategize your distributions to minimize your tax liability. You can also contribute to a traditional IRA even if you participate in an employer-sponsored retirement plan, but in some cases not all of your traditional IRA contributions will be tax deductible.'],
]
scores = model.predict(pairs)
print(scores.shape)
# (5,)
# Or rank different texts based on similarity to a single text
ranks = model.rank(
'how much should i pay for breast implants',
[
'Implant Fees. The cost of buying the implants themselves will influence the overall costs of the procedure. Silicone implants cost between $1,800 and $2,500 though this may go up to slightly over $3,000.Saline implants will cost anywhere between $1,200 and $1,600.The cost of implants varies due to size and manufacturer though there is usually not much of a difference.Anesthesia Fees. There are various options for your anesthesia and this will have a direct impact on the fee you will be charged.otal Costs of Brest Implants. With all the above factors taken into consideration, the total cost of breast implants generally are somewhere in the range of $5,000 and $15,000. However, it is best for your safety and peace of mind to avoid the lowest-charging surgeons and the ones charging very high fees.',
"Best Answer: Regular shoes. If your horse doesn't have bad feet, don't put shoes on him. Shoes actually weaken the hooves due to a lack of circulation and the nail holes (they just make the hooves stronger while the shoes are on, once you take them off the hooves are weaker than they were at first).f your horse doesn't have bad feet, don't put shoes on him. Shoes actually weaken the hooves due to a lack of circulation and the nail holes (they just make the hooves stronger while the shoes are on, once you take them off the hooves are weaker than they were at first).",
'Insert a disc that contains files into the drive that is having the problem. Use a type of disc that is not being recognized in the drive. Good discs to use are game or software discs that were purchased from a store. Do not use music CDs. If the DVD drive can read CDs but not DVDs, insert a DVD movie.nsert a software CD (like a game or business software) into the CD/DVD drive and note what happens. If an AutoPlay window opens, the drive is able to read the disc. The data stored on the disc may still be bad, but an AutoPlay window proves that the drive can read data on the disc.',
"The higher above sea level you go, (for example, the tops of mountains,) the more separated and spaced out the molecules become, which causes cold weather. This is the ACCURATE answer to how elevation affects temperature. learned the answer to this in science this year, so don't worry, it is accurate: The higher above sea level/elevation you are, the colder the temperature becomes. The reas â\x80¦ on for this is because there are air molecules in the air bump closer together when you are lower above sea level-that creates warm weather.",
'You can contribute to a Roth at any age, even past retirement age, as long as youâ\x80\x99re still earning taxable income. A working spouse can also contribute to a Roth IRA on behalf of a nonworking spouse. For a 401(k), the 2014 contribution limit is $17,500, unless youâ\x80\x99re 50 or older, in which case the limit is $23,000.hen you can strategize your distributions to minimize your tax liability. You can also contribute to a traditional IRA even if you participate in an employer-sponsored retirement plan, but in some cases not all of your traditional IRA contributions will be tax deductible.',
]
)
# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]
train-eval, NanoMSMARCO, NanoNFCorpus and NanoNQCERerankingEvaluator| Metric | train-eval | NanoMSMARCO | NanoNFCorpus | NanoNQ |
|---|---|---|---|---|
| map | 0.6511 | 0.5909 (+0.1013) | 0.3364 (+0.0660) | 0.6673 (+0.2466) |
| mrr@10 | 0.6494 | 0.5862 (+0.1087) | 0.5282 (+0.0284) | 0.6862 (+0.2595) |
| ndcg@10 | 0.7082 | 0.6658 (+0.1254) | 0.3656 (+0.0405) | 0.7191 (+0.2185) |
NanoBEIR_meanCENanoBEIREvaluator| Metric | Value |
|---|---|
| map | 0.5315 (+0.1380) |
| mrr@10 | 0.6002 (+0.1322) |
| ndcg@10 | 0.5835 (+0.1281) |
sentence_0, sentence_1, and label| sentence_0 | sentence_1 | label | |
|---|---|---|---|
| type | string | string | int |
| details |
|
|
|
| sentence_0 | sentence_1 | label |
|---|---|---|
how much should i pay for breast implants |
Implant Fees. The cost of buying the implants themselves will influence the overall costs of the procedure. Silicone implants cost between $1,800 and $2,500 though this may go up to slightly over $3,000.Saline implants will cost anywhere between $1,200 and $1,600.The cost of implants varies due to size and manufacturer though there is usually not much of a difference.Anesthesia Fees. There are various options for your anesthesia and this will have a direct impact on the fee you will be charged.otal Costs of Brest Implants. With all the above factors taken into consideration, the total cost of breast implants generally are somewhere in the range of $5,000 and $15,000. However, it is best for your safety and peace of mind to avoid the lowest-charging surgeons and the ones charging very high fees. |
1 |
are merrell shoes lifetime warranty |
Best Answer: Regular shoes. If your horse doesn't have bad feet, don't put shoes on him. Shoes actually weaken the hooves due to a lack of circulation and the nail holes (they just make the hooves stronger while the shoes are on, once you take them off the hooves are weaker than they were at first).f your horse doesn't have bad feet, don't put shoes on him. Shoes actually weaken the hooves due to a lack of circulation and the nail holes (they just make the hooves stronger while the shoes are on, once you take them off the hooves are weaker than they were at first). |
0 |
what is the largest capacity dvd disc available |
Insert a disc that contains files into the drive that is having the problem. Use a type of disc that is not being recognized in the drive. Good discs to use are game or software discs that were purchased from a store. Do not use music CDs. If the DVD drive can read CDs but not DVDs, insert a DVD movie.nsert a software CD (like a game or business software) into the CD/DVD drive and note what happens. If an AutoPlay window opens, the drive is able to read the disc. The data stored on the disc may still be bad, but an AutoPlay window proves that the drive can read data on the disc. |
0 |
BinaryCrossEntropyLosseval_strategy: stepsper_device_train_batch_size: 64per_device_eval_batch_size: 64num_train_epochs: 1fp16: Trueoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 64per_device_eval_batch_size: 64per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 1eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 5e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1num_train_epochs: 1max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: {}warmup_ratio: 0.0warmup_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: 42data_seed: Nonejit_mode_eval: Falseuse_ipex: Falsebf16: Falsefp16: Truefp16_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: 0dataloader_prefetch_factor: Nonepast_index: -1disable_tqdm: Falseremove_unused_columns: Truelabel_names: Noneload_best_model_at_end: Falseignore_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}deepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torchoptim_args: Noneadafactor: Falsegroup_by_length: Falselength_column_name: lengthddp_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: Falsegradient_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: Nonedispatch_batches: Nonesplit_batches: Noneinclude_tokens_per_second: Falseinclude_num_input_tokens_seen: Falseneftune_noise_alpha: Noneoptim_target_modules: Nonebatch_eval_metrics: Falseeval_on_start: Falseuse_liger_kernel: Falseeval_use_gather_object: Falseaverage_tokens_across_devices: Falseprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportional| Epoch | Step | Training Loss | train-eval_ndcg@10 | NanoMSMARCO_ndcg@10 | NanoNFCorpus_ndcg@10 | NanoNQ_ndcg@10 | NanoBEIR_mean_ndcg@10 |
|---|---|---|---|---|---|---|---|
| -1 | -1 | - | 0.0312 | 0.0280 (-0.5124) | 0.2260 (-0.0991) | 0.0315 (-0.4691) | 0.0952 (-0.3602) |
| 0.016 | 500 | 0.6271 | - | - | - | - | - |
| 0.032 | 1000 | 0.4867 | - | - | - | - | - |
| 0.048 | 1500 | 0.3551 | - | - | - | - | - |
| 0.064 | 2000 | 0.2768 | - | - | - | - | - |
| 0.08 | 2500 | 0.2455 | - | - | - | - | - |
| 0.096 | 3000 | 0.2186 | - | - | - | - | - |
| 0.112 | 3500 | 0.2151 | - | - | - | - | - |
| 0.128 | 4000 | 0.2002 | - | - | - | - | - |
| 0.144 | 4500 | 0.1973 | - | - | - | - | - |
| 0.16 | 5000 | 0.1928 | 0.6389 | 0.6178 (+0.0774) | 0.3541 (+0.0291) | 0.6869 (+0.1862) | 0.5529 (+0.0976) |
| 0.176 | 5500 | 0.1841 | - | - | - | - | - |
| 0.192 | 6000 | 0.1835 | - | - | - | - | - |
| 0.208 | 6500 | 0.1828 | - | - | - | - | - |
| 0.224 | 7000 | 0.1777 | - | - | - | - | - |
| 0.24 | 7500 | 0.1674 | - | - | - | - | - |
| 0.256 | 8000 | 0.1655 | - | - | - | - | - |
| 0.272 | 8500 | 0.1706 | - | - | - | - | - |
| 0.288 | 9000 | 0.1629 | - | - | - | - | - |
| 0.304 | 9500 | 0.1641 | - | - | - | - | - |
| 0.32 | 10000 | 0.1631 | 0.6859 | 0.6220 (+0.0815) | 0.3849 (+0.0598) | 0.6951 (+0.1944) | 0.5673 (+0.1119) |
| 0.336 | 10500 | 0.1616 | - | - | - | - | - |
| 0.352 | 11000 | 0.1575 | - | - | - | - | - |
| 0.368 | 11500 | 0.1565 | - | - | - | - | - |
| 0.384 | 12000 | 0.1523 | - | - | - | - | - |
| 0.4 | 12500 | 0.1628 | - | - | - | - | - |
| 0.416 | 13000 | 0.1569 | - | - | - | - | - |
| 0.432 | 13500 | 0.1581 | - | - | - | - | - |
| 0.448 | 14000 | 0.1527 | - | - | - | - | - |
| 0.464 | 14500 | 0.1484 | - | - | - | - | - |
| 0.48 | 15000 | 0.1531 | 0.6939 | 0.6455 (+0.1051) | 0.3663 (+0.0413) | 0.6977 (+0.1970) | 0.5698 (+0.1145) |
| 0.496 | 15500 | 0.1482 | - | - | - | - | - |
| 0.512 | 16000 | 0.1523 | - | - | - | - | - |
| 0.528 | 16500 | 0.1532 | - | - | - | - | - |
| 0.544 | 17000 | 0.1513 | - | - | - | - | - |
| 0.56 | 17500 | 0.1486 | - | - | - | - | - |
| 0.576 | 18000 | 0.1438 | - | - | - | - | - |
| 0.592 | 18500 | 0.1496 | - | - | - | - | - |
| 0.608 | 19000 | 0.1455 | - | - | - | - | - |
| 0.624 | 19500 | 0.1474 | - | - | - | - | - |
| 0.64 | 20000 | 0.1484 | 0.7025 | 0.6423 (+0.1019) | 0.3637 (+0.0387) | 0.7162 (+0.2156) | 0.5741 (+0.1187) |
| 0.656 | 20500 | 0.1436 | - | - | - | - | - |
| 0.672 | 21000 | 0.1427 | - | - | - | - | - |
| 0.688 | 21500 | 0.1463 | - | - | - | - | - |
| 0.704 | 22000 | 0.1475 | - | - | - | - | - |
| 0.72 | 22500 | 0.1446 | - | - | - | - | - |
| 0.736 | 23000 | 0.1424 | - | - | - | - | - |
| 0.752 | 23500 | 0.1397 | - | - | - | - | - |
| 0.768 | 24000 | 0.1405 | - | - | - | - | - |
| 0.784 | 24500 | 0.1405 | - | - | - | - | - |
| 0.8 | 25000 | 0.1397 | 0.7014 | 0.6492 (+0.1088) | 0.3672 (+0.0422) | 0.7229 (+0.2222) | 0.5798 (+0.1244) |
| 0.816 | 25500 | 0.1378 | - | - | - | - | - |
| 0.832 | 26000 | 0.1409 | - | - | - | - | - |
| 0.848 | 26500 | 0.1368 | - | - | - | - | - |
| 0.864 | 27000 | 0.1389 | - | - | - | - | - |
| 0.88 | 27500 | 0.1354 | - | - | - | - | - |
| 0.896 | 28000 | 0.1412 | - | - | - | - | - |
| 0.912 | 28500 | 0.138 | - | - | - | - | - |
| 0.928 | 29000 | 0.1369 | - | - | - | - | - |
| 0.944 | 29500 | 0.1321 | - | - | - | - | - |
| 0.96 | 30000 | 0.137 | 0.7150 | 0.6576 (+0.1172) | 0.3655 (+0.0405) | 0.7211 (+0.2204) | 0.5814 (+0.1260) |
| 0.976 | 30500 | 0.1342 | - | - | - | - | - |
| 0.992 | 31000 | 0.137 | - | - | - | - | - |
| 1.0 | 31250 | - | 0.7082 | 0.6658 (+0.1254) | 0.3656 (+0.0405) | 0.7191 (+0.2185) | 0.5835 (+0.1281) |
Carbon emissions were measured using CodeCarbon.
@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
microsoft/MiniLM-L12-H384-uncased