Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper
•
1908.10084
•
Published
•
9
This is a sentence-transformers model finetuned from sentence-transformers/distiluse-base-multilingual-cased-v2 on the wmt_da, mlqe_en_de, mlqe_en_zh, mlqe_et_en, mlqe_ne_en, mlqe_ro_en and mlqe_si_en datasets. It maps sentences & paragraphs to a 512-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}) with Transformer model: DistilBertModel
(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): Dense({'in_features': 768, 'out_features': 512, 'bias': True, 'activation_function': 'torch.nn.modules.activation.Tanh'})
)
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("RomainDarous/distiluse-base-multilingual-cased-v2-sts")
# Run inference
sentences = [
'Garnizoana otomană se retrage în sudul Dunării, iar după 164 de ani cetatea intră din nou sub stăpânirea europenilor.',
'Ottoman garnisoana is withdrawing into the south of the Danube and, after 164 years, it is once again under the control of Europeans.',
'This is because, once again, we have taken into account the fact that we have adopted a large number of legislative proposals.',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 512]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [3, 3]
sts-eval, sts-test, sts-test, sts-test, sts-test, sts-test, sts-test and sts-testEmbeddingSimilarityEvaluator| Metric | sts-eval | sts-test |
|---|---|---|
| pearson_cosine | 0.4242 | 0.3324 |
| spearman_cosine | 0.4175 | 0.2807 |
sts-evalEmbeddingSimilarityEvaluator| Metric | Value |
|---|---|
| pearson_cosine | 0.0773 |
| spearman_cosine | 0.1305 |
sts-evalEmbeddingSimilarityEvaluator| Metric | Value |
|---|---|
| pearson_cosine | 0.1673 |
| spearman_cosine | 0.1837 |
sts-evalEmbeddingSimilarityEvaluator| Metric | Value |
|---|---|
| pearson_cosine | 0.3567 |
| spearman_cosine | 0.3657 |
sts-evalEmbeddingSimilarityEvaluator| Metric | Value |
|---|---|
| pearson_cosine | 0.4127 |
| spearman_cosine | 0.4104 |
sts-evalEmbeddingSimilarityEvaluator| Metric | Value |
|---|---|
| pearson_cosine | 0.5255 |
| spearman_cosine | 0.4786 |
sts-evalEmbeddingSimilarityEvaluator| Metric | Value |
|---|---|
| pearson_cosine | 0.3119 |
| spearman_cosine | 0.2814 |
sentence1, sentence2, and score| sentence1 | sentence2 | score | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence1 | sentence2 | score |
|---|---|---|
Z dat ÚZIS také vyplývá, že se zastavil úbytek zdravotních sester v nemocnicích. |
The data from the IHIS also shows that the decline of nurses in hospitals has stopped. |
0.47 |
Я был самым гордым, самым пьяным девственником, которого кто-либо когда-либо видел. |
I was the proudest, most drunk virgin anyone had ever seen. |
0.99 |
Das Trampolinspringen hat einen gewissen Außenseitercharme, teilweise weil es für das unaufgeklärte Ohr passender für eine Clownsschule als die für die Olympischen Spiele klingt. |
The trampoline jumping has some outsider charm, in part because it sounds more appropriate for the unenlightened ear for a clowns school than the one for the Olympics. |
0.81 |
CoSENTLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "pairwise_cos_sim"
}
sentence1, sentence2, and score| sentence1 | sentence2 | score | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence1 | sentence2 | score |
|---|---|---|
Early Muslim traders and merchants visited Bengal while traversing the Silk Road in the first millennium. |
Frühe muslimische Händler und Kaufleute besuchten Bengalen, während sie im ersten Jahrtausend die Seidenstraße durchquerten. |
0.9233333468437195 |
While Fran dissipated shortly after that, the tropical wave progressed into the northeastern Pacific Ocean. |
Während Fran kurz danach zerstreute, entwickelte sich die tropische Welle in den nordöstlichen Pazifischen Ozean. |
0.8899999856948853 |
Distressed securities include such events as restructurings, recapitalizations, and bankruptcies. |
Zu den belasteten Wertpapieren gehören Restrukturierungen, Rekapitalisierungen und Insolvenzen. |
0.9300000071525574 |
CoSENTLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "pairwise_cos_sim"
}
sentence1, sentence2, and score| sentence1 | sentence2 | score | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence1 | sentence2 | score |
|---|---|---|
In the late 1980s, the hotel's reputation declined, and it functioned partly as a "backpackers hangout." |
在 20 世纪 80 年代末 , 这家旅馆的声誉下降了 , 部分地起到了 "背包吊销" 的作用。 |
0.40666666626930237 |
From 1870 to 1915, 36 million Europeans migrated away from Europe. |
从 1870 年到 1915 年 , 3, 600 万欧洲人从欧洲移民。 |
0.8333333730697632 |
In some photos, the footpads did press into the regolith, especially when they moved sideways at touchdown. |
在一些照片中 , 脚垫确实挤进了后台 , 尤其是当他们在触地时侧面移动时。 |
0.33000001311302185 |
CoSENTLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "pairwise_cos_sim"
}
sentence1, sentence2, and score| sentence1 | sentence2 | score | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence1 | sentence2 | score |
|---|---|---|
Gruusias vahistati president Mihhail Saakašvili pressibüroo nõunik Simon Kiladze, keda süüdistati spioneerimises. |
In Georgia, an adviser to the press office of President Mikhail Saakashvili, Simon Kiladze, was arrested and accused of spying. |
0.9466666579246521 |
Nii teadmissotsioloogia pooldajad tavaliselt Kuhni tõlgendavadki, arendades tema vaated sõnaselgeks relativismiks. |
This is how supporters of knowledge sociology usually interpret Kuhn by developing his views into an explicit relativism. |
0.9366666674613953 |
18. jaanuaril 2003 haarasid mitmeid Canberra eeslinnu võsapõlengud, milles hukkus neli ja sai vigastada 435 inimest. |
On 18 January 2003, several of the suburbs of Canberra were seized by debt fires which killed four people and injured 435 people. |
0.8666666150093079 |
CoSENTLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "pairwise_cos_sim"
}
sentence1, sentence2, and score| sentence1 | sentence2 | score | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence1 | sentence2 | score |
|---|---|---|
सामान्य बजट प्रायः फेब्रुअरीका अंतिम कार्य दिवसमा लाईन्छ। |
A normal budget is usually awarded to the digital working day of February. |
0.5600000023841858 |
कविताका यस्ता स्वरूपमा दुई, तिन वा चार पाउसम्मका मुक्तक, हाइकु, सायरी र लोकसूक्तिहरू पर्दछन् । |
The book consists of two, free of her or four paulets, haiku, Sairi, and locus in such forms. |
0.23666666448116302 |
ब्रिट्नीले यस बारेमा प्रतिक्रिया ब्यक्ता गरदै भनिन,"कुन ठूलो कुरा हो र? |
Britney did not respond to this, saying "which is a big thing and a big thing? |
0.21666665375232697 |
CoSENTLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "pairwise_cos_sim"
}
sentence1, sentence2, and score| sentence1 | sentence2 | score | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence1 | sentence2 | score |
|---|---|---|
Orașul va fi împărțit în patru districte, iar suburbiile în 10 mahalale. |
The city will be divided into four districts and suburbs into 10 mahalals. |
0.4699999988079071 |
La scurt timp după aceasta, au devenit cunoscute debarcările germane de la Trondheim, Bergen și Stavanger, precum și luptele din Oslofjord. |
In the light of the above, the Authority concludes that the aid granted to ADIF is compatible with the internal market pursuant to Article 61 (3) (c) of the EEA Agreement. |
0.02666666731238365 |
Până în vara 1791, în Clubul iacobinilor au dominat reprezentanții monarhismului liberal constituțional. |
Until the summer of 1791, representatives of liberal constitutional monarchism dominated in the Jacobins Club. |
0.8733333349227905 |
CoSENTLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "pairwise_cos_sim"
}
sentence1, sentence2, and score| sentence1 | sentence2 | score | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence1 | sentence2 | score |
|---|---|---|
ඇපලෝ 4 සැටර්න් V බූස්ටරයේ ප්රථම පර්යේෂණ පියාසැරිය විය. |
The first research flight of the Apollo 4 Saturn V Booster. |
0.7966666221618652 |
මෙහි අවපාතය සැලකීමේ දී, මෙහි 48%ක අවරෝහණය $ මිලියන 125කට අධික චිත්රපටයක් ලද තෙවන කුඩාම අවපාතය වේ. |
In conjunction with the depression here, 48 % of obesity here is the third smallest depression in over $ 125 million film. |
0.17666666209697723 |
එසේම "බකමූණන් මගින් මෙම රාක්ෂසියගේ රාත්රී හැසිරීම සංකේතවත් වන බව" පවසයි. |
Also "the owl says that this monster's night behavior is symbolic". |
0.8799999952316284 |
CoSENTLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "pairwise_cos_sim"
}
sentence1, sentence2, and score| sentence1 | sentence2 | score | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence1 | sentence2 | score |
|---|---|---|
The note adds that should the departure from the White House be delayed, a second aircrew would be needed for the return flight due to duty-hour restrictions. |
V poznámce se dodává, že pokud by se odlet z Bílého domu zpozdil, byla by pro zpáteční let kvůli omezení pracovní doby nutná druhá letecká posádka. |
0.95 |
上半年电信网络诈骗犯罪上升七成 最高检总结特点-中新网 |
In the first half of the year, telecommunication network fraud crimes rose by 70%. The highest inspection summary characteristics-Zhongxin.com |
0.72 |
Als zentrale Herausforderungen für den Bundesnachrichtendienst (BND) nannte Merkel den Kampf gegen die Verbreitung von Falschmeldungen im Internet und die Abwehr von Cyberattacken. |
Merkel a cité la lutte contre la propagation de fausses nouvelles en ligne et la défense contre les cyberattaques comme des défis majeurs pour le service fédéral de renseignement (BND). |
0.87 |
CoSENTLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "pairwise_cos_sim"
}
sentence1, sentence2, and score| sentence1 | sentence2 | score | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence1 | sentence2 | score |
|---|---|---|
Resuming her patrols, Constitution managed to recapture the American sloop Neutrality on 27 March and, a few days later, the French ship Carteret. |
Mit der Wiederaufnahme ihrer Patrouillen gelang es der Verfassung, am 27. März die amerikanische Schleuderneutralität und wenige Tage später das französische Schiff Carteret zurückzuerobern. |
0.9033333659172058 |
Blaine's nomination alienated many Republicans who viewed Blaine as ambitious and immoral. |
Blaines Nominierung entfremdete viele Republikaner, die Blaine als ehrgeizig und unmoralisch betrachteten. |
0.9216666221618652 |
This initiated a brief correspondence between the two which quickly descended into political rancor. |
Dies leitete eine kurze Korrespondenz zwischen den beiden ein, die schnell zu politischem Groll abstieg. |
0.878333330154419 |
CoSENTLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "pairwise_cos_sim"
}
sentence1, sentence2, and score| sentence1 | sentence2 | score | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence1 | sentence2 | score |
|---|---|---|
Freeman briefly stayed with the king before returning to Accra via Whydah, Ahgwey and Little Popo. |
弗里曼在经过惠达、阿格威和小波波回到阿克拉之前与国王一起住了一会儿。 |
0.6683333516120911 |
Fantastic Fiction "Scratches in the Sky, Ben Peek, Agog! |
奇特的虚构 "天空中的碎片 , 本佩克 , 阿戈 ! |
0.71833336353302 |
For Hermann Keller, the running quavers and semiquavers "suffuse the setting with health and strength." |
对赫尔曼 · 凯勒来说 , 跑步的跳跃者和半跳跃者 "让环境充满健康和力量" 。 |
0.7066666483879089 |
CoSENTLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "pairwise_cos_sim"
}
sentence1, sentence2, and score| sentence1 | sentence2 | score | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence1 | sentence2 | score |
|---|---|---|
Jackson pidas seal kõne, öeldes, et James Brown on tema suurim inspiratsioon. |
Jackson gave a speech there saying that James Brown is his greatest inspiration. |
0.9833333492279053 |
Kaanelugu rääkis loo kolme ungarlase üleelamistest Ungari revolutsiooni päevil. |
The life of the Man spoke of a story of three Hungarians living in the days of the Hungarian Revolution. |
0.28999999165534973 |
Teise maailmasõja ajal oli ta mitme Saksa juhatusele alluvate eesti väeosa ülem. |
During World War II, he was the commander of several of the German leadership. |
0.4516666829586029 |
CoSENTLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "pairwise_cos_sim"
}
sentence1, sentence2, and score| sentence1 | sentence2 | score | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence1 | sentence2 | score |
|---|---|---|
१८९२ तिर भवानीदत्त पाण्डेले 'मुद्रा राक्षस'को अनुवाद गरे। |
Around 1892, Bhavani Pandit translated the 'money monster'. |
0.8416666388511658 |
यस बच्चाको मुखले आमाको स्तन यस बच्चाको मुखले आमाको स्तन राम्ररी च्यापेको छ । |
The breasts of this child's mouth are taped well with the mother's mouth. |
0.2150000035762787 |
बुवाको बन्दुक चोरेर हिँडेका बराललाई केआई सिंहले अब गोली ल्याउन लगाए ।... |
Kei Singh, who stole the boy's closet, took the bullet to bring it now.. |
0.27000001072883606 |
CoSENTLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "pairwise_cos_sim"
}
sentence1, sentence2, and score| sentence1 | sentence2 | score | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence1 | sentence2 | score |
|---|---|---|
Cornwallis se afla înconjurat pe uscat de forțe armate net superioare și retragerea pe mare era îndoielnică din cauza flotei franceze. |
Cornwallis was surrounded by shore by higher armed forces and the sea withdrawal was doubtful due to the French fleet. |
0.8199999928474426 |
thumbrightuprightDansatori [[cretani de muzică tradițională. |
Number of employees employed in the production of the like product in the Union. |
0.009999999776482582 |
Potrivit documentelor vremii și tradiției orale, aceasta a fost cea mai grea perioadă din istoria orașului. |
According to the documents of the oral weather and tradition, this was the hardest period in the city's history. |
0.5383332967758179 |
CoSENTLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "pairwise_cos_sim"
}
sentence1, sentence2, and score| sentence1 | sentence2 | score | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence1 | sentence2 | score |
|---|---|---|
එයට ශි්ර ලංකාවේ සාමය ඇති කිරිමටත් නැති කිරිමටත් පුළුවන්. |
It can also cause peace in Sri Lanka. |
0.3199999928474426 |
ඔහු මනෝ විද්යාව, සමාජ විද්යාව, ඉතිහාසය හා සන්නිවේදනය යන විෂය ක්ෂේත්රයන් පිලිබදවද අධ්යයනයන් සිදු කිරීමට උත්සාහ කරන ලදි. |
He attempted to do subjects in psychology, sociology, history and communication. |
0.5366666913032532 |
එහෙත් කිසිදු මිනිසෙක් හෝ ගැහැනියෙක් එලිමහනක නොවූහ. |
But no man or woman was eliminated. |
0.2783333361148834 |
CoSENTLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "pairwise_cos_sim"
}
eval_strategy: stepsper_device_train_batch_size: 64per_device_eval_batch_size: 64num_train_epochs: 2warmup_ratio: 0.1overwrite_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: 1.0num_train_epochs: 2max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: {}warmup_ratio: 0.1warmup_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: proportional| Epoch | Step | Training Loss | wmt da loss | mlqe en de loss | mlqe en zh loss | mlqe et en loss | mlqe ne en loss | mlqe ro en loss | mlqe si en loss | sts-eval_spearman_cosine | sts-test_spearman_cosine |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0.4 | 6690 | 7.8421 | 7.5547 | 7.5619 | 7.5555 | 7.5327 | 7.5354 | 7.5109 | 7.5564 | 0.1989 | - |
| 0.8 | 13380 | 7.552 | 7.5420 | 7.5757 | 7.5739 | 7.5185 | 7.5126 | 7.4994 | 7.5511 | 0.2336 | - |
| 1.2 | 20070 | 7.5216 | 7.5465 | 7.6072 | 7.5942 | 7.5217 | 7.5141 | 7.4871 | 7.5471 | 0.2694 | - |
| 1.6 | 26760 | 7.5024 | 7.5329 | 7.6123 | 7.5814 | 7.5230 | 7.5141 | 7.4679 | 7.5379 | 0.2866 | - |
| 2.0 | 33450 | 7.495 | 7.5252 | 7.6106 | 7.5756 | 7.5201 | 7.5128 | 7.4725 | 7.5417 | 0.2814 | 0.2807 |
@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",
}
@online{kexuefm-8847,
title={CoSENT: A more efficient sentence vector scheme than Sentence-BERT},
author={Su Jianlin},
year={2022},
month={Jan},
url={https://kexue.fm/archives/8847},
}