Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper
• 1908.10084 • Published
• 12
This is a sentence-transformers model finetuned from sentence-transformers/all-mpnet-base-v2. It maps sentences & paragraphs to a 768-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.
SentenceTransformer(
(0): Transformer({'max_seq_length': 384, 'do_lower_case': False}) with Transformer model: MPNetModel
(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': True})
(2): Normalize()
)
First install the Sentence Transformers library:
pip install -U sentence-transformers
Then you can load this model and run inference.
from sentence_transformers import SentenceTransformer
# Download from the 🤗 Hub
model = SentenceTransformer("sentence_transformers_model_id")
# Run inference
sentences = [
'We in Britain think differently to Americans.',
'Originally Posted by zaf We in Britain think differently to Americans.',
'south korea has had a bullet train system since the 1980s.',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 768]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [3, 3]
sts-devEmbeddingSimilarityEvaluator| Metric | sts-dev | |
|---|---|---|
| pearson_cosine | 0.9075 | 0.9075 |
| spearman_cosine | 0.906 | 0.906 |
sentence_0, sentence_1, and label| sentence_0 | sentence_1 | label | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence_0 | sentence_1 | label |
|---|---|---|
US Senate to vote on fiscal cliff deal as deadline nears |
Fiscal cliff: House delays vote on fiscal cliff deal - live |
0.5599999904632569 |
This is America, my friends, and it should not happen here," he said to loud applause. |
"This is America, my friends, and it should not happen here." |
0.65 |
Books To Help Kids Talk About Boston Marathon News |
Report of two explosions at finish line of Boston Marathon |
0.1600000023841858 |
CosineSimilarityLoss with these parameters:{
"loss_fct": "torch.nn.modules.loss.MSELoss"
}
eval_strategy: stepsper_device_train_batch_size: 32per_device_eval_batch_size: 32num_train_epochs: 10multi_dataset_batch_sampler: round_robinoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 32per_device_eval_batch_size: 32per_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: 10max_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: 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: 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: round_robin| Epoch | Step | Training Loss | spearman_cosine | sts-dev_spearman_cosine |
|---|---|---|---|---|
| 0 | 0 | - | 0.8811 | - |
| 0.1 | 18 | - | - | 0.8816 |
| 0.2 | 36 | - | - | 0.8834 |
| 0.3 | 54 | - | - | 0.8847 |
| 0.4 | 72 | - | - | 0.8894 |
| 0.5 | 90 | - | - | 0.8933 |
| 0.6 | 108 | - | - | 0.8966 |
| 0.7 | 126 | - | - | 0.9005 |
| 0.8 | 144 | - | - | 0.9020 |
| 0.9 | 162 | - | - | 0.9010 |
| 1.0 | 180 | - | - | 0.9001 |
| 1.1 | 198 | - | - | 0.9022 |
| 1.2 | 216 | - | - | 0.9018 |
| 1.3 | 234 | - | - | 0.9015 |
| 1.4 | 252 | - | - | 0.9029 |
| 1.5 | 270 | - | - | 0.9044 |
| 1.6 | 288 | - | - | 0.9049 |
| 1.7 | 306 | - | - | 0.9051 |
| 1.8 | 324 | - | - | 0.9033 |
| 1.9 | 342 | - | - | 0.9039 |
| 2.0 | 360 | - | - | 0.9050 |
| 2.1 | 378 | - | - | 0.9042 |
| 2.2 | 396 | - | - | 0.9041 |
| 2.3 | 414 | - | - | 0.9040 |
| 2.4 | 432 | - | - | 0.9048 |
| 2.5 | 450 | - | - | 0.9045 |
| 2.6 | 468 | - | - | 0.9046 |
| 2.7 | 486 | - | - | 0.9047 |
| 2.7778 | 500 | 0.0153 | - | - |
| 2.8 | 504 | - | - | 0.9057 |
| 2.9 | 522 | - | - | 0.9065 |
| 3.0 | 540 | - | - | 0.9074 |
| 3.1 | 558 | - | - | 0.9073 |
| 3.2 | 576 | - | - | 0.9065 |
| 3.3 | 594 | - | - | 0.9046 |
| 3.4 | 612 | - | - | 0.9057 |
| 3.5 | 630 | - | - | 0.9069 |
| 3.6 | 648 | - | - | 0.9062 |
| 3.7 | 666 | - | - | 0.9061 |
| 3.8 | 684 | - | - | 0.9050 |
| 3.9 | 702 | - | - | 0.9050 |
| 4.0 | 720 | - | - | 0.9048 |
| 4.1 | 738 | - | - | 0.9052 |
| 4.2 | 756 | - | - | 0.9055 |
| 4.3 | 774 | - | - | 0.9060 |
| 4.4 | 792 | - | - | 0.9059 |
| 4.5 | 810 | - | - | 0.9064 |
| 4.6 | 828 | - | - | 0.9063 |
| 4.7 | 846 | - | - | 0.9063 |
| 4.8 | 864 | - | - | 0.9067 |
| 4.9 | 882 | - | - | 0.9059 |
| 5.0 | 900 | - | - | 0.9052 |
| 5.1 | 918 | - | - | 0.9061 |
| 5.2 | 936 | - | - | 0.9057 |
| 5.3 | 954 | - | - | 0.9053 |
| 5.4 | 972 | - | - | 0.9060 |
| 5.5 | 990 | - | - | 0.9050 |
| 5.5556 | 1000 | 0.0051 | - | - |
| 5.6 | 1008 | - | - | 0.9053 |
| 5.7 | 1026 | - | - | 0.9052 |
| 5.8 | 1044 | - | - | 0.9056 |
| 5.9 | 1062 | - | - | 0.9062 |
| 6.0 | 1080 | - | - | 0.9056 |
| 6.1 | 1098 | - | - | 0.9054 |
| 6.2 | 1116 | - | - | 0.9058 |
| 6.3 | 1134 | - | - | 0.9058 |
| 6.4 | 1152 | - | - | 0.9056 |
| 6.5 | 1170 | - | - | 0.9057 |
| 6.6 | 1188 | - | - | 0.9055 |
| 6.7 | 1206 | - | - | 0.9055 |
| 6.8 | 1224 | - | - | 0.9053 |
| 6.9 | 1242 | - | - | 0.9053 |
| 7.0 | 1260 | - | - | 0.9053 |
| 7.1 | 1278 | - | - | 0.9057 |
| 7.2 | 1296 | - | - | 0.9055 |
| 7.3 | 1314 | - | - | 0.9053 |
| 7.4 | 1332 | - | - | 0.9056 |
| 7.5 | 1350 | - | - | 0.9059 |
| 7.6 | 1368 | - | - | 0.9060 |
| 7.7 | 1386 | - | - | 0.9057 |
| 7.8 | 1404 | - | - | 0.9058 |
| 7.9 | 1422 | - | - | 0.9057 |
| 8.0 | 1440 | - | - | 0.9058 |
| 8.1 | 1458 | - | - | 0.9059 |
| 8.2 | 1476 | - | - | 0.9060 |
| 8.3 | 1494 | - | - | 0.9056 |
| 8.3333 | 1500 | 0.0031 | - | - |
| 8.4 | 1512 | - | - | 0.9057 |
| 8.5 | 1530 | - | - | 0.9060 |
| 8.6 | 1548 | - | - | 0.9058 |
| 8.7 | 1566 | - | - | 0.9060 |
| 8.8 | 1584 | - | - | 0.9062 |
| 8.9 | 1602 | - | - | 0.9061 |
| 9.0 | 1620 | - | - | 0.9061 |
| 9.1 | 1638 | - | - | 0.9061 |
| 9.2 | 1656 | - | - | 0.9059 |
| 9.3 | 1674 | - | - | 0.9060 |
| 9.4 | 1692 | - | - | 0.9061 |
| 9.5 | 1710 | - | - | 0.9061 |
| 9.6 | 1728 | - | - | 0.9061 |
| 9.7 | 1746 | - | - | 0.9060 |
| 9.8 | 1764 | - | - | 0.9061 |
| 9.9 | 1782 | - | - | 0.9061 |
| 10.0 | 1800 | - | 0.9060 | 0.9060 |
@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
sentence-transformers/all-mpnet-base-v2