Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 15
How to use Bheri/ithasa-mmbert-gist with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("Bheri/ithasa-mmbert-gist")
sentences = [
"The false promise of sovereignty.",
"२ जिगीषोः प्रयाणे च अमरः।",
"सत्त्वहेतु सुदृढकृत प्रतिज्ञा।",
"उम्र क्रमशः 16 वर्ष व 15 वर्ष है।"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from jhu-clsp/mmBERT-base. 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': 128, 'do_lower_case': False, 'architecture': 'ModernBertModel'})
(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})
)
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 = [
'attenuated vaccines:',
'कम संवेदनशील टीकेः',
'६.५% दसादशे',
]
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.8402, 0.7259],
# [0.8402, 1.0000, 0.7006],
# [0.7259, 0.7006, 1.0000]])
eval-en-saTranslationEvaluator| Metric | Value |
|---|---|
| src2trg_accuracy | 0.632 |
| trg2src_accuracy | 0.63 |
| mean_accuracy | 0.631 |
sentence1 and sentence2| sentence1 | sentence2 | |
|---|---|---|
| type | string | string |
| details |
|
|
| sentence1 | sentence2 |
|---|---|
There was no Mughal tradition of primogeniture, the systematic passing of rule, upon an emperor's death, to his eldest son. |
चक्रवर्तिनः मृत्योः अनन्तरं तस्य शासनस्य व्यवस्थितरूपेण सङ्क्रमणस्य, मुघलपरम्परायाः ज्येष्ठपुत्राधिकारपद्धतिः नासीत्। |
The four sons of Shah Jahan all held governorships during their father's reign. |
शाह्-जहाँ-नामकस्य चत्वारः पुत्राः, सर्वे पितुः शासनकाले शासकपदम् अधारयन्। |
In this regard he discusses the correlation between social opportunities of education and health and how both of these complement economic and political freedoms as a healthy and well-educated person is better suited to make informed economic decisions and be involved in fruitful political demonstrations etc. |
अस्मिन् विषये सः शिक्षणस्य स्वास्थ्यस्य च सामाजिकावकाशानाम् अन्योन्य-सम्बन्धस्य, तथा च एतद्द्वयम् अपि आर्थिक-राजनैतिक-स्वातन्त्र्ययोः कथं पूरकं भवतः इति च चर्चां करोति, यतोहि स्वस्था सुशिक्षिता च व्यक्तिः ज्ञानपूर्वम् आर्थिकविषयान् निर्णेतुं तथा फलप्रदेषु राजनैतिकेषु प्रतिपादनादिषु संलग्नः भवितुं च अधिकारी भवति इति। |
CachedGISTEmbedLoss with these parameters:{
"guide": "SentenceTransformer('Bheri/labse-en-sa-v1')",
"temperature": 0.01,
"mini_batch_size": 32,
"margin_strategy": "absolute",
"margin": 0.0,
"contrast_anchors": true,
"contrast_positives": true,
"gather_across_devices": false
}
sentence1 and sentence2| sentence1 | sentence2 | |
|---|---|---|
| type | string | string |
| details |
|
|
| sentence1 | sentence2 |
|---|---|
plus 2 tempered glass screen protectors: |
6 पश्चात तापाभिसंतप्तॊ विदुर समार कर्शितः |
"Take sadaqah (alms) from their wealth in order to purify them with it." (p. |
अप्येकाङ्गेऽप्यधोवस्तुमिच्छामि च सुकुत्सिते" ॥ |
"Who could it possibly be?" |
कश्च तासेः सम्भवति ? |
CachedGISTEmbedLoss with these parameters:{
"guide": "SentenceTransformer('Bheri/labse-en-sa-v1')",
"temperature": 0.01,
"mini_batch_size": 32,
"margin_strategy": "absolute",
"margin": 0.0,
"contrast_anchors": true,
"contrast_positives": true,
"gather_across_devices": false
}
per_device_train_batch_size: 32num_train_epochs: 5max_steps: 14000learning_rate: 2e-05warmup_steps: 500gradient_accumulation_steps: 4bf16: Trueeval_strategy: stepsload_best_model_at_end: Trueper_device_train_batch_size: 32num_train_epochs: 5max_steps: 14000learning_rate: 2e-05lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 500optim: adamw_torch_fusedoptim_args: Noneweight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08optim_target_modules: Nonegradient_accumulation_steps: 4average_tokens_across_devices: Truemax_grad_norm: 1.0label_smoothing_factor: 0.0bf16: Truefp16: Falsebf16_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: trackioeval_strategy: stepsper_device_eval_batch_size: 8prediction_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: 42data_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: 0dataloader_pin_memory: Truedataloader_persistent_workers: Falsedataloader_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_backend: Noneddp_timeout: 1800fsdp: []fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}deepspeed: 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: {}| Epoch | Step | Training Loss | Validation Loss | eval-en-sa_mean_accuracy |
|---|---|---|---|---|
| 0.0034 | 100 | 20.6784 | - | - |
| 0.0068 | 200 | 11.1049 | - | - |
| 0.0102 | 300 | 3.2979 | - | - |
| 0.0137 | 400 | 1.8530 | - | - |
| 0.0171 | 500 | 1.3271 | - | - |
| 0.0205 | 600 | 1.0448 | - | - |
| 0.0239 | 700 | 0.8774 | - | - |
| 0.0273 | 800 | 0.8045 | - | - |
| 0.0307 | 900 | 0.7365 | - | - |
| 0.0341 | 1000 | 0.6741 | 0.2732 | 0.5425 |
| 0.0376 | 1100 | 0.6641 | - | - |
| 0.0410 | 1200 | 0.6364 | - | - |
| 0.0444 | 1300 | 0.5756 | - | - |
| 0.0478 | 1400 | 0.5813 | - | - |
| 0.0512 | 1500 | 0.5673 | - | - |
| 0.0546 | 1600 | 0.5489 | - | - |
| 0.0580 | 1700 | 0.5330 | - | - |
| 0.0614 | 1800 | 0.5271 | - | - |
| 0.0649 | 1900 | 0.5327 | - | - |
| 0.0683 | 2000 | 0.4929 | 0.1969 | 0.5855 |
| 0.0717 | 2100 | 0.4895 | - | - |
| 0.0751 | 2200 | 0.4848 | - | - |
| 0.0785 | 2300 | 0.4926 | - | - |
| 0.0819 | 2400 | 0.4627 | - | - |
| 0.0853 | 2500 | 0.4717 | - | - |
| 0.0888 | 2600 | 0.4835 | - | - |
| 0.0922 | 2700 | 0.4621 | - | - |
| 0.0956 | 2800 | 0.4544 | - | - |
| 0.0990 | 2900 | 0.4634 | - | - |
| 0.1024 | 3000 | 0.4314 | 0.1699 | 0.599 |
| 0.1058 | 3100 | 0.4392 | - | - |
| 0.1092 | 3200 | 0.4216 | - | - |
| 0.1127 | 3300 | 0.4366 | - | - |
| 0.1161 | 3400 | 0.4305 | - | - |
| 0.1195 | 3500 | 0.4100 | - | - |
| 0.1229 | 3600 | 0.4181 | - | - |
| 0.1263 | 3700 | 0.4238 | - | - |
| 0.1297 | 3800 | 0.4398 | - | - |
| 0.1331 | 3900 | 0.4284 | - | - |
| 0.1366 | 4000 | 0.4202 | 0.1505 | 0.615 |
| 0.1400 | 4100 | 0.4189 | - | - |
| 0.1434 | 4200 | 0.4228 | - | - |
| 0.1468 | 4300 | 0.4137 | - | - |
| 0.1502 | 4400 | 0.4052 | - | - |
| 0.1536 | 4500 | 0.4041 | - | - |
| 0.1570 | 4600 | 0.3988 | - | - |
| 0.1604 | 4700 | 0.4039 | - | - |
| 0.1639 | 4800 | 0.3977 | - | - |
| 0.1673 | 4900 | 0.3917 | - | - |
| 0.1707 | 5000 | 0.4036 | 0.1458 | 0.6245 |
| 0.1741 | 5100 | 0.4162 | - | - |
| 0.1775 | 5200 | 0.3984 | - | - |
| 0.1809 | 5300 | 0.4099 | - | - |
| 0.1843 | 5400 | 0.3930 | - | - |
| 0.1878 | 5500 | 0.4112 | - | - |
| 0.1912 | 5600 | 0.4248 | - | - |
| 0.1946 | 5700 | 0.3883 | - | - |
| 0.1980 | 5800 | 0.3970 | - | - |
| 0.2014 | 5900 | 0.3876 | - | - |
| 0.2048 | 6000 | 0.4068 | 0.1393 | 0.6255 |
| 0.2082 | 6100 | 0.3816 | - | - |
| 0.2117 | 6200 | 0.3938 | - | - |
| 0.2151 | 6300 | 0.3976 | - | - |
| 0.2185 | 6400 | 0.3806 | - | - |
| 0.2219 | 6500 | 0.3930 | - | - |
| 0.2253 | 6600 | 0.4046 | - | - |
| 0.2287 | 6700 | 0.3791 | - | - |
| 0.2321 | 6800 | 0.3708 | - | - |
| 0.2355 | 6900 | 0.3856 | - | - |
| 0.2390 | 7000 | 0.3934 | 0.1359 | 0.6275 |
| 0.2424 | 7100 | 0.3910 | - | - |
| 0.2458 | 7200 | 0.3860 | - | - |
| 0.2492 | 7300 | 0.3978 | - | - |
| 0.2526 | 7400 | 0.3836 | - | - |
| 0.2560 | 7500 | 0.3862 | - | - |
| 0.2594 | 7600 | 0.3833 | - | - |
| 0.2629 | 7700 | 0.3774 | - | - |
| 0.2663 | 7800 | 0.3938 | - | - |
| 0.2697 | 7900 | 0.3804 | - | - |
| 0.2731 | 8000 | 0.3746 | 0.1348 | 0.632 |
| 0.2765 | 8100 | 0.3894 | - | - |
| 0.2799 | 8200 | 0.3732 | - | - |
| 0.2833 | 8300 | 0.3674 | - | - |
| 0.2868 | 8400 | 0.3965 | - | - |
| 0.2902 | 8500 | 0.3830 | - | - |
| 0.2936 | 8600 | 0.3857 | - | - |
| 0.2970 | 8700 | 0.3759 | - | - |
| 0.3004 | 8800 | 0.3997 | - | - |
| 0.3038 | 8900 | 0.3764 | - | - |
| 0.3072 | 9000 | 0.3786 | 0.1340 | 0.633 |
| 0.3107 | 9100 | 0.3709 | - | - |
| 0.3141 | 9200 | 0.3683 | - | - |
| 0.3175 | 9300 | 0.3812 | - | - |
| 0.3209 | 9400 | 0.3760 | - | - |
| 0.3243 | 9500 | 0.3781 | - | - |
| 0.3277 | 9600 | 0.3766 | - | - |
| 0.3311 | 9700 | 0.3704 | - | - |
| 0.3345 | 9800 | 0.3875 | - | - |
| 0.3380 | 9900 | 0.3887 | - | - |
| 0.3414 | 10000 | 0.3904 | 0.1342 | 0.633 |
| 0.3448 | 10100 | 0.3790 | - | - |
| 0.3482 | 10200 | 0.3639 | - | - |
| 0.3516 | 10300 | 0.3710 | - | - |
| 0.3550 | 10400 | 0.3823 | - | - |
| 0.3584 | 10500 | 0.3829 | - | - |
| 0.3619 | 10600 | 0.3880 | - | - |
| 0.3653 | 10700 | 0.3914 | - | - |
| 0.3687 | 10800 | 0.3638 | - | - |
| 0.3721 | 10900 | 0.3896 | - | - |
| 0.3755 | 11000 | 0.3800 | 0.1345 | 0.629 |
| 0.3789 | 11100 | 0.3823 | - | - |
| 0.3823 | 11200 | 0.3773 | - | - |
| 0.3858 | 11300 | 0.3615 | - | - |
| 0.3892 | 11400 | 0.3757 | - | - |
| 0.3926 | 11500 | 0.3690 | - | - |
| 0.3960 | 11600 | 0.3760 | - | - |
| 0.3994 | 11700 | 0.3734 | - | - |
| 0.4028 | 11800 | 0.3948 | - | - |
| 0.4062 | 11900 | 0.3867 | - | - |
| 0.4097 | 12000 | 0.3876 | 0.1340 | 0.631 |
| 0.4131 | 12100 | 0.3702 | - | - |
| 0.4165 | 12200 | 0.3882 | - | - |
| 0.4199 | 12300 | 0.3881 | - | - |
| 0.4233 | 12400 | 0.3894 | - | - |
| 0.4267 | 12500 | 0.3823 | - | - |
| 0.4301 | 12600 | 0.3816 | - | - |
| 0.4335 | 12700 | 0.3844 | - | - |
| 0.4370 | 12800 | 0.3782 | - | - |
| 0.4404 | 12900 | 0.3811 | - | - |
| 0.4438 | 13000 | 0.386 | 0.1339 | 0.6335 |
| 0.4472 | 13100 | 0.3704 | - | - |
| 0.4506 | 13200 | 0.3719 | - | - |
| 0.4540 | 13300 | 0.3936 | - | - |
| 0.4574 | 13400 | 0.3867 | - | - |
| 0.4609 | 13500 | 0.3654 | - | - |
| 0.4643 | 13600 | 0.3614 | - | - |
| 0.4677 | 13700 | 0.3740 | - | - |
| 0.4711 | 13800 | 0.3943 | - | - |
| 0.4745 | 13900 | 0.3793 | - | - |
| 0.4779 | 14000 | 0.3756 | 0.1345 | 0.631 |
@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
jhu-clsp/mmBERT-base