Scaling Deep Contrastive Learning Batch Size under Memory Limited Setup
Paper • 2101.06983 • Published • 2
How to use mjaliz/bslm-pair-combined-safe with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("mjaliz/bslm-pair-combined-safe")
sentences = [
"بازی ایروپولی",
"ساعت مچی زنانه رَستا (Rasta) نقره 925 با روکش طلا سفید و قاب مستطیلی نگینکاری شده",
"زعفران صادراتی افضل 1.5 گرمی نشان استاندارد",
"بازی فکری مونوپولی PayDay (پی دی) خانوادگی مدیریت پول 2-4 بازیکن"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from mjaliz/bslm-pair-206k on the json dataset. It maps sentences & paragraphs to a 1024-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': 'XLMRobertaModel'})
(1): Pooling({'embedding_dimension': 1024, '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
queries = [
'شومیز و شلوار عروسکی زنانه',
]
documents = [
'ست شومیز شلوار زنانه ایوا مدل عروسکی قهوه\u200cای',
'سرویس غذاخوری 27 پارچه چینی زرین قالب کواترو طرح ادلین طوسی',
'روسری مجلسی ژان ژان ترک شاین با حاشیه نگین\u200cکاری قواره ۱۲۰ سانتی\u200cمتر',
]
query_embeddings = model.encode_query(queries)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings.shape)
# [1, 1024] [3, 1024]
# Get the similarity scores for the embeddings
similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities)
# tensor([[ 0.8277, -0.0022, -0.0189]])
devInformationRetrievalEvaluator| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.7932 |
| cosine_accuracy@5 | 0.9386 |
| cosine_accuracy@10 | 0.9634 |
| cosine_accuracy@50 | 0.9883 |
| cosine_precision@1 | 0.7932 |
| cosine_precision@5 | 0.2715 |
| cosine_precision@10 | 0.1584 |
| cosine_precision@50 | 0.0411 |
| cosine_recall@1 | 0.6622 |
| cosine_recall@5 | 0.8925 |
| cosine_recall@10 | 0.9373 |
| cosine_recall@50 | 0.9821 |
| cosine_ndcg@10 | 0.8712 |
| cosine_mrr@10 | 0.8558 |
| cosine_map@10 | 0.8377 |
anchor and positive| anchor | positive | |
|---|---|---|
| type | string | string |
| modality | text | text |
| details |
|
|
| anchor | positive |
|---|---|
مانتو تابستانه سایزبزرگ |
مانتو زنانه بلند کتان لمه مهتابان (Mahtaban) مدل قیطوندوزی شده سایزبزرگ |
شال توری بهاره |
شال رینگی زنانه بافت توری مشکی ریزش ملایم بهاره تابستانه |
کاور صندلی خودرو |
روکش صندلی خودرو ماتین کاور طرح لاماری جودون برای پراید 111 هاچبک رنگ عسلی |
CachedMultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim",
"mini_batch_size": 32,
"gather_across_devices": true,
"directions": [
"query_to_doc"
],
"partition_mode": "joint",
"hardness_mode": null,
"hardness_strength": 0.0
}
anchor and positive| anchor | positive | |
|---|---|---|
| type | string | string |
| modality | text | text |
| details |
|
|
| anchor | positive |
|---|---|
رژگونه توت فرنگی |
بالم لب توت فرنگی Anakan (آناکان) آبرسان ویتامینه گیاهی |
چای ساز کوخ |
چای ساز برقی Kouch (کوخ) مدل KT-2150 مشکی، 2200 وات، کتری استیل دوجداره |
میز کنسول |
میز کنسول FARASHAHGROUP با درب طرح چوب و قفسه بندی باز |
CachedMultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim",
"mini_batch_size": 32,
"gather_across_devices": true,
"directions": [
"query_to_doc"
],
"partition_mode": "joint",
"hardness_mode": null,
"hardness_strength": 0.0
}
per_device_train_batch_size: 256num_train_epochs: 5.0learning_rate: 2e-05warmup_steps: 0.1weight_decay: 0.01bf16: Truegradient_checkpointing: Trueper_device_eval_batch_size: 64dataloader_num_workers: 4batch_sampler: no_duplicatesper_device_train_batch_size: 256num_train_epochs: 5.0max_steps: -1learning_rate: 2e-05lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 0.1optim: adamw_torch_fusedoptim_args: Noneweight_decay: 0.01adam_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: Truegradient_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: Nonetrackio_bucket_id: Nonetrackio_static_space_id: Noneper_device_eval_batch_size: 64prediction_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: Falseignore_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: Truedataloader_num_workers: 4dataloader_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_static_graph: Noneddp_backend: Noneddp_timeout: 1800fsdp: Nonefsdp_config: Nonedeepspeed: Nonedebug: []skip_memory_metrics: Truedo_predict: Falseresume_from_checkpoint: Nonewarmup_ratio: Nonelocal_rank: -1prompts: Nonebatch_sampler: no_duplicatesmulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | Validation Loss | dev_cosine_ndcg@10 |
|---|---|---|---|---|
| 0.0257 | 100 | 1.5386 | - | - |
| 0.0513 | 200 | 1.2748 | - | - |
| 0.0770 | 300 | 1.1664 | - | - |
| 0.1027 | 400 | 1.1179 | - | - |
| 0.1284 | 500 | 1.0774 | 0.4263 | 0.8280 |
| 0.1540 | 600 | 1.0482 | - | - |
| 0.1797 | 700 | 1.0287 | - | - |
| 0.2054 | 800 | 0.9916 | - | - |
| 0.2311 | 900 | 0.9794 | - | - |
| 0.2567 | 1000 | 0.9707 | 0.3903 | 0.8408 |
| 0.2824 | 1100 | 0.9690 | - | - |
| 0.3081 | 1200 | 0.9540 | - | - |
| 0.3338 | 1300 | 0.9484 | - | - |
| 0.3594 | 1400 | 0.9298 | - | - |
| 0.3851 | 1500 | 0.9201 | 0.3788 | 0.8507 |
| 0.4108 | 1600 | 0.9160 | - | - |
| 0.4365 | 1700 | 0.9118 | - | - |
| 0.4621 | 1800 | 0.9137 | - | - |
| 0.4878 | 1900 | 0.8985 | - | - |
| 0.5135 | 2000 | 0.8995 | 0.3692 | 0.8506 |
| 0.5392 | 2100 | 0.9045 | - | - |
| 0.5648 | 2200 | 0.8824 | - | - |
| 0.5905 | 2300 | 0.8808 | - | - |
| 0.6162 | 2400 | 0.8804 | - | - |
| 0.6418 | 2500 | 0.8681 | 0.3605 | 0.8543 |
| 0.6675 | 2600 | 0.8748 | - | - |
| 0.6932 | 2700 | 0.8669 | - | - |
| 0.7189 | 2800 | 0.8633 | - | - |
| 0.7445 | 2900 | 0.8595 | - | - |
| 0.7702 | 3000 | 0.8555 | 0.3593 | 0.8589 |
| 0.7959 | 3100 | 0.8541 | - | - |
| 0.8216 | 3200 | 0.8445 | - | - |
| 0.8472 | 3300 | 0.8448 | - | - |
| 0.8729 | 3400 | 0.8438 | - | - |
| 0.8986 | 3500 | 0.8375 | 0.3616 | 0.8606 |
| 0.9243 | 3600 | 0.8392 | - | - |
| 0.9499 | 3700 | 0.8397 | - | - |
| 0.9756 | 3800 | 0.8311 | - | - |
| 1.0072 | 3900 | 0.8389 | - | - |
| 1.0329 | 4000 | 0.8259 | 0.3666 | 0.8634 |
| 1.0585 | 4100 | 0.8214 | - | - |
| 1.0842 | 4200 | 0.8278 | - | - |
| 1.1099 | 4300 | 0.8237 | - | - |
| 1.1356 | 4400 | 0.8246 | - | - |
| 1.1612 | 4500 | 0.8110 | 0.3707 | 0.8647 |
| 1.1869 | 4600 | 0.8107 | - | - |
| 1.2126 | 4700 | 0.7897 | - | - |
| 1.2383 | 4800 | 0.8023 | - | - |
| 1.2639 | 4900 | 0.7967 | - | - |
| 1.2896 | 5000 | 0.8017 | 0.3566 | 0.8657 |
| 1.3153 | 5100 | 0.7930 | - | - |
| 1.3409 | 5200 | 0.7983 | - | - |
| 1.3666 | 5300 | 0.7898 | - | - |
| 1.3923 | 5400 | 0.7811 | - | - |
| 1.4180 | 5500 | 0.7804 | 0.3653 | 0.8656 |
| 1.4436 | 5600 | 0.7856 | - | - |
| 1.4693 | 5700 | 0.7796 | - | - |
| 1.4950 | 5800 | 0.7728 | - | - |
| 1.5207 | 5900 | 0.7783 | - | - |
| 1.5463 | 6000 | 0.7827 | 0.3749 | 0.8655 |
| 1.5720 | 6100 | 0.7598 | - | - |
| 1.5977 | 6200 | 0.7670 | - | - |
| 1.6234 | 6300 | 0.7707 | - | - |
| 1.6490 | 6400 | 0.7646 | - | - |
| 1.6747 | 6500 | 0.7644 | 0.3736 | 0.8686 |
| 1.7004 | 6600 | 0.7633 | - | - |
| 1.7261 | 6700 | 0.7571 | - | - |
| 1.7517 | 6800 | 0.7665 | - | - |
| 1.7774 | 6900 | 0.7646 | - | - |
| 1.8031 | 7000 | 0.7566 | 0.3612 | 0.8673 |
| 1.8288 | 7100 | 0.7545 | - | - |
| 1.8544 | 7200 | 0.7563 | - | - |
| 1.8801 | 7300 | 0.7535 | - | - |
| 1.9058 | 7400 | 0.7576 | - | - |
| 1.9315 | 7500 | 0.7536 | 0.3724 | 0.8690 |
| 1.9571 | 7600 | 0.7502 | - | - |
| 1.9828 | 7700 | 0.7497 | - | - |
| 2.0144 | 7800 | 0.7588 | - | - |
| 2.0401 | 7900 | 0.7414 | - | - |
| 2.0657 | 8000 | 0.7442 | 0.3745 | 0.8688 |
| 2.0914 | 8100 | 0.7562 | - | - |
| 2.1171 | 8200 | 0.7512 | - | - |
| 2.1427 | 8300 | 0.7454 | - | - |
| 2.1684 | 8400 | 0.7419 | - | - |
| 2.1941 | 8500 | 0.7301 | 0.3740 | 0.8694 |
| 2.2198 | 8600 | 0.7290 | - | - |
| 2.2454 | 8700 | 0.7324 | - | - |
| 2.2711 | 8800 | 0.7319 | - | - |
| 2.2968 | 8900 | 0.7365 | - | - |
| 2.3225 | 9000 | 0.7291 | 0.3737 | 0.8693 |
| 2.3481 | 9100 | 0.7339 | - | - |
| 2.3738 | 9200 | 0.7251 | - | - |
| 2.3995 | 9300 | 0.7214 | - | - |
| 2.4252 | 9400 | 0.7207 | - | - |
| 2.4508 | 9500 | 0.7298 | 0.3670 | 0.8702 |
| 2.4765 | 9600 | 0.7257 | - | - |
| 2.5022 | 9700 | 0.7124 | - | - |
| 2.5279 | 9800 | 0.7313 | - | - |
| 2.5535 | 9900 | 0.7211 | - | - |
| 2.5792 | 10000 | 0.7107 | 0.3712 | 0.8710 |
| 2.6049 | 10100 | 0.7149 | - | - |
| 2.6306 | 10200 | 0.7209 | - | - |
| 2.6562 | 10300 | 0.7112 | - | - |
| 2.6819 | 10400 | 0.7192 | - | - |
| 2.7076 | 10500 | 0.7061 | 0.3628 | 0.8712 |
@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}
}
Base model
mjaliz/bslm-pair-206k