Scaling Deep Contrastive Learning Batch Size under Memory Limited Setup
Paper
•
2101.06983
•
Published
•
1
This is a sentence-transformers model finetuned from google-bert/bert-base-multilingual-cased. 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': 512, 'do_lower_case': False}) with Transformer model: BertModel
(1): Pooling({'word_embedding_dimension': 768, '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})
)
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("Savoxism/Finetuned-BERT-Multilingual-Legal-Doc-Retrieval")
# Run inference
sentences = [
'Tổ chức sinh hoạt tôn giáo tập trung cần đáp ứng điều kiện gì?',
'"Điều 16. Điều kiện đăng ký sinh hoạt tôn giáo tập trung\n1. Tổ chức tôn giáo đăng ký sinh hoạt tôn giáo tập trung cho tín đồ tại những nơi chưa đủ điều kiện thành lập tổ chức tôn giáo trực thuộc; tổ chức được cấp chứng nhận đăng ký hoạt động tôn giáo đăng ký sinh hoạt tôn giáo tập trung cho những người thuộc tổ chức khi đáp ứng đủ các điều kiện sau đây:\na) Có địa điểm hợp pháp để sinh hoạt tôn giáo;\nb) Nhóm sinh hoạt tôn giáo tập trung có người đại diện là công dân Việt Nam thường trú tại Việt Nam, có năng lực hành vi dân sự đầy đủ; không trong thời gian bị áp dụng biện pháp xử lý hành chính trong lĩnh vực tín ngưỡng, tôn giáo; không có án tích hoặc không phải là người đang bị buộc tội theo quy định của pháp luật về tố tụng hình sự;\nc) Nội dung sinh hoạt tôn giáo không thuộc trường hợp quy định tại Điều 5 của Luật này.\n2. Những người theo tôn giáo không thuộc trường hợp quy định tại khoản 1 Điều này được đăng ký sinh hoạt tôn giáo tập trung khi đáp ứng đủ các điều kiện quy định tại khoản 1 Điều này và các điều kiện sau đây:\na) Có giáo lý, giáo luật;\nb) Tên của nhóm sinh hoạt tôn giáo tập trung không trùng với tên tổ chức tôn giáo hoặc tổ chức đã được cấp chứng nhận đăng ký hoạt động tôn giáo, tên tổ chức chính trị, tổ chức chính trị - xã hội hoặc tên danh nhân, anh hùng dân tộc."',
'ĐIỀU TRỊ\n...\n3. Điều trị hỗ trợ\na) Hạ sốt.\nChỉ dùng paracetamol khi nhiệt độ trên 39oC (không dùng thuốc hạ sốt nhóm salicylate như aspirin).\nb) Bảo đảm chế độ dinh dưỡng và chăm sóc.\n- Dinh dưỡng:\n+ Người bệnh nhẹ: cho ăn bằng đường miệng.\n+ Người bệnh nặng: cho ăn sữa và bột dinh dưỡng qua ống thông dạ dày.\n+ Nếu người bệnh không ăn được phải kết hợp nuôi dưỡng bằng đường tĩnh mạch.\n- Chăm sóc hô hấp: giúp người bệnh ho, khạc; vỗ rung vùng ngực; hút đờm.\nc) Sử dụng kháng sinh thích hợp khi có bội nhiễm vi khuẩn\nd) Hỗ trợ hô hấp khi có suy hô hấp:\n- Nằm đầu cao 30-450.\n- Cho người bệnh thở oxy với lưu lượng thích hợp.\n- Những trường hợp không đáp ứng với thở oxy cần hỗ trợ hô hấp bằng máy thở không xâm nhập hoặc xâm nhập.\ne) Phát hiện và điều trị suy đa phủ tạng.\ng) Những trường hợp nặng điều trị giống như cúm A (H5N1) nặng đã được Bộ Y tế ban hành.\n...',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 768]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [3, 3]
sentence_0 and sentence_1| sentence_0 | sentence_1 | |
|---|---|---|
| type | string | string |
| details |
|
|
| sentence_0 | sentence_1 |
|---|---|
Người sử dụng lao động khi thực hiện đào tạo nghề cần thông báo kết quả đào tạo đến cơ quan nào? |
Trách nhiệm của người sử dụng lao động về đào tạo, bồi dưỡng, nâng cao trình độ, kỹ năng nghề |
Thương nhân kinh doanh Siêu thị kinh doanh tổng hợp có thể tự tiến hành phân hạng Siêu thị của mình không? |
Phân hạng, tên gọi và biển hiệu Siêu thị, Trung tâm thương mại |
Căn hộ chung cư phải đảm bảo có diện tích tối thiểu bao nhiêu theo quy định hiện nay? |
"2.2.4 Căn hộ chung cư |
CachedMultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim"
}
per_device_train_batch_size: 32per_device_eval_batch_size: 32num_train_epochs: 2multi_dataset_batch_sampler: round_robinoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: noprediction_loss_only: Trueper_device_train_batch_size: 32per_device_eval_batch_size: 32per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 1eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 5e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1num_train_epochs: 2max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: {}warmup_ratio: 0.0warmup_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: 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, '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: batch_samplermulti_dataset_batch_sampler: round_robin| Epoch | Step | Training Loss |
|---|---|---|
| 0.1786 | 500 | 0.6029 |
| 0.3571 | 1000 | 0.1195 |
| 0.5357 | 1500 | 0.0848 |
| 0.7143 | 2000 | 0.0719 |
| 0.8929 | 2500 | 0.0645 |
| 1.0714 | 3000 | 0.0547 |
| 1.25 | 3500 | 0.0299 |
| 1.4286 | 4000 | 0.033 |
| 1.6071 | 4500 | 0.0292 |
| 1.7857 | 5000 | 0.0244 |
| 1.9643 | 5500 | 0.0268 |
@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
google-bert/bert-base-multilingual-cased