Scaling Deep Contrastive Learning Batch Size under Memory Limited Setup
Paper • 2101.06983 • Published • 3
How to use shawnriju/bge-small-construction-rag with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("shawnriju/bge-small-construction-rag")
sentences = [
"Represent this sentence for searching relevant passages: Could you clarify the new description of the topographic influence's reach in the amendment?",
"Ssangyong v NHAI (SC 2019) > Judgment (R.F. Nariman, J.) > ¶ 38 - The Ground of Challenge under Section 34(2)(a)(iii)\nIn Minmetals Germany GmbH v. Ferco Steel Ltd., [1999] CLC 647, the Queen's Bench Division referred to this ground under the New York Convention, and held as follows:\n\"The inability to present a case issue\nAlthough many of those states who are parties to\nthe New York Convention are civil law jurisdictions or are those which like China derive the whole or part of their procedural rules from the civil law and therefore have essentially an inquisitorial system, art. V of the Convention protects the requirements of natural justice reflected in the audi alteram partem rule. Therefore, where the tribunal is procedurally entitled to conduct its own investigations into the facts, the effect of this provision will be to avoid enforcement of an award based on findings of fact derived from such investigations if the enforcee has not been given any reasonable opportunity to present its case in relation to the results of such investigations. Article 26 of the CIETAC rules by reference to which the parties had agreed to arbitrate provided:\n'Article 26 - The parties shall give evidence for the facts on which their claim or defence is based. The arbitration tribunal may, if it deems it necessary, make investigations and collect evidence on its own initiative.' That, however, was not treated by the Beijing court\nas permitting the tribunal to reach its conclusions and make an award without first disclosing to both parties the materials which it had derived from its own\ninvestigations. That quite distinctly appears from the grounds of the court's decision - that Ferco was, for reasons for which it was not responsible, unable 'to state its view'. Those reasons could only have been its lack of prior access to the sub-sale award and the evidence which underlay it. I conclude that it was to give Ferco's lawyer an opportunity to refute this material that the Beijing court ordered a 'resumed' arbitration.\"\n(at pp. 656-657)",
"IS 875 (Part 3):1987 > Amendments > Amendment No. 2, item 15 - Amendment No. 2 (March 2002) - amends Cl. C-1\nAmendment No. 2 (March 2002) to IS 875 (Part 3):1987. (Page 55, clause C-1, second line) - Substitute 'and' for 'add'. [Curator's explanation: the topographic influence extends 1.5 Le upwind and 2.5 Le downwind of the crest]",
"CPWD GCC 2020 > Integrity Pact > Integrity Pact\nI/We acknowledge that in the event of my/our failure to sign and accept the Integrity Agreement, while submitting the tender/bid, CPWD shall have unqualified, absolute and unfettered right to disqualify the tenderer/bidder and reject the tender/bid is accordance with terms and conditions of the tender/ bid.\nYours faithfully\n(Duly authorized signatory of the Bidder)"
]
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, text classification, clustering, and more.
SentenceTransformer(
(0): Transformer({'max_seq_length': 512, 'do_lower_case': True}) with Transformer model: BertModel
(1): Pooling({'word_embedding_dimension': 384, '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): 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 = [
'Represent this sentence for searching relevant passages: How does the friction coefficient change under tangential action, and what is the friction coefficient for 90-degree angles?',
'IS 875 (Part 3):1987 > Tables > Table 9\n( &uw 6.2.2.4 )\n-T i 1 T\nI 1 E 1\nL; G z I__ ---- _____: J I c\n--\n7\n9\n, ----I 1 1 End Surfaces\nD 1 D\nE ) E\' j c j c\' / c; I / j I - -05 / -0.3 1 ! -0\'6 / i I -0.3 / 1 -0.3 1 -0.4 I -0*3 / 0.8 / : I 0\'3\nI I I 0\'6 ! -1\'0\n-I\n0\n0.1 ; -0.3\n45O\n-0\'3 j -C\'4\nj_ I I I-\n9o"\nI\n_-A-\nForj : Cp top = -i\'O; Cp bottom = -0.2\n45"\nTangentially acting friction: ROOo ip 0\'05 pdbd\n90"\nRoof sIope a 0 30\' e - 0\' - 450, D, D\', E, E\' :x1: length 9 = 90", D, D\', E, E\' prr !engzh b\', thereafter Cp = 0\ni\n-7\n.j_ G\'\nI',
'IS 875 (Part 3):1987 > Tables > Table 11\n( Clause 6.2.2.4)\nb=Sd\nPRESSURE COEFFICIENTS, CD\ne End Surfaces\nD D\' E E\'\n-- -~.\n00 -1.0 03 -0.5 0.2 ,\n45" -0\'3 0.1 -0\'3 0\'1\n90" -0.3 0 -0.3 0 -0\'4 0.8 09 -0.6 -\n0" Forf: Cp top = -11\'0; Cp bottom = 0\'4\n0" - 90° Tangentially acting friction, RIO\' = O"1 pdbd\nf b\'=d\n1\nRoof slope (L = IO" 8 = 0" - 45", D, D\', E, E\' full length 0 = 90°, D, D\', E, E\' par1 length b\', thereafter Cp = 0\nc I C G 1 G\nTABU I2 PRESSURE COEFFICIFiNTS (*OP AND BOTTOM ) FOR PITCRBD FBE ROOFS ir - 10" WITH EFFECTS OF TRAIN OR STORED MATJZItIAL8\nG i\n! 1 I /\n1 -0\'4 0.8 0\'3\n! I\ni I\nI\n0" \' ForJ: I;, top = -15; Cp bottom = 0.9\n0" - I!$" / Tangentially acting friction: R,o" .= 0.1 p&j\ni\n( CIaw 6.2.2.4 )\n-T h\'=O$t h _A_\ni i\n!\nRoof slope m - IO0 EAacts of trains or stored materials: e-o.=- 45\',or 135\' - 180°, D, D\', E, E\' full length 0 = 90*, D, D\', E, E\' part length b\', thereafter CD = 0\nG\'\n-0%',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 384]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [3, 3]
valInformationRetrievalEvaluator| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.6912 |
| cosine_accuracy@3 | 0.8971 |
| cosine_accuracy@5 | 0.9265 |
| cosine_accuracy@10 | 0.9412 |
| cosine_precision@1 | 0.6912 |
| cosine_precision@3 | 0.299 |
| cosine_precision@5 | 0.1853 |
| cosine_precision@10 | 0.0941 |
| cosine_recall@1 | 0.6912 |
| cosine_recall@3 | 0.8971 |
| cosine_recall@5 | 0.9265 |
| cosine_recall@10 | 0.9412 |
| cosine_ndcg@10 | 0.8279 |
| cosine_mrr@10 | 0.7901 |
| cosine_map@100 | 0.7924 |
| dot_accuracy@1 | 0.6912 |
| dot_accuracy@3 | 0.8971 |
| dot_accuracy@5 | 0.9265 |
| dot_accuracy@10 | 0.9412 |
| dot_precision@1 | 0.6912 |
| dot_precision@3 | 0.299 |
| dot_precision@5 | 0.1853 |
| dot_precision@10 | 0.0941 |
| dot_recall@1 | 0.6912 |
| dot_recall@3 | 0.8971 |
| dot_recall@5 | 0.9265 |
| dot_recall@10 | 0.9412 |
| dot_ndcg@10 | 0.8279 |
| dot_mrr@10 | 0.7901 |
| dot_map@100 | 0.7924 |
anchor, positive, and negative| anchor | positive | negative | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| anchor | positive | negative |
|---|---|---|
Represent this sentence for searching relevant passages: Is ignoring a superior court's judgment on interest recovery considered a breach of Indian law's fundamental principles? |
Ssangyong v NHAI (SC 2019) > Judgment (R.F. Nariman, J.) > ¶ 13 (part 2/2) - Changes made by the Amendment Act, 2015 |
Ssangyong v NHAI (SC 2019) > Judgment (R.F. Nariman, J.) > ¶ 17 (part 1/7) - Changes made by the Amendment Act, 2015 |
Represent this sentence for searching relevant passages: What are the procedures for submitting a corrected measurement book if errors are found in the initial one? |
CPWD GCC 2020 > Clauses of Contract > Clause 6 - Computerized Measurement Book |
Ssangyong v NHAI (SC 2019) > Judgment (R.F. Nariman, J.) > ¶ 17 (part 6/7) - Changes made by the Amendment Act, 2015 |
Represent this sentence for searching relevant passages: What instruments are recommended for tall structures to measure wind data and how can this data be utilized? |
IS 875 (Part 3):1987 > Foreword > Cl. 0.3.3-0.4 |
IS 875 (Part 3):1987 > 7. Dynamic Effects > Cl. 7-7.1 (part 1/4) - DYNAMIC EFFECTS |
CachedMultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim"
}
eval_strategy: epochper_device_train_batch_size: 32learning_rate: 2e-05warmup_ratio: 0.1data_seed: 42load_best_model_at_end: Truebatch_sampler: no_duplicatesoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: epochprediction_loss_only: Trueper_device_train_batch_size: 32per_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: 3max_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: 42jit_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: Trueignore_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: Falsehub_always_push: Falsegradient_checkpointing: Falsegradient_checkpointing_kwargs: Noneinclude_inputs_for_metrics: Falseeval_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: Falsebatch_sampler: no_duplicatesmulti_dataset_batch_sampler: proportional| Epoch | Step | Training Loss | val_cosine_map@100 |
|---|---|---|---|
| 0 | 0 | - | 0.7059 |
| 0.25 | 5 | 1.67 | - |
| 0.5 | 10 | 1.321 | - |
| 0.75 | 15 | 1.0658 | - |
| 1.0 | 20 | 0.7881 | - |
| 1.05 | 21 | - | 0.7916 |
| 1.2 | 25 | 0.8238 | - |
| 1.45 | 30 | 0.7223 | - |
| 1.7 | 35 | 0.7229 | - |
| 1.95 | 40 | 0.6751 | - |
| 2.05 | 42 | - | 0.7912 |
| 2.15 | 45 | 0.4682 | - |
| 2.4 | 50 | 0.5694 | - |
| 2.65 | 55 | 0.6663 | - |
| 2.9 | 60 | 0.6347 | 0.7924 |
@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{gao2021scaling,
title={Scaling Deep Contrastive Learning Batch Size under Memory Limited Setup},
author={Luyu Gao and Yunyi Zhang and Jiawei Han and Jamie Callan},
year={2021},
eprint={2101.06983},
archivePrefix={arXiv},
primaryClass={cs.LG}
}