Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper
• 1908.10084 • Published
• 12
This is a sentence-transformers model finetuned from sentence-transformers/LaBSE. 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': 256, 'do_lower_case': False}) with Transformer model: BertModel
(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': True, 'pooling_mode_mean_tokens': False, '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): Dense({'in_features': 768, 'out_features': 768, 'bias': True, 'activation_function': 'torch.nn.modules.activation.Tanh'})
(3): 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("panagoa/LaBSE-kbd-v0.2")
# Run inference
sentences = [
"We've never seen Tom this angry before.",
"Tom'u daha önce asla bu kadar öfkeli görmedik.",
'Soyez attentive aux voleurs à la tire.',
]
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]
validationEmbeddingSimilarityEvaluator| Metric | Value |
|---|---|
| pearson_cosine | -0.28 |
| spearman_cosine | -0.3212 |
sentence_0, sentence_1, and label| sentence_0 | sentence_1 | label | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence_0 | sentence_1 | label |
|---|---|---|
Почему вас это удивило? |
Сыт ар щIывгъэщIэгъуар? |
0.9298050403594972 |
Ребёнка кто-нибудь видел? |
Quelqu'un a-t-il vu l'enfant ? |
0.0 |
Marie se couchait. |
Мэри гъуэлъырт. |
0.9330472946166992 |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim"
}
eval_strategy: stepsper_device_train_batch_size: 16per_device_eval_batch_size: 16num_train_epochs: 2multi_dataset_batch_sampler: round_robinoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 16per_device_eval_batch_size: 16per_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: 1.0num_train_epochs: 2max_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 | validation_spearman_cosine |
|---|---|---|---|
| 0.0005 | 100 | - | -0.7761 |
| 0.0009 | 200 | - | -0.7598 |
| 0.0014 | 300 | - | -0.7485 |
| 0.0019 | 400 | - | -0.7412 |
| 0.0024 | 500 | 0.2864 | -0.7354 |
| 0.0028 | 600 | - | -0.7307 |
| 0.0033 | 700 | - | -0.7191 |
| 0.0038 | 800 | - | -0.7206 |
| 0.0042 | 900 | - | -0.7197 |
| 0.0047 | 1000 | 0.0463 | -0.7037 |
| 0.0052 | 1100 | - | -0.6866 |
| 0.0057 | 1200 | - | -0.6798 |
| 0.0061 | 1300 | - | -0.6844 |
| 0.0066 | 1400 | - | -0.6716 |
| 0.0071 | 1500 | 0.0184 | -0.6658 |
| 0.0075 | 1600 | - | -0.6620 |
| 0.0080 | 1700 | - | -0.6532 |
| 0.0085 | 1800 | - | -0.6455 |
| 0.0090 | 1900 | - | -0.6452 |
| 0.0094 | 2000 | 0.011 | -0.6360 |
| 0.0099 | 2100 | - | -0.6240 |
| 0.0104 | 2200 | - | -0.6220 |
| 0.0108 | 2300 | - | -0.6294 |
| 0.0113 | 2400 | - | -0.6038 |
| 0.0118 | 2500 | 0.0092 | -0.6116 |
| 0.0122 | 2600 | - | -0.5996 |
| 0.0127 | 2700 | - | -0.6120 |
| 0.0132 | 2800 | - | -0.5940 |
| 0.0137 | 2900 | - | -0.5848 |
| 0.0141 | 3000 | 0.0071 | -0.5958 |
| 0.0146 | 3100 | - | -0.5840 |
| 0.0151 | 3200 | - | -0.5944 |
| 0.0155 | 3300 | - | -0.5895 |
| 0.0160 | 3400 | - | -0.5849 |
| 0.0165 | 3500 | 0.0056 | -0.5708 |
| 0.0005 | 100 | - | -0.5686 |
| 0.0009 | 200 | - | -0.5608 |
| 0.0014 | 300 | - | -0.5587 |
| 0.0024 | 500 | 0.0053 | - |
| 0.0047 | 1000 | 0.0081 | -0.5882 |
| 0.0071 | 1500 | 0.0058 | - |
| 0.0094 | 2000 | 0.0064 | -0.5127 |
| 0.0118 | 2500 | 0.004 | - |
| 0.0141 | 3000 | 0.0042 | -0.4934 |
| 0.0165 | 3500 | 0.0048 | - |
| 0.0188 | 4000 | 0.0036 | -0.4762 |
| 0.0212 | 4500 | 0.0051 | - |
| 0.0236 | 5000 | 0.0054 | -0.4754 |
| 0.0259 | 5500 | 0.0054 | - |
| 0.0283 | 6000 | 0.0054 | -0.4609 |
| 0.0306 | 6500 | 0.0044 | - |
| 0.0330 | 7000 | 0.0048 | -0.4716 |
| 0.0353 | 7500 | 0.0061 | - |
| 0.0377 | 8000 | 0.0018 | -0.4293 |
| 0.0400 | 8500 | 0.0047 | - |
| 0.0424 | 9000 | 0.0043 | -0.4311 |
| 0.0448 | 9500 | 0.0034 | - |
| 0.0471 | 10000 | 0.0041 | -0.4429 |
| 0.0495 | 10500 | 0.0028 | - |
| 0.0518 | 11000 | 0.0032 | -0.4324 |
| 0.0542 | 11500 | 0.0025 | - |
| 0.0565 | 12000 | 0.0037 | -0.4374 |
| 0.0589 | 12500 | 0.003 | - |
| 0.0612 | 13000 | 0.005 | -0.4522 |
| 0.0636 | 13500 | 0.0051 | - |
| 0.0660 | 14000 | 0.0048 | -0.3994 |
| 0.0683 | 14500 | 0.0034 | - |
| 0.0707 | 15000 | 0.0032 | -0.4148 |
| 0.0730 | 15500 | 0.0046 | - |
| 0.0754 | 16000 | 0.0026 | -0.3848 |
| 0.0777 | 16500 | 0.0036 | - |
| 0.0801 | 17000 | 0.0051 | -0.3845 |
| 0.0824 | 17500 | 0.0031 | - |
| 0.0848 | 18000 | 0.0035 | -0.3500 |
| 0.0872 | 18500 | 0.0028 | - |
| 0.0895 | 19000 | 0.0021 | -0.3634 |
| 0.0919 | 19500 | 0.0025 | - |
| 0.0942 | 20000 | 0.0023 | -0.3428 |
| 0.0966 | 20500 | 0.0042 | - |
| 0.0989 | 21000 | 0.0038 | -0.3432 |
| 0.1013 | 21500 | 0.005 | - |
| 0.1037 | 22000 | 0.0024 | -0.3515 |
| 0.1060 | 22500 | 0.0029 | - |
| 0.1084 | 23000 | 0.0033 | -0.3929 |
| 0.1107 | 23500 | 0.003 | - |
| 0.1131 | 24000 | 0.0029 | -0.3309 |
| 0.1154 | 24500 | 0.0038 | - |
| 0.1178 | 25000 | 0.0028 | -0.3369 |
| 0.1201 | 25500 | 0.0025 | - |
| 0.1225 | 26000 | 0.002 | -0.3257 |
| 0.1249 | 26500 | 0.0025 | - |
| 0.1272 | 27000 | 0.0033 | -0.3659 |
| 0.1296 | 27500 | 0.0023 | - |
| 0.1319 | 28000 | 0.0031 | -0.3208 |
| 0.1343 | 28500 | 0.0027 | - |
| 0.1366 | 29000 | 0.0031 | -0.3298 |
| 0.1390 | 29500 | 0.0047 | - |
| 0.1413 | 30000 | 0.003 | -0.3460 |
| 0.1437 | 30500 | 0.004 | - |
| 0.1461 | 31000 | 0.0027 | -0.3567 |
| 0.1484 | 31500 | 0.0063 | - |
| 0.1508 | 32000 | 0.003 | -0.3382 |
| 0.1531 | 32500 | 0.0022 | - |
| 0.1555 | 33000 | 0.0048 | -0.3475 |
| 0.1578 | 33500 | 0.0021 | - |
| 0.1602 | 34000 | 0.0043 | -0.3323 |
| 0.1625 | 34500 | 0.0031 | - |
| 0.1649 | 35000 | 0.0024 | -0.3207 |
| 0.1673 | 35500 | 0.0029 | - |
| 0.1696 | 36000 | 0.0032 | -0.3004 |
| 0.1720 | 36500 | 0.0046 | - |
| 0.1743 | 37000 | 0.0033 | -0.3085 |
| 0.1767 | 37500 | 0.002 | - |
| 0.1790 | 38000 | 0.0022 | -0.3270 |
| 0.1814 | 38500 | 0.0036 | - |
| 0.1837 | 39000 | 0.0034 | -0.3042 |
| 0.1861 | 39500 | 0.0034 | - |
| 0.1885 | 40000 | 0.0016 | -0.3193 |
| 0.1908 | 40500 | 0.0026 | - |
| 0.1932 | 41000 | 0.0028 | -0.2945 |
| 0.1955 | 41500 | 0.0031 | - |
| 0.1979 | 42000 | 0.0016 | -0.2942 |
| 0.2002 | 42500 | 0.0021 | - |
| 0.2026 | 43000 | 0.003 | -0.2998 |
| 0.2049 | 43500 | 0.0042 | - |
| 0.2073 | 44000 | 0.0023 | -0.3245 |
| 0.2097 | 44500 | 0.0018 | - |
| 0.2120 | 45000 | 0.0021 | -0.3212 |
@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",
}
@misc{henderson2017efficient,
title={Efficient Natural Language Response Suggestion for Smart Reply},
author={Matthew Henderson and Rami Al-Rfou and Brian Strope and Yun-hsuan Sung and Laszlo Lukacs and Ruiqi Guo and Sanjiv Kumar and Balint Miklos and Ray Kurzweil},
year={2017},
eprint={1705.00652},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
Base model
sentence-transformers/LaBSE