Scaling Deep Contrastive Learning Batch Size under Memory Limited Setup
Paper
• 2101.06983 • Published
• 2
This is a sentence-transformers model finetuned from varin/embeddinggemma-thai-law on the json dataset. It maps sentences & paragraphs to a 768-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': 256, 'do_lower_case': False, 'architecture': 'Gemma3TextModel'})
(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, '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): Dense({'in_features': 768, 'out_features': 3072, 'bias': False, 'activation_function': 'torch.nn.modules.linear.Identity'})
(3): Dense({'in_features': 3072, 'out_features': 768, 'bias': False, 'activation_function': 'torch.nn.modules.linear.Identity'})
(4): 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("varin/embeddinggemma-thai-law")
# Run inference
queries = [
"\u0e2b\u0e32\u0e01\u0e1c\u0e39\u0e49\u0e40\u0e1b\u0e47\u0e19\u0e2b\u0e38\u0e49\u0e19\u0e2a\u0e48\u0e27\u0e19\u0e17\u0e31\u0e49\u0e07\u0e2b\u0e21\u0e14\u0e43\u0e2b\u0e49\u0e04\u0e27\u0e32\u0e21\u0e22\u0e34\u0e19\u0e22\u0e2d\u0e21 \u0e2b\u0e49\u0e32\u0e07\u0e2b\u0e38\u0e49\u0e19\u0e2a\u0e48\u0e27\u0e19\u0e08\u0e14\u0e17\u0e30\u0e40\u0e1a\u0e35\u0e22\u0e19\u0e2a\u0e2d\u0e07\u0e41\u0e2b\u0e48\u0e07\u0e08\u0e30\u0e04\u0e27\u0e1a\u0e23\u0e27\u0e21\u0e01\u0e31\u0e19\u0e44\u0e14\u0e49\u0e2b\u0e23\u0e37\u0e2d\u0e44\u0e21\u0e48?",
]
documents = [
'ประมวลกฎหมายแพ่งและพาณิชย์ มาตรา 1073 ห้างหุ้นส่วนจดทะเบียนห้างหนึ่งจะควบเข้าเป็นอันเดียวกับห้างหุ้นส่วนจดทะเบียนอีกห้างหนึ่งก็ได้ โดยความยินยอมของผู้เป็นหุ้นส่วนทั้งหมด เว้นแต่จะได้ตกลงกันไว้เป็นอย่างอื่น',
'การควบห้างหุ้นส่วนจดทะเบียนต้องกระทำโดยความยินยอมของหุ้นส่วนไม่น้อยกว่าสามในสี่ของจำนวนหุ้นส่วนทั้งหมดเท่านั้น',
'ประมวลกฎหมายแพ่งและพาณิชย์ มาตรา 1061 เมื่อห้างหุ้นส่วนเลิกกันแล้วก็ให้จัดการชำระบัญชี เว้นแต่จะได้ตกลงกันให้จัดการทรัพย์สินโดยวิธีอื่นในระหว่างผู้เป็นหุ้นส่วนด้วยกัน หรือว่าห้างหุ้นส่วนนั้นศาลได้พิพากษาให้ล้มละลาย ถ้าการเลิกห้างหุ้นส่วนนั้นได้เป็นไปโดยที่เจ้าหนี้เฉพาะตัวของผู้เป็นหุ้นส่วนคนใดคนหนึ่งได้ให้คำบอกกล่าวก็ดี หรือโดยที่ผู้เป็นหุ้นส่วนคนใดคนหนึ่งล้มละลายก็ดี ท่านว่าจะงดการชำระบัญชีเสียได้ต่อเมื่อเจ้าหนี้คนนั้น หรือเจ้าพนักงานรักษาทรัพย์ยินยอมด้วย การชำระบัญชีนั้น ให้ผู้เป็นหุ้นส่วนทั้งหมดด้วยกันจัดทำหรือให้บุคคลอื่นซึ่งผู้เป็นหุ้นส่วนได้ตั้งแต่งขึ้นนั้นเป็นผู้จัดทำ การตั้งแต่งผู้ชำระบัญชี ให้วินิจฉัยชี้ขาดโดยคะแนนเสียงข้างมากของผู้เป็นหุ้นส่วน',
]
query_embeddings = model.encode_query(queries)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings.shape)
# [1, 768] [3, 768]
# Get the similarity scores for the embeddings
similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities)
# tensor([[0.7431, 0.0676, 0.1604]])
anchor, positive, and negative| anchor | positive | negative | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| anchor | positive | negative |
|---|---|---|
กฎหมายนี้มีชื่อเรียกว่าอะไร |
ประมวลกฎหมายแพ่งและพาณิชย์ มาตรา 1 กฎหมายนี้ให้เรียกว่า ประมวลกฎหมายแพ่งและพาณิชย์ |
พระราชบัญญัติว่าด้วยธุรกรรมทางอิเล็กทรอนิกส์ |
ชื่อของประมวลกฎหมายนี้คืออะไร |
ประมวลกฎหมายแพ่งและพาณิชย์ มาตรา 1 กฎหมายนี้ให้เรียกว่า ประมวลกฎหมายแพ่งและพาณิชย์ |
ประมวลรัษฎากร |
กฎหมายที่กล่าวถึงในมาตรานี้เรียกว่าอะไร |
ประมวลกฎหมายแพ่งและพาณิชย์ มาตรา 1 กฎหมายนี้ให้เรียกว่า ประมวลกฎหมายแพ่งและพาณิชย์ |
พระราชบัญญัติล้มละลาย |
CachedMultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim",
"mini_batch_size": 8,
"gather_across_devices": false
}
per_device_train_batch_size: 16learning_rate: 2e-05num_train_epochs: 1warmup_ratio: 0.1bf16: Truepush_to_hub: Truehub_model_id: varin/embeddinggemma-thai-lawhub_strategy: endoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: noprediction_loss_only: Trueper_device_train_batch_size: 16per_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: 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: Nonejit_mode_eval: Falsebf16: Truefp16: 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, '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: Trueresume_from_checkpoint: Nonehub_model_id: varin/embeddinggemma-thai-lawhub_strategy: endhub_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.0077 | 10 | 0.0347 |
| 0.0154 | 20 | 0.0056 |
| 0.0231 | 30 | 0.0127 |
| 0.0308 | 40 | 0.0101 |
| 0.0386 | 50 | 0.056 |
| 0.0463 | 60 | 0.003 |
| 0.0540 | 70 | 0.0061 |
| 0.0617 | 80 | 0.0134 |
| 0.0694 | 90 | 0.0114 |
| 0.0771 | 100 | 0.0013 |
| 0.0848 | 110 | 0.0107 |
| 0.0925 | 120 | 0.02 |
| 0.1002 | 130 | 0.002 |
| 0.1079 | 140 | 0.0016 |
| 0.1157 | 150 | 0.1214 |
| 0.1234 | 160 | 0.0062 |
| 0.1311 | 170 | 0.0322 |
| 0.1388 | 180 | 0.0354 |
| 0.1465 | 190 | 0.0267 |
| 0.1542 | 200 | 0.0176 |
| 0.1619 | 210 | 0.0139 |
| 0.1696 | 220 | 0.0469 |
| 0.1773 | 230 | 0.0268 |
| 0.1850 | 240 | 0.0361 |
| 0.1928 | 250 | 0.0369 |
| 0.2005 | 260 | 0.0902 |
| 0.2082 | 270 | 0.1318 |
| 0.2159 | 280 | 0.0116 |
| 0.2236 | 290 | 0.0204 |
| 0.2313 | 300 | 0.0166 |
| 0.2390 | 310 | 0.147 |
| 0.2467 | 320 | 0.0124 |
| 0.2544 | 330 | 0.0251 |
| 0.2621 | 340 | 0.0138 |
| 0.2699 | 350 | 0.043 |
| 0.2776 | 360 | 0.0814 |
| 0.2853 | 370 | 0.0181 |
| 0.2930 | 380 | 0.0328 |
| 0.3007 | 390 | 0.0273 |
| 0.3084 | 400 | 0.1388 |
| 0.3161 | 410 | 0.031 |
| 0.3238 | 420 | 0.0443 |
| 0.3315 | 430 | 0.0219 |
| 0.3392 | 440 | 0.0065 |
| 0.3470 | 450 | 0.0201 |
| 0.3547 | 460 | 0.043 |
| 0.3624 | 470 | 0.0411 |
| 0.3701 | 480 | 0.1481 |
| 0.3778 | 490 | 0.0352 |
| 0.3855 | 500 | 0.0208 |
| 0.3932 | 510 | 0.0159 |
| 0.4009 | 520 | 0.0161 |
| 0.4086 | 530 | 0.007 |
| 0.4163 | 540 | 0.0227 |
| 0.4241 | 550 | 0.0221 |
| 0.4318 | 560 | 0.0166 |
| 0.4395 | 570 | 0.007 |
| 0.4472 | 580 | 0.0291 |
| 0.4549 | 590 | 0.0152 |
| 0.4626 | 600 | 0.0158 |
| 0.4703 | 610 | 0.0344 |
| 0.4780 | 620 | 0.0184 |
| 0.4857 | 630 | 0.0126 |
| 0.4934 | 640 | 0.0091 |
| 0.5012 | 650 | 0.0154 |
| 0.5089 | 660 | 0.0155 |
| 0.5166 | 670 | 0.0096 |
| 0.5243 | 680 | 0.017 |
| 0.5320 | 690 | 0.0108 |
| 0.5397 | 700 | 0.0119 |
| 0.5474 | 710 | 0.007 |
| 0.5551 | 720 | 0.0273 |
| 0.5628 | 730 | 0.0232 |
| 0.5705 | 740 | 0.0186 |
| 0.5783 | 750 | 0.0246 |
| 0.5860 | 760 | 0.0118 |
| 0.5937 | 770 | 0.0035 |
| 0.6014 | 780 | 0.0133 |
| 0.6091 | 790 | 0.026 |
| 0.6168 | 800 | 0.0038 |
| 0.6245 | 810 | 0.044 |
| 0.6322 | 820 | 0.0076 |
| 0.6399 | 830 | 0.0334 |
| 0.6476 | 840 | 0.0173 |
| 0.6554 | 850 | 0.0111 |
| 0.6631 | 860 | 0.0385 |
| 0.6708 | 870 | 0.0082 |
| 0.6785 | 880 | 0.0114 |
| 0.6862 | 890 | 0.0071 |
| 0.6939 | 900 | 0.0414 |
| 0.7016 | 910 | 0.0038 |
| 0.7093 | 920 | 0.0065 |
| 0.7170 | 930 | 0.0049 |
| 0.7247 | 940 | 0.1457 |
| 0.7325 | 950 | 0.0117 |
| 0.7402 | 960 | 0.0146 |
| 0.7479 | 970 | 0.0162 |
| 0.7556 | 980 | 0.0132 |
| 0.7633 | 990 | 0.0035 |
| 0.7710 | 1000 | 0.0103 |
| 0.7787 | 1010 | 0.0409 |
| 0.7864 | 1020 | 0.0157 |
| 0.7941 | 1030 | 0.1586 |
| 0.8019 | 1040 | 0.0205 |
| 0.8096 | 1050 | 0.0915 |
| 0.8173 | 1060 | 0.015 |
| 0.8250 | 1070 | 0.0103 |
| 0.8327 | 1080 | 0.0016 |
| 0.8404 | 1090 | 0.0198 |
| 0.8481 | 1100 | 0.0393 |
| 0.8558 | 1110 | 0.0241 |
| 0.8635 | 1120 | 0.0043 |
| 0.8712 | 1130 | 0.0114 |
| 0.8790 | 1140 | 0.0215 |
| 0.8867 | 1150 | 0.0174 |
| 0.8944 | 1160 | 0.0286 |
| 0.9021 | 1170 | 0.006 |
| 0.9098 | 1180 | 0.0155 |
| 0.9175 | 1190 | 0.0292 |
| 0.9252 | 1200 | 0.0117 |
| 0.9329 | 1210 | 0.0153 |
| 0.9406 | 1220 | 0.0135 |
| 0.9483 | 1230 | 0.0203 |
| 0.9561 | 1240 | 0.0091 |
| 0.9638 | 1250 | 0.0282 |
| 0.9715 | 1260 | 0.0142 |
| 0.9792 | 1270 | 0.0983 |
| 0.9869 | 1280 | 0.0126 |
| 0.9946 | 1290 | 0.0159 |
@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}
}
Unable to build the model tree, the base model loops to the model itself. Learn more.