Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 15
How to use jangedoo/sanolm-v2 with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("jangedoo/sanolm-v2")
sentences = [
"मैले अघि किनिएको सामान फिर्ता गर्न खोज्दैछु, तर मेरो बिल र रिटर्न कागजातहरू कहाँ पेश गर्नुपर्छ?",
"आट्टक्कथा गायक (भागवतर) द्वारा कथकळिको कथाको प्रस्तुति हुन्छ, त्यसैका आधारमा नट अभिनय गर्दछन् । कथकळिमा दुइ गायक हुन्छन्, पहिला एक गायक गाउँछ, अर्को गायक त्यसलाई दोहरा्दछ । पहिला गाने भएकालोई 'पोन्नानि' र अर्का गायकलाई 'शिंकिटि' भनिन्छ । जबसम्म नट गीतहरूका भाव र अर्थलाई पूर्णतः अभिनीत गर्दछन् तबसम्म गायक गाँदै रहन्छन् । कथकळि संगीतलाई Mood Music पनि भनिन्छ ।",
"१३) भुसेल ३३) करजङ",
"सामान फिर्ता गर्नका लागि, कृपया तपाईंले किनमेल गरेको स्टोरको ग्राहक सेवा केन्द्रमा सम्पर्क गर्नुहोस् वा हाम्रो आधिकारिक वेबसाइटमा उपलब्ध रिटर्न प्रक्रिया अनुसार आवश्यक कागजातहरू अपलोड गर्नुहोस्।"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from jangedoo/sanolm-base-v2 on the hard_negatives and replay datasets. It maps sentences & paragraphs to a 384-dimensional dense vector space and can be used for retrieval.
SentenceTransformer(
(0): Transformer({'transformer_task': 'feature-extraction', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'last_hidden_state'}}, 'module_output_name': 'token_embeddings', 'architecture': 'ModernBertModel'})
(1): Pooling({'embedding_dimension': 384, 'pooling_mode': 'mean', '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
queries = [
'डेङ्गी रोग विश्वका कति देशहरूमा व्याप्त छ?',
]
documents = [
'डेङ्गी दोस्रो विश्वयुद्धको समयदेखि विश्वव्यापी समस्या बनेको हो। हाल यो रोग विश्वका ११० देशहरूमा व्याप्त छ। प्रत्येक वर्ष यो रोगका कारण करीब ५ करोडदेखि ५ करोड २८ लाख मानिसहरू बिरामी पर्ने गरेका छन्। जसमध्ये करीब दसहजारदेखि बीसहजार मानिसहरूको मृत्यु हुने गरेको छ। डेङ्गीको महामारीको बारेमा सन् १७७९ लिखित तथ्य भेटिएको छ। यो रोग भाइरसका कारणले लाग्ने र लामखुट्टेका कारणले मानिसमा सर्ने गरेको तथ्य बीसौँ सताब्दीमै पत्ता लागेको थियो। लामखुट्टेको निर्मुल पार्न असम्भव जस्तै भएकोले सिँधै भाइरसलाई नियन्त्रण गर्ने औषधिहरूको बारेमा पनि अध्ययन भइरहेको छ।',
"Despite some changes, China's one-child family planning program remains a source of coercion, forced abortions, infanticide and perilously imbalanced boy-girl ratios, State Department officials said Tuesday.",
'बलभद्र कुँवर नेपाली सेना (तत्कालिन गोरखाली सेना)को पुरानो गोरख गणको कप्तान थिए। उनले देहरादुनको बाहिर नालापानीको युद्धमा गोरखाली सेनाका नेतृत्व गर्दै लडेका थिए।',
]
query_embeddings = model.encode_query(queries)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings.shape)
# [1, 384] [3, 384]
# Get the similarity scores for the embeddings
similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities)
# tensor([[0.8878, 0.7303, 0.6111]])
hard_negative, indic_rag, balanced_news, en_ne_alignment, hard_negative, indic_rag, balanced_news and en_ne_alignmentInformationRetrievalEvaluator with these parameters:{
"query_prompt_name": "query",
"corpus_prompt_name": "passage"
}
| Metric | hard_negative | indic_rag | balanced_news | en_ne_alignment |
|---|---|---|---|---|
| cosine_accuracy@1 | 0.369 | 0.655 | 0.6283 | 0.0106 |
| cosine_accuracy@3 | 0.593 | 0.742 | 0.775 | 0.6567 |
| cosine_accuracy@5 | 0.683 | 0.771 | 0.815 | 0.7981 |
| cosine_accuracy@10 | 0.768 | 0.814 | 0.8517 | 0.8944 |
| cosine_precision@1 | 0.369 | 0.655 | 0.6283 | 0.0106 |
| cosine_precision@3 | 0.1977 | 0.2473 | 0.2583 | 0.2189 |
| cosine_precision@5 | 0.1366 | 0.1542 | 0.163 | 0.1596 |
| cosine_precision@10 | 0.0768 | 0.0814 | 0.0852 | 0.0894 |
| cosine_recall@1 | 0.369 | 0.655 | 0.6283 | 0.0106 |
| cosine_recall@3 | 0.593 | 0.742 | 0.775 | 0.6567 |
| cosine_recall@5 | 0.683 | 0.771 | 0.815 | 0.7981 |
| cosine_recall@10 | 0.768 | 0.814 | 0.8517 | 0.8944 |
| cosine_ndcg@10 | 0.564 | 0.7324 | 0.744 | 0.489 |
| cosine_mrr@10 | 0.4992 | 0.7065 | 0.7091 | 0.355 |
| cosine_map@100 | 0.5055 | 0.7105 | 0.7138 | 0.3599 |
anchor, positive, negative_1, negative_2, and negative_3| anchor | positive | negative_1 | negative_2 | negative_3 | |
|---|---|---|---|---|---|
| type | string | string | string | string | string |
| modality | text | text | text | text | text |
| details |
|
|
|
|
|
| anchor | positive | negative_1 | negative_2 | negative_3 |
|---|---|---|---|---|
Baby lai night time ma wake garyo bhane ke fix garnu parcha? |
यदि बच्चा राति उठेर रोइरहेको छ भने, सबैभन्दा पहिले उसलाई आरामदायी वातावरण दिनुहोस्। प्रकाश कम राख्नुहोस्, मधुर आवाजमा कुरा गर्नुहोस् र बिस्तारै उसलाई सुत्न लगाउनुहोस्। यदि समस्या जारी रहेमा बालरोग विशेषज्ञ (Pediatrician) सँग consult गर्नु राम्रो हुन्छ। |
Bataune kura garna saknu hunchha, tara thik fix pani hunna sakcha. |
Baby lai garma garma chautari ma rakhnu parcha, yeta le help garcha. |
Sadae thik bhanda lai 10 minute samma wait garnuhos, pachi pani wake bhane pani bhetna pardaina. |
पासपोर्ट बनाउन कुन अफिसमा जानुपर्छ? |
नेपाली नागरिकले नयाँ पासपोर्टको लागि सम्बन्धित जिल्ला प्रशासन कार्यालय (District Administration Office) मा निवेदन दिनुपर्ने हुन्छ। |
पासपोर्टको लागि सबैभन्दा नजिकको बैंक शाखामा मात्र जाने आवश्यकता पर्दछ। |
तपाईँले पासपोर्ट नवीकरणको लागि मात्र 'विदेश सेवा केन्द्र' मा जानु पर्छ। |
पासपोर्ट बनाउनको लागि सरकारी सरकारी निकायको सट्टा निजी फोटो स्टुडियोमा भेट्नुपर्छ। |
Online certificate renewal ko regards ma ke samasya aaunchha? |
Online portal ma certificate renewal ko lagi 'verification failed' error aaune bhaye, sabai bhanda pahile ta aapno mobile number ra email address check garnuhos. Yadi tyahi thik chha bhane, government helpline ma contact garera support ma sodhna parchha. |
Certificate renewal ko lagi lagi naya application form bharnu paryo bhane tapai le online process ma aaphai nai try garnu hos. |
Certificate ko renewal ko time frame 30 din ho, tesaile jaldikai garera pani samasya aune chhaina. |
Yo process lai government office ma personal javera bharnu parne ho, online ma dinu chhaina. |
main.CachedGISTEmbedLoss with these parameters:{
"guide": "SentenceTransformer('intfloat/multilingual-e5-small')",
"temperature": 0.01,
"mini_batch_size": 16,
"margin_strategy": "relative",
"margin": 0.05,
"contrast_anchors": true,
"contrast_positives": false,
"gather_across_devices": false
}
anchor and positive| anchor | positive | |
|---|---|---|
| type | string | string |
| modality | text | text |
| details |
|
|
| anchor | positive |
|---|---|
निश्चयले जिते कार्ल्सबर्ग गल्फ |
कार्ल्सबर्ग गल्फ सिरिज २०१९ मा मेजर निश्चय रायमाझी कुल २ सय ७५ अंक बटुल्दै नेट च्याम्पियन भएका छन् । विजेता भएवापत् उनले नोभेम्बर पहिलो साता मलेसियामा हुने गल्फ प्रतियोगितामा भाग लिने छन् । टासी छिरिङ २ सय १० अंक प्राप्त गर्दै ग्रस विजेता बनेका छन् । |
A leader with a leader |
नेतासँगै नेता |
रौतहट प्रहरीले कुटपिटको घटनामा जाहेरी लिन मानेन, मिलापत्र गर्न पीडित पक्षलाई दबाब |
Rautahat police refused to take a complaint in the case of assault, pressure on the victim to settle |
main.CachedGISTEmbedLoss with these parameters:{
"guide": "SentenceTransformer('intfloat/multilingual-e5-small')",
"temperature": 0.01,
"mini_batch_size": 16,
"margin_strategy": "relative",
"margin": 0.05,
"contrast_anchors": true,
"contrast_positives": false,
"gather_across_devices": false
}
per_device_train_batch_size: 128num_train_epochs: 2.0learning_rate: 5e-06warmup_steps: 0.1bf16: Truetorch_compile: Truetorch_compile_backend: inductorper_device_eval_batch_size: 16load_best_model_at_end: Truedata_seed: 42dataloader_num_workers: 8dataloader_persistent_workers: Truedataloader_prefetch_factor: 4prompts: {'anchor': 'query: ', 'positive': 'passage: ', 'negative_1': 'passage: ', 'negative_2': 'passage: ', 'negative_3': 'passage: '}batch_sampler: no_duplicatesper_device_train_batch_size: 128num_train_epochs: 2.0max_steps: -1learning_rate: 5e-06lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 0.1optim: adamw_torch_fusedoptim_args: Noneweight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08optim_target_modules: Nonegradient_accumulation_steps: 1average_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: Truetorch_compile_backend: inductortorch_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: Nonetrackio_bucket_id: Nonetrackio_static_space_id: Noneper_device_eval_batch_size: 16prediction_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: 42use_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: 8dataloader_pin_memory: Truedataloader_persistent_workers: Truedataloader_prefetch_factor: 4remove_unused_columns: Truelabel_names: Nonetrain_sampling_strategy: randomlength_column_name: lengthddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falseddp_static_graph: Noneddp_backend: Noneddp_timeout: 1800fsdp: Nonefsdp_config: Nonedeepspeed: Nonedebug: []skip_memory_metrics: Truedo_predict: Falseresume_from_checkpoint: Nonewarmup_ratio: Nonelocal_rank: -1prompts: {'anchor': 'query: ', 'positive': 'passage: ', 'negative_1': 'passage: ', 'negative_2': 'passage: ', 'negative_3': 'passage: '}batch_sampler: no_duplicatesmulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | hard_negative_cosine_ndcg@10 | indic_rag_cosine_ndcg@10 | balanced_news_cosine_ndcg@10 | en_ne_alignment_cosine_ndcg@10 |
|---|---|---|---|---|---|---|
| 0.0502 | 31 | 3.2558 | - | - | - | - |
| 0.1003 | 62 | 1.5447 | 0.3483 | 0.6433 | 0.6051 | 0.3638 |
| 0.1505 | 93 | 0.8522 | - | - | - | - |
| 0.2006 | 124 | 0.6679 | 0.3726 | 0.6900 | 0.6713 | 0.4115 |
| 0.2508 | 155 | 0.6209 | - | - | - | - |
| 0.3010 | 186 | 0.5758 | 0.3844 | 0.7045 | 0.6988 | 0.4335 |
| 0.3511 | 217 | 0.5351 | - | - | - | - |
| 0.4013 | 248 | 0.5234 | 0.3887 | 0.7111 | 0.7144 | 0.4434 |
| 0.4515 | 279 | 0.4474 | - | - | - | - |
| 0.5016 | 310 | 0.4444 | 0.3907 | 0.7193 | 0.7287 | 0.4507 |
| 0.5518 | 341 | 0.4595 | - | - | - | - |
| 0.6019 | 372 | 0.4143 | 0.3923 | 0.7261 | 0.7371 | 0.4561 |
| 0.6521 | 403 | 0.3946 | - | - | - | - |
| 0.7023 | 434 | 0.4026 | 0.3909 | 0.7302 | 0.7440 | 0.4620 |
| 0.7524 | 465 | 0.3900 | - | - | - | - |
| 0.8026 | 496 | 0.3825 | 0.3916 | 0.7314 | 0.7473 | 0.4637 |
| 0.8528 | 527 | 0.3980 | - | - | - | - |
| 0.9029 | 558 | 0.3711 | 0.3928 | 0.7326 | 0.7508 | 0.4661 |
| 0.9531 | 589 | 0.3678 | - | - | - | - |
| 1.0 | 618 | - | 0.3930 | 0.7329 | 0.7525 | 0.4670 |
| 0.1032 | 13 | 0.7110 | - | - | - | - |
| 0.2063 | 26 | 0.6710 | 0.4261 | 0.7335 | 0.7489 | 0.4706 |
| 0.3095 | 39 | 0.6519 | - | - | - | - |
| 0.4127 | 52 | 0.5455 | 0.4754 | 0.7301 | 0.7487 | 0.4780 |
| 0.5159 | 65 | 0.4912 | - | - | - | - |
| 0.6190 | 78 | 0.5774 | 0.5007 | 0.7320 | 0.7448 | 0.4830 |
| 0.7222 | 91 | 0.5217 | - | - | - | - |
| 0.8254 | 104 | 0.5394 | 0.5272 | 0.7314 | 0.7432 | 0.4838 |
| 0.9286 | 117 | 0.4898 | - | - | - | - |
| 1.0317 | 130 | 0.4209 | 0.5419 | 0.7305 | 0.7420 | 0.4845 |
| 1.1349 | 143 | 0.4120 | - | - | - | - |
| 1.2381 | 156 | 0.4448 | 0.5556 | 0.7306 | 0.7412 | 0.4849 |
| 1.3413 | 169 | 0.3246 | - | - | - | - |
| 1.4444 | 182 | 0.3570 | 0.5603 | 0.7313 | 0.7420 | 0.4865 |
| 1.5476 | 195 | 0.4110 | - | - | - | - |
| 1.6508 | 208 | 0.2963 | 0.5626 | 0.7321 | 0.7451 | 0.4881 |
| 1.7540 | 221 | 0.3628 | - | - | - | - |
| 1.8571 | 234 | 0.3137 | 0.5639 | 0.7320 | 0.7440 | 0.4885 |
| 1.9603 | 247 | 0.3308 | - | - | - | - |
| 2.0 | 252 | - | 0.564 | 0.7324 | 0.744 | 0.489 |
@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
jangedoo/sanolm-base-v2