Scaling Deep Contrastive Learning Batch Size under Memory Limited Setup
Paper
• 2101.06983 • Published
• 2
This is a sentence-transformers model finetuned from BAAI/bge-m3. It maps sentences & paragraphs to a 1024-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': False}) with Transformer model: XLMRobertaModel
(1): Pooling({'word_embedding_dimension': 1024, '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("comet24082002/ft_bge_newLaw_CachedMultipleNegativeRankingLoss_V1_5epochs")
# Run inference
sentences = [
'Công ty có quyền giảm lương khi người lao động không đảm bảo hiệu suất công việc?',
'"Điều 94. Nguyên tắc trả lương\n1. Người sử dụng lao động phải trả lương trực tiếp, đầy đủ, đúng hạn cho người lao động. Trường hợp người lao động không thể nhận lương trực tiếp thì người sử dụng lao động có thể trả lương cho người được người lao động ủy quyền hợp pháp.\n2. Người sử dụng lao động không được hạn chế hoặc can thiệp vào quyền tự quyết chi tiêu lương của người lao động; không được ép buộc người lao động chi tiêu lương vào việc mua hàng hóa, sử dụng dịch vụ của người sử dụng lao động hoặc của đơn vị khác mà người sử dụng lao động chỉ định."',
'Các biện pháp tăng cường an toàn hoạt động bay\nCục Hàng không Việt Nam áp dụng các biện pháp tăng cường sau:\n1. Phổ biến kinh nghiệm, bài học liên quan trên thế giới và tại Việt Nam cho các tổ chức, cá nhân liên quan trực tiếp đến hoạt động bay bằng các hình thức thích hợp.\n2. Tổ chức thực hiện, giám sát kết quả thực hiện khuyến cáo an toàn của các cuộc điều tra tai nạn tàu bay, sự cố trong lĩnh vực hoạt động bay.\n3. Tổng kết, đánh giá và phân tích định kỳ hàng năm việc thực hiện quản lý an toàn hoạt động bay; tổ chức khắc phục các hạn chế, yêu cầu, đề nghị liên quan nhằm hoàn thiện công tác quản lý an toàn và SMS.\n4. Tổ chức huấn luyện, đào tạo về an toàn hoạt động bay.',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 1024]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [3, 3]
anchor and positive| anchor | positive | |
|---|---|---|
| type | string | string |
| details |
|
|
| anchor | positive |
|---|---|
Người thừa kế theo di chúc gồm những ai? |
"Điều 613. Người thừa kế |
Đầu tư vốn nhà nước vào doanh nghiệp được thực hiện bằng những hình thức nào? |
Hình thức đầu tư vốn nhà nước vào doanh nghiệp |
Thủ tục thành lập trung tâm hiến máu chữ thập đỏ có quy định như thế nào? |
Thủ tục thành lập cơ sở hiến máu chữ thập đỏ |
CachedMultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim"
}
per_device_train_batch_size: 256learning_rate: 2e-05num_train_epochs: 5warmup_ratio: 0.1overwrite_output_dir: Falsedo_predict: Falseprediction_loss_only: Trueper_device_train_batch_size: 256per_device_eval_batch_size: 8per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 1eval_accumulation_steps: Nonelearning_rate: 2e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 5max_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: 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}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: Falsefp16_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_sampler: batch_samplermulti_dataset_batch_sampler: proportional| Epoch | Step | Training Loss |
|---|---|---|
| 0.0476 | 2 | 1.1564 |
| 0.0952 | 4 | 0.9996 |
| 0.1429 | 6 | 1.0032 |
| 0.1905 | 8 | 0.77 |
| 0.2381 | 10 | 0.6496 |
| 0.2857 | 12 | 0.435 |
| 0.3333 | 14 | 0.4408 |
| 0.3810 | 16 | 0.467 |
| 0.4286 | 18 | 0.4484 |
| 0.4762 | 20 | 0.366 |
| 0.5238 | 22 | 0.3131 |
| 0.5714 | 24 | 0.3068 |
| 0.6190 | 26 | 0.3319 |
| 0.6667 | 28 | 0.2293 |
| 0.7143 | 30 | 0.3322 |
| 0.7619 | 32 | 0.2658 |
| 0.8095 | 34 | 0.2591 |
| 0.8571 | 36 | 0.3763 |
| 0.9048 | 38 | 0.2642 |
| 0.9524 | 40 | 0.2871 |
| 1.0 | 42 | 0.2005 |
| 1.0476 | 44 | 0.1757 |
| 1.0952 | 46 | 0.2309 |
| 1.1429 | 48 | 0.218 |
| 1.1905 | 50 | 0.2702 |
| 1.2381 | 52 | 0.2113 |
| 1.2857 | 54 | 0.184 |
| 1.3333 | 56 | 0.2414 |
| 1.3810 | 58 | 0.1692 |
| 1.4286 | 60 | 0.2015 |
| 1.4762 | 62 | 0.2303 |
| 1.5238 | 64 | 0.1829 |
| 1.5714 | 66 | 0.216 |
| 1.6190 | 68 | 0.182 |
| 1.6667 | 70 | 0.2362 |
| 1.7143 | 72 | 0.183 |
| 1.7619 | 74 | 0.239 |
| 1.8095 | 76 | 0.2207 |
| 1.8571 | 78 | 0.1848 |
| 1.9048 | 80 | 0.1828 |
| 1.9524 | 82 | 0.2324 |
| 2.0 | 84 | 0.1048 |
| 2.0476 | 86 | 0.1852 |
| 2.0952 | 88 | 0.1381 |
| 2.1429 | 90 | 0.1723 |
| 2.1905 | 92 | 0.1519 |
| 2.2381 | 94 | 0.1285 |
| 2.2857 | 96 | 0.1545 |
| 2.3333 | 98 | 0.1786 |
| 2.3810 | 100 | 0.1803 |
| 2.4286 | 102 | 0.1191 |
| 2.4762 | 104 | 0.1546 |
| 2.5238 | 106 | 0.1782 |
| 2.5714 | 108 | 0.1609 |
| 2.6190 | 110 | 0.1642 |
| 2.6667 | 112 | 0.1204 |
| 2.7143 | 114 | 0.173 |
| 2.7619 | 116 | 0.1332 |
| 2.8095 | 118 | 0.1567 |
| 2.8571 | 120 | 0.124 |
| 2.9048 | 122 | 0.1768 |
| 2.9524 | 124 | 0.1776 |
| 3.0 | 126 | 0.1091 |
| 3.0476 | 128 | 0.1621 |
| 3.0952 | 130 | 0.1231 |
| 3.1429 | 132 | 0.1117 |
| 3.1905 | 134 | 0.1328 |
| 3.2381 | 136 | 0.1201 |
| 3.2857 | 138 | 0.1052 |
| 3.3333 | 140 | 0.0967 |
| 3.3810 | 142 | 0.1397 |
| 3.4286 | 144 | 0.1051 |
| 3.4762 | 146 | 0.1412 |
| 3.5238 | 148 | 0.157 |
| 3.5714 | 150 | 0.1241 |
| 3.6190 | 152 | 0.1119 |
| 3.6667 | 154 | 0.1222 |
| 3.7143 | 156 | 0.1324 |
| 3.7619 | 158 | 0.1489 |
| 3.8095 | 160 | 0.1228 |
| 3.8571 | 162 | 0.1321 |
| 3.9048 | 164 | 0.1373 |
| 3.9524 | 166 | 0.1313 |
| 4.0 | 168 | 0.0746 |
| 4.0476 | 170 | 0.1188 |
| 4.0952 | 172 | 0.1443 |
| 4.1429 | 174 | 0.095 |
| 4.1905 | 176 | 0.1227 |
| 4.2381 | 178 | 0.1197 |
| 4.2857 | 180 | 0.1102 |
| 4.3333 | 182 | 0.133 |
| 4.3810 | 184 | 0.0993 |
| 4.4286 | 186 | 0.1354 |
| 4.4762 | 188 | 0.1143 |
| 4.5238 | 190 | 0.1326 |
| 4.5714 | 192 | 0.0927 |
| 4.6190 | 194 | 0.1085 |
| 4.6667 | 196 | 0.1181 |
| 4.7143 | 198 | 0.1131 |
| 4.7619 | 200 | 0.1136 |
| 4.8095 | 202 | 0.1045 |
| 4.8571 | 204 | 0.1268 |
| 4.9048 | 206 | 0.1133 |
| 4.9524 | 208 | 0.1274 |
| 5.0 | 210 | 0.0607 |
@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
BAAI/bge-m3