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, 'architecture': '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("sentence_transformers_model_id")
# Run inference
sentences = [
"Word: r a| Context: r a j b ' a q i i l r a u t i i w .| Translation: El huesito del coyotillo.",
'Morpheme: r a | Gloss: DIM',
'Morpheme: p o r k e | Gloss: porque',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 768]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[1.0000, 0.8346, 0.1137],
# [0.8346, 1.0000, 0.0429],
# [0.1137, 0.0429, 1.0000]])
validationmain.IREvaluatorWithLogging| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.6535 |
| cosine_accuracy@3 | 0.9351 |
| cosine_accuracy@5 | 0.9606 |
| cosine_accuracy@10 | 0.9791 |
| cosine_precision@1 | 0.6535 |
| cosine_precision@3 | 0.3449 |
| cosine_precision@5 | 0.2255 |
| cosine_precision@10 | 0.1256 |
| cosine_recall@1 | 0.5838 |
| cosine_recall@3 | 0.8582 |
| cosine_recall@5 | 0.9008 |
| cosine_recall@10 | 0.9527 |
| cosine_ndcg@10 | 0.8189 |
| cosine_mrr@10 | 0.7922 |
| cosine_map@100 | 0.7623 |
sentence_0, sentence_1, and label| sentence_0 | sentence_1 | label | |
|---|---|---|---|
| type | string | string | int |
| details |
|
|
|
| sentence_0 | sentence_1 | label |
|---|---|---|
Word: l i k ' á y b ' a l| Context: b w e n , n o n q e l i t i b ' i n l o q ' e ' q e l e n w e e l i k ' á y b ' a l| Translation: Bueno asi es compro cosas en el merrcado. |
Morpheme: b ' i l | Gloss: INS |
11799 |
Word: b ' e l e j e b '| Context: r i b ' e l e j e b ' i i k ' ,| Translation: De los nueve meses. |
Morpheme: e b ' | Gloss: NUM |
34957 |
Word: t r a| Context: D e s p w e s t r a j u u t| Translation: Después los jutes. |
Morpheme: t r a | Gloss: DIM |
9903 |
main.LossLoggereval_strategy: stepsper_device_train_batch_size: 64per_device_eval_batch_size: 64num_train_epochs: 50fp16: Truemulti_dataset_batch_sampler: round_robinoverwrite_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: 50max_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}parallelism_config: Nonedeepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torch_fusedoptim_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: Falsehub_revision: Nonegradient_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: Noneinclude_tokens_per_second: Falseinclude_num_input_tokens_seen: Falseneftune_noise_alpha: Noneoptim_target_modules: Nonebatch_eval_metrics: Falseeval_on_start: Falseuse_liger_kernel: Falseliger_kernel_config: Noneeval_use_gather_object: Falseaverage_tokens_across_devices: Falseprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: round_robinrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | validation_cosine_ndcg@10 |
|---|---|---|---|
| 0.5291 | 500 | 1.0856 | 0.6291 |
| 1.0 | 945 | - | 0.6728 |
| 1.0582 | 1000 | 0.8022 | 0.6719 |
| 1.5873 | 1500 | 0.738 | 0.6894 |
| 2.0 | 1890 | - | 0.7071 |
| 2.1164 | 2000 | 0.707 | 0.7359 |
| 2.6455 | 2500 | 0.6807 | 0.7328 |
| 3.0 | 2835 | - | 0.7411 |
| 3.1746 | 3000 | 0.6588 | 0.7200 |
| 3.7037 | 3500 | 0.6526 | 0.7550 |
| 4.0 | 3780 | - | 0.7424 |
| 4.2328 | 4000 | 0.6243 | 0.7574 |
| 4.7619 | 4500 | 0.6239 | 0.7488 |
| 5.0 | 4725 | - | 0.7467 |
| 5.2910 | 5000 | 0.6009 | 0.7538 |
| 5.8201 | 5500 | 0.5984 | 0.7791 |
| 6.0 | 5670 | - | 0.7724 |
| 6.3492 | 6000 | 0.5802 | 0.7861 |
| 6.8783 | 6500 | 0.5768 | 0.8024 |
| 7.0 | 6615 | - | 0.7780 |
| 7.4074 | 7000 | 0.5731 | 0.7770 |
| 7.9365 | 7500 | 0.5665 | 0.7898 |
| 8.0 | 7560 | - | 0.7992 |
| 8.4656 | 8000 | 0.5451 | 0.7836 |
| 8.9947 | 8500 | 0.5611 | 0.7673 |
| 9.0 | 8505 | - | 0.7622 |
| 9.5238 | 9000 | 0.5368 | 0.7548 |
| 10.0 | 9450 | - | 0.7742 |
| 10.0529 | 9500 | 0.5409 | 0.7843 |
| 10.5820 | 10000 | 0.5277 | 0.7467 |
| 11.0 | 10395 | - | 0.7760 |
| 11.1111 | 10500 | 0.5323 | 0.7680 |
| 11.6402 | 11000 | 0.5261 | 0.7765 |
| 12.0 | 11340 | - | 0.7807 |
| 12.1693 | 11500 | 0.511 | 0.7805 |
| 12.6984 | 12000 | 0.5133 | 0.7817 |
| 13.0 | 12285 | - | 0.7476 |
| 13.2275 | 12500 | 0.5185 | 0.7724 |
| 13.7566 | 13000 | 0.5133 | 0.7709 |
| 14.0 | 13230 | - | 0.7621 |
| 14.2857 | 13500 | 0.5054 | 0.7880 |
| 14.8148 | 14000 | 0.5047 | 0.7531 |
| 15.0 | 14175 | - | 0.7696 |
| 15.3439 | 14500 | 0.4995 | 0.7659 |
| 15.8730 | 15000 | 0.4968 | 0.7615 |
| 16.0 | 15120 | - | 0.7686 |
| 16.4021 | 15500 | 0.4841 | 0.7659 |
| 16.9312 | 16000 | 0.4848 | 0.7814 |
| 17.0 | 16065 | - | 0.7766 |
| 17.4603 | 16500 | 0.4804 | 0.7737 |
| 17.9894 | 17000 | 0.4859 | 0.7809 |
| 18.0 | 17010 | - | 0.7789 |
| 18.5185 | 17500 | 0.4749 | 0.7832 |
| 19.0 | 17955 | - | 0.7872 |
| 19.0476 | 18000 | 0.481 | 0.7815 |
| 19.5767 | 18500 | 0.4718 | 0.7730 |
| 20.0 | 18900 | - | 0.7746 |
| 20.1058 | 19000 | 0.4721 | 0.7807 |
| 20.6349 | 19500 | 0.4702 | 0.7973 |
| 21.0 | 19845 | - | 0.7914 |
| 21.1640 | 20000 | 0.4671 | 0.7828 |
| 21.6931 | 20500 | 0.4707 | 0.7841 |
| 22.0 | 20790 | - | 0.7919 |
| 22.2222 | 21000 | 0.4716 | 0.7913 |
| 22.7513 | 21500 | 0.4616 | 0.7752 |
| 23.0 | 21735 | - | 0.7854 |
| 23.2804 | 22000 | 0.4657 | 0.7830 |
| 23.8095 | 22500 | 0.4557 | 0.7713 |
| 24.0 | 22680 | - | 0.7770 |
| 24.3386 | 23000 | 0.4683 | 0.7961 |
| 24.8677 | 23500 | 0.4537 | 0.7895 |
| 25.0 | 23625 | - | 0.7962 |
| 25.3968 | 24000 | 0.4507 | 0.7918 |
| 25.9259 | 24500 | 0.4598 | 0.7985 |
| 26.0 | 24570 | - | 0.7862 |
| 26.4550 | 25000 | 0.458 | 0.7906 |
| 26.9841 | 25500 | 0.4523 | 0.7897 |
| 27.0 | 25515 | - | 0.7879 |
| 27.5132 | 26000 | 0.4441 | 0.7969 |
| 28.0 | 26460 | - | 0.7845 |
| 28.0423 | 26500 | 0.4534 | 0.7974 |
| 28.5714 | 27000 | 0.4444 | 0.7906 |
| 29.0 | 27405 | - | 0.7952 |
| 29.1005 | 27500 | 0.4393 | 0.7933 |
| 29.6296 | 28000 | 0.4408 | 0.7928 |
| 30.0 | 28350 | - | 0.8044 |
| 30.1587 | 28500 | 0.4461 | 0.8052 |
| 30.6878 | 29000 | 0.4419 | 0.7956 |
| 31.0 | 29295 | - | 0.8047 |
| 31.2169 | 29500 | 0.4385 | 0.7957 |
| 31.7460 | 30000 | 0.446 | 0.8037 |
| 32.0 | 30240 | - | 0.7964 |
| 32.2751 | 30500 | 0.4354 | 0.7903 |
| 32.8042 | 31000 | 0.4348 | 0.7885 |
| 33.0 | 31185 | - | 0.8039 |
| 33.3333 | 31500 | 0.4342 | 0.7933 |
| 33.8624 | 32000 | 0.4363 | 0.7974 |
| 34.0 | 32130 | - | 0.7931 |
| 34.3915 | 32500 | 0.4245 | 0.8022 |
| 34.9206 | 33000 | 0.442 | 0.8016 |
| 35.0 | 33075 | - | 0.8013 |
| 35.4497 | 33500 | 0.4293 | 0.8052 |
| 35.9788 | 34000 | 0.4327 | 0.7908 |
| 36.0 | 34020 | - | 0.7941 |
| 36.5079 | 34500 | 0.4267 | 0.8078 |
| 37.0 | 34965 | - | 0.7965 |
| 37.0370 | 35000 | 0.4351 | 0.7942 |
| 37.5661 | 35500 | 0.4276 | 0.8026 |
| 38.0 | 35910 | - | 0.7991 |
| 38.0952 | 36000 | 0.4196 | 0.8083 |
| 38.6243 | 36500 | 0.4312 | 0.8014 |
| 39.0 | 36855 | - | 0.8098 |
| 39.1534 | 37000 | 0.4268 | 0.8152 |
| 39.6825 | 37500 | 0.4224 | 0.8111 |
| 40.0 | 37800 | - | 0.7984 |
| 40.2116 | 38000 | 0.4295 | 0.8095 |
| 40.7407 | 38500 | 0.4243 | 0.8162 |
| 41.0 | 38745 | - | 0.8097 |
| 41.2698 | 39000 | 0.4172 | 0.8139 |
| 41.7989 | 39500 | 0.4259 | 0.8128 |
| 42.0 | 39690 | - | 0.8138 |
| 42.3280 | 40000 | 0.4261 | 0.8116 |
| 42.8571 | 40500 | 0.4156 | 0.8046 |
| 43.0 | 40635 | - | 0.8078 |
| 43.3862 | 41000 | 0.4215 | 0.8185 |
| 43.9153 | 41500 | 0.4175 | 0.8074 |
| 44.0 | 41580 | - | 0.8053 |
| 44.4444 | 42000 | 0.4164 | 0.8108 |
| 44.9735 | 42500 | 0.4147 | 0.8054 |
| 45.0 | 42525 | - | 0.8065 |
| 45.5026 | 43000 | 0.4141 | 0.8145 |
| 46.0 | 43470 | - | 0.8119 |
| 46.0317 | 43500 | 0.4172 | 0.8111 |
| 46.5608 | 44000 | 0.4126 | 0.8127 |
| 47.0 | 44415 | - | 0.8155 |
| 47.0899 | 44500 | 0.4189 | 0.8130 |
| 47.6190 | 45000 | 0.4118 | 0.8163 |
| 48.0 | 45360 | - | 0.8165 |
| 48.1481 | 45500 | 0.4146 | 0.8173 |
| 48.6772 | 46000 | 0.4103 | 0.8181 |
| 49.0 | 46305 | - | 0.8189 |
@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/LaBSE