Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 17
How to use vivekkopthsd/hinglish-st-33m with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("vivekkopthsd/hinglish-st-33m")
sentences = [
"query: nirasan aur bachat ke niyam kyaa hain?",
"passage: Section 536: Repeal and savings\n\nindividual, who\n\nis a resident out-\n\nside India as de -\n\nfined in section\n\n2(w) of the For -\n\neign Exchange\n\nManagement\n\nAct, 1999 (42 of\n\n1999); or\n\n( b) a person being\n\nan individual\n\nwho has been\n\npermitted by the\n\nSuch interest is on moneys\n\nstanding to the credit of\n\nsuch person in a Non-Res-\n\nident (External) Account in\n\nany bank in India as per the\n\nsaid Act and the rules made\n\nthereunder.\n\nSl.\n\nNo.\n\nIncome not to be\n\nincluded in total\n\nincome\n\nEligible persons Conditions\n\nA B C D\n\nReserve Bank of\n\nIndia to maintain\n\nthe said account.\n\n2. Any remuneration\n\nreceived for service\n\nin the capacity as an\n\nofficial mentioned in\n\ncolumn C, not being a\n\ncitizen of India.\n\nAn official, by whatev-\n\ner name called, of an\n\nembassy, high commis-\n\nsion, legation, commis-\n\nsion, consulate or the\n\ntrade representation of\n\na foreign State, or as a\n\nmember of the staff of\n\nany of these officials.\n\n( a) The remuneration re-\n\nceived as a trade com-\n\nmissioner or other\n\nofficial representative\n\nin India of the gov -\n\nernment of a foreign\n\nState (not holding\n\noffice as such in an\n\nhonorary capacity),\n\nor as members of the\n\nstaff, if any, of the\n\ngovernment, resident\n\nfor similar purposes\n\nin the country con -\n\ncerned enjoy a similar\n\nexemption in that\n\ncountry; and\n\n( b) the members of the\n\nstaff are subjects of\n\nthe country repre -\n\nsented and are not\n\nengaged in any busi -\n\nness or profession or\n\nemployment in India\n\notherwise than as\n\nmembers of such staff.\n\n3. Any remuneration re-\n\nceived as an employee\n\nfor services rendered\n\nby him during his stay\n\nin India.\n\nA person who is an\n\nemployee of a foreign\n\nenterprise, not being a\n\ncitizen of India.\n\n( a) The foreign enterprise\n\nis not engaged in any\n\ntrade or business in\n\nIndia;\n\n( b) his stay in India does\n\nnot exceed in the",
"passage: Section 136: Deduction in respect of contributions given by companies to political parties\n\n136. (1) An assessee, being an Indian company, shall be allowed a deduction for \n the amount contributed by it, other than by way of cash, during a tax year to \na political party registered under section 29A of the Representation of the People \nAct, 1951 (43 of 1951) or an electoral trust.\n(2) For the purposes of this section, the term “contribute”, with its grammatical \nvariations and cognate expressions shall have the same meaning as assigned to it \nin section 182 of the Companies Act, 2013 (18 of 2013).\nDeduction in respect of contributions given by any person to political parties.",
"passage: Section 232: Certain conditions for applicability of tonnage tax scheme\n\nissued by the Director-General of Shipping or the Inland Waterways Authority of India,\n\nas the case may be, and notified by the Central Government.\n\n(13) The tonnage tax company shall be required to furnish a copy of the certificate\n\nissued by the Director-General of Shipping, or the designated authority, as appointed\n\nby the respective State Governments under the Inland Vessels Act, 2021 (24 of 2021),\n\nas the case may be, along with the return of income under section 263 to the effect\n\nthat such company has complied with the minimum training requirement as per the\n\nguidelines referred to in sub-section (12) for the tax year.]\n\n(14) If the minimum training requirement is not complied with for any five con -\n\nsecutive tax years, the option of the company for tonnage tax scheme shall cease\n\nto have effect from the beginning of the tax year following the fifth consecutive tax\n\nyear in which the failure to comply with the minimum training requirement as per\n\nsub-section (12) had occurred.\n\n(15) In the case of every company which has opted for tonnage tax scheme, not\n\nmore than 49% of the net tonnage of the qualifying ships operated by it during any\n\ntax year shall be chartered in.\n\n40. Sub-sections (12) and (13) substituted by the Finance Act, 2026, w.e.f. 1-4-2026. Prior to\n\ntheir substitution, sub-sections (12) and (13) read as under :\n\n“(12) A tonnage tax company, after its option has been approved under section 231(4), shall\n\ncomply with the minimum training requirement in respect of trainee officers as per the\n\nguidelines issued by the Director-General of Shipping and notified by the Central Government.\n\n(13) The tonnage tax company shall be required to furnish a copy of the certificate issued"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model trained. It maps sentences & paragraphs to a 384-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, classification, clustering, and more.
SentenceTransformer(
(0): Transformer({'transformer_task': 'feature-extraction', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'last_hidden_state'}}, 'module_output_name': 'token_embeddings', 'architecture': 'BertModel'})
(1): Pooling({'embedding_dimension': 384, 'pooling_mode': 'mean', '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 = [
'query: aayakar praadhikaran dvaaraa apiil karane ke lie kaun sii kar chhuut upalabdh hai?',
'passage: धारा 373: आयकर प्राधिकरण द्वारा अपील दाखिल करना 373. (1) बोर्ड इस अध्याय के प्रावधानों के तहत किसी आयकर प्राधिकरण द्वारा अपील दाखिल करने के उद्देश्य से, इस अध्याय के प्रावधानों के तहत किसी भी आयकर प्राधिकरण द्वारा अपील दाखिल करने को विनियमित करने के उद्देश्य से, समय-समय पर अन्य आयकर प्राधिकरणों को आदेश, निर्देश या निर्देश जारी कर सकता है, यह ऐसे मौद्रिक सीमाओं को निर्धारित करने से नहीं रोक सकता है, जो वह किसी भी आयकर वर्ष के लिए किसी भी आयकर प्राधिकरण के मामले में किसी भी मुद्दे पर अपील नहीं कर सकता है। (2) जहां उप-धारा (1) के तहत जारी आदेशों, निर्देशों या निर्देशों का पालन करते हुए आयकर प्राधिकरण ने किसी भी मामले में किसी भी मुद्दे पर अपील नहीं दायर की है, तो यह इस तरह के किसी भी प्राधिकरण को किसी अन्य आयकर वर्ष के लिए किसी भी मामले में याचिका दायर करने से नहीं रोक सकता है। (3) जहां उप-धारा (1) के तहत किसी आयकर प्राधिकरण द्वारा या निर्देशों के तहत किसी भी मामले में याचिका दायर नहीं की गई है, और जहां किसी भी मामले में अपील करने वाले पक्ष द्वारा या याचिका दायर नहीं की गई है, उस मामले में अदालत द्वारा किसी भी याचिका दायर नहीं की जाएगी। (1)',
'passage: Section 367: Appeal to Supreme Court\n\n367. An appeal shall lie to the Supreme Court from any judgment of the High \n Court delivered on an appeal made to High Court in respect of an order \npassed under section 363 in any case which the High Court certifies to be fit for \nappeal to the Supreme Court.\nHearing before Supreme Court.',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 384]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[1.0000, 0.2213, 0.1421],
# [0.2213, 1.0000, 0.3914],
# [0.1421, 0.3914, 1.0000]])
anchor, positive, and negative| anchor | positive | negative | |
|---|---|---|---|
| type | string | string | string |
| modality | text | text | text |
| details |
|
|
|
| anchor | positive | negative |
|---|---|---|
query: तलाशी और जब्त के लिए किस प्रकार की कर छूट उपलब्ध है? |
passage: Section 247: Search and seizure |
passage: धारा 296: धारा 63[(1) धारा 286 के प्रावधानों के बावजूद, धारा 294 के तहत आदेश उस तिमाही के अंत से अठारह महीने के भीतर पारित किया जाएगा जिसमें तलाशी शुरू की गई थी या तलाशी ली गई थी.] (2) जहां तलाशी शुरू की गई थी या तलाशी ली गई थी, और संबंधित खंड अवधि की कुल अज्ञात आय के आकलन या पुनर्मूल्यांकन के दौरान धारा 166 (1) के तहत कोई संदर्भ दिया गया है, ऐसे मूल्यांकन या पुनर्मूल्यांकन प्रक्रिया को पूरा करने के लिए उपलब्ध अवधि को बारह महीने तक बढ़ाया जाएगा। (3) उपधारा (1) के तहत समय सीमा की गणना में, उस समय अवधि (एक सौ और अस्सी दिनों से अधिक नहीं) जो उस तारीख से शुरू होती है जिस दिन ऐसी तलाशी शुरू की गई है या एक पुनर्मूल्यांकन किया गया है और जहां धारा 166 (1) के तहत प्रदान की गई अवधि की समाप्ति के दौरान धनराशि का पुनर्मूल्यांकन किया गया है, और जब धारा 261 के अंत के अंत के लिए ऐसी अवधि समाप्त हो जाती है, तो ऐसे अनुच्छेद (2) के तहत किसी अन्य व्यक्ति द्वारा इस तरह के मूल्यांकन की अवधि के अंत तक या पुनर्मूल्यांकन की अवधि के लिए संदर्भित किया जाएगा, यदि धारा 29 (5) के अंत तक किसी अन्य व्यक्ति ... |
query: aay kii kam riporting aur galat riporting ke lie jurmaanaa ke lie kaun sii kar chhuut upalabdh hai? |
passage: Section 439: Penalty for under-reporting and misreporting of income |
passage: Section 367: Appeal to Supreme Court |
query: कार्यवाही को अमान्य नहीं करने के लिए अधिनियम में किस धारा के तहत रिक्त पद आदि को कवर किया गया है? |
passage: धारा 382: रिक्तियां, आदि, कार्यवाही को अमान्य नहीं करने के लिए 382. अग्रिम निर्णय बोर्ड द्वारा कोई कार्यवाही या अग्रिम निर्णय की घोषणा, केवल बोर्ड के गठन में किसी भी रिक्त स्थान या दोष की उपस्थिति के आधार पर प्रश्न या अमान्य होगी। अग्रिम निर्णय के लिए आवेदन। |
passage: धारा 381: अग्रिम निर्णयों के लिए बोर्ड 381. (1) केंद्र सरकार इस अध्याय के तहत अग्रिम निर्णय देने के लिए एक या अधिक बोर्डों का गठन करेगी, जैसा कि आवश्यक हो, उस तिथि पर या उसके बाद, जिसे केंद्र सरकार अधिसूचना द्वारा नियुक्त कर सकती है। (2) अग्रिम निर्णयों के लिए बोर्ड में दो सदस्य होंगे, प्रत्येक एक अधिकारी मुख्य आयुक्त के पद से कम नहीं होगा, जैसा कि बोर्ड द्वारा नामित किया जा सकता है। रिक्तियां आदि, कार्यवाही को अमान्य नहीं करने के लिए। |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim",
"gather_across_devices": false,
"directions": [
"query_to_doc"
],
"partition_mode": "joint",
"hardness_mode": null,
"hardness_strength": 0.0
}
per_device_train_batch_size: 96learning_rate: 2e-05num_train_epochs: 1lr_scheduler_type: cosinewarmup_ratio: 0.1seed: 45dataloader_num_workers: 4overwrite_output_dir: Falsedo_predict: Falseprediction_loss_only: Trueper_device_train_batch_size: 96per_device_eval_batch_size: 8per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 1eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 2e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 1max_steps: -1lr_scheduler_type: cosinelr_scheduler_kwargs: Nonewarmup_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: 45data_seed: Nonejit_mode_eval: 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: 4dataloader_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: lengthproject: huggingfacetrackio_space_id: trackioddp_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: noneftune_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: Trueprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss |
|---|---|---|
| 0.2381 | 10 | 2.4989 |
| 0.4762 | 20 | 2.3856 |
| 0.7143 | 30 | 2.3208 |
| 0.9524 | 40 | 2.343 |
@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{oord2019representationlearningcontrastivepredictive,
title={Representation Learning with Contrastive Predictive Coding},
author={Aaron van den Oord and Yazhe Li and Oriol Vinyals},
year={2019},
eprint={1807.03748},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/1807.03748},
}