Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper
•
1908.10084
•
Published
•
9
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_ContrastiveLoss_V1_5epochs")
# Run inference
sentences = [
'Cục Xuất nhập khẩu thuộc phạm vi quản lý nhà nước của cơ quan nào?',
'Vị trí và chức năng\n1. Cục Xuất nhập khẩu là tổ chức thuộc Bộ Công Thương, thực hiện chức năng tham mưu, giúp Bộ trưởng Bộ Công Thương quản lý nhà nước và tổ chức thực thi pháp luật trong lĩnh vực hoạt động xuất khẩu, nhập khẩu hàng hóa, xuất xứ hàng hóa, mua bán hàng hóa quốc tế, đại lý mua, bán, gia công và quá cảnh hàng hóa với nước ngoài, thuộc phạm vi quản lý nhà nước của Bộ Công Thương.\n2. Cục Xuất nhập khẩu có tư cách pháp nhân, con dấu và tài khoản riêng theo quy định của pháp luật; kinh phí hoạt động do ngân sách nhà nước cấp và từ các khoản thu phí, lệ phí theo quy định của Nhà nước.\nCục Xuất nhập khẩu có tên giao dịch quốc tế bằng tiếng Anh: Agency of Foreign Trade.\nTên viết tắt: AFT.\nTrụ sở chính tại thành phố Hà Nội.',
'"Điều 112. Nghỉ lễ, tết\n1. Người lao động được nghỉ làm việc, hưởng nguyên lương trong những ngày lễ, tết sau đây:\na) Tết Dương lịch: 01 ngày (ngày 01 tháng 01 dương lịch);\nb) Tết Âm lịch: 05 ngày;\nc) Ngày Chiến thắng: 01 ngày (ngày 30 tháng 4 dương lịch);\nd) Ngày Quốc tế lao động: 01 ngày (ngày 01 tháng 5 dương lịch);\nđ) Quốc khánh: 02 ngày (ngày 02 tháng 9 dương lịch và 01 ngày liền kề trước hoặc sau);\ne) Ngày Giỗ Tổ Hùng Vương: 01 ngày (ngày 10 tháng 3 âm lịch).\n2. Lao động là người nước ngoài làm việc tại Việt Nam ngoài các ngày nghỉ theo quy định tại khoản 1 Điều này còn được nghỉ thêm 01 ngày Tết cổ truyền dân tộc và 01 ngày Quốc khánh của nước họ.\n3. Hằng năm, căn cứ vào điều kiện thực tế, Thủ tướng Chính phủ quyết định cụ thể ngày nghỉ quy định tại điểm b và điểm đ khoản 1 Điều này."',
]
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]
sentence1, sentence2, and label| sentence1 | sentence2 | label | |
|---|---|---|---|
| type | string | string | int |
| details |
|
|
|
| sentence1 | sentence2 | label |
|---|---|---|
Hồ sơ đề nghị xét cấp lại giấy phép lái xe quá hạn gồm những gì? |
"Điều 36. Cấp lại giấy phép lái xe |
1 |
Việc nhận xét và đánh giá đối với công chức cấp Trung ương luân chuyển được thực hiện khi nào? |
Cấp độ thành tích khen thưởng để xét nâng bậc lương trước thời hạn do lập thành tích xuất sắc: |
0 |
Người thực tập nghiệp vụ đăng kiểm viên xe cơ giới phải đáp ứng các điều kiện gì? |
"Điều 3. Thực tập nghiệp vụ đăng kiểm viên xe cơ giới |
1 |
ContrastiveLoss with these parameters:{
"distance_metric": "SiameseDistanceMetric.COSINE_DISTANCE",
"margin": 0.5,
"size_average": true
}
per_device_train_batch_size: 4learning_rate: 2e-05num_train_epochs: 5warmup_ratio: 0.1overwrite_output_dir: Falsedo_predict: Falseprediction_loss_only: Trueper_device_train_batch_size: 4per_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.0190 | 50 | 0.0301 |
| 0.0380 | 100 | 0.023 |
| 0.0570 | 150 | 0.0197 |
| 0.0760 | 200 | 0.0179 |
| 0.0950 | 250 | 0.0172 |
| 0.1140 | 300 | 0.0166 |
| 0.1330 | 350 | 0.0164 |
| 0.1520 | 400 | 0.014 |
| 0.1710 | 450 | 0.0143 |
| 0.1900 | 500 | 0.0139 |
| 0.2090 | 550 | 0.0129 |
| 0.2281 | 600 | 0.0158 |
| 0.2471 | 650 | 0.0131 |
| 0.2661 | 700 | 0.0138 |
| 0.2851 | 750 | 0.0135 |
| 0.3041 | 800 | 0.0125 |
| 0.3231 | 850 | 0.0137 |
| 0.3421 | 900 | 0.0152 |
| 0.3611 | 950 | 0.0137 |
| 0.3801 | 1000 | 0.0138 |
| 0.3991 | 1050 | 0.0137 |
| 0.4181 | 1100 | 0.0158 |
| 0.4371 | 1150 | 0.0115 |
| 0.4561 | 1200 | 0.0145 |
| 0.4751 | 1250 | 0.0147 |
| 0.4941 | 1300 | 0.0134 |
| 0.5131 | 1350 | 0.0138 |
| 0.5321 | 1400 | 0.0124 |
| 0.5511 | 1450 | 0.0134 |
| 0.5701 | 1500 | 0.012 |
| 0.5891 | 1550 | 0.0127 |
| 0.6081 | 1600 | 0.0143 |
| 0.6271 | 1650 | 0.0154 |
| 0.6461 | 1700 | 0.0121 |
| 0.6651 | 1750 | 0.0112 |
| 0.6842 | 1800 | 0.0143 |
| 0.7032 | 1850 | 0.0135 |
| 0.7222 | 1900 | 0.013 |
| 0.7412 | 1950 | 0.0124 |
| 0.7602 | 2000 | 0.0117 |
| 0.7792 | 2050 | 0.0121 |
| 0.7982 | 2100 | 0.0145 |
| 0.8172 | 2150 | 0.0125 |
| 0.8362 | 2200 | 0.0086 |
| 0.8552 | 2250 | 0.0132 |
| 0.8742 | 2300 | 0.0127 |
| 0.8932 | 2350 | 0.0135 |
| 0.9122 | 2400 | 0.0129 |
| 0.9312 | 2450 | 0.0121 |
| 0.9502 | 2500 | 0.0121 |
| 0.9692 | 2550 | 0.0125 |
| 0.9882 | 2600 | 0.0117 |
| 1.0072 | 2650 | 0.0119 |
| 1.0262 | 2700 | 0.0083 |
| 1.0452 | 2750 | 0.0071 |
| 1.0642 | 2800 | 0.0084 |
| 1.0832 | 2850 | 0.0083 |
| 1.1022 | 2900 | 0.0073 |
| 1.1212 | 2950 | 0.0081 |
| 1.1403 | 3000 | 0.0097 |
| 1.1593 | 3050 | 0.008 |
| 1.1783 | 3100 | 0.0081 |
| 1.1973 | 3150 | 0.0103 |
| 1.2163 | 3200 | 0.0079 |
| 1.2353 | 3250 | 0.0085 |
| 1.2543 | 3300 | 0.0083 |
| 1.2733 | 3350 | 0.008 |
| 1.2923 | 3400 | 0.0059 |
| 1.3113 | 3450 | 0.0078 |
| 1.3303 | 3500 | 0.0054 |
| 1.3493 | 3550 | 0.0083 |
| 1.3683 | 3600 | 0.0082 |
| 1.3873 | 3650 | 0.0088 |
| 1.4063 | 3700 | 0.0113 |
| 1.4253 | 3750 | 0.0067 |
| 1.4443 | 3800 | 0.0103 |
| 1.4633 | 3850 | 0.0094 |
| 1.4823 | 3900 | 0.0081 |
| 1.5013 | 3950 | 0.007 |
| 1.5203 | 4000 | 0.0076 |
| 1.5393 | 4050 | 0.0071 |
| 1.5583 | 4100 | 0.0085 |
| 1.5773 | 4150 | 0.0084 |
| 1.5964 | 4200 | 0.0078 |
| 1.6154 | 4250 | 0.0071 |
| 1.6344 | 4300 | 0.0072 |
| 1.6534 | 4350 | 0.0087 |
| 1.6724 | 4400 | 0.0066 |
| 1.6914 | 4450 | 0.0083 |
| 1.7104 | 4500 | 0.008 |
| 1.7294 | 4550 | 0.0072 |
| 1.7484 | 4600 | 0.0094 |
| 1.7674 | 4650 | 0.0087 |
| 1.7864 | 4700 | 0.0097 |
| 1.8054 | 4750 | 0.0101 |
| 1.8244 | 4800 | 0.0096 |
| 1.8434 | 4850 | 0.0074 |
| 1.8624 | 4900 | 0.0084 |
| 1.8814 | 4950 | 0.0072 |
| 1.9004 | 5000 | 0.0084 |
| 1.9194 | 5050 | 0.0096 |
| 1.9384 | 5100 | 0.0079 |
| 1.9574 | 5150 | 0.0091 |
| 1.9764 | 5200 | 0.0091 |
| 1.9954 | 5250 | 0.0085 |
| 2.0144 | 5300 | 0.0054 |
| 2.0334 | 5350 | 0.0038 |
| 2.0525 | 5400 | 0.0046 |
| 2.0715 | 5450 | 0.0046 |
| 2.0905 | 5500 | 0.0059 |
| 2.1095 | 5550 | 0.0043 |
| 2.1285 | 5600 | 0.0046 |
| 2.1475 | 5650 | 0.004 |
| 2.1665 | 5700 | 0.0034 |
| 2.1855 | 5750 | 0.0037 |
| 2.2045 | 5800 | 0.0032 |
| 2.2235 | 5850 | 0.0031 |
| 2.2425 | 5900 | 0.0038 |
| 2.2615 | 5950 | 0.0046 |
| 2.2805 | 6000 | 0.0035 |
| 2.2995 | 6050 | 0.0045 |
| 2.3185 | 6100 | 0.0044 |
| 2.3375 | 6150 | 0.0037 |
| 2.3565 | 6200 | 0.0046 |
| 2.3755 | 6250 | 0.0052 |
| 2.3945 | 6300 | 0.0037 |
| 2.4135 | 6350 | 0.004 |
| 2.4325 | 6400 | 0.0036 |
| 2.4515 | 6450 | 0.0036 |
| 2.4705 | 6500 | 0.0041 |
| 2.4895 | 6550 | 0.0049 |
| 2.5086 | 6600 | 0.0034 |
| 2.5276 | 6650 | 0.0056 |
| 2.5466 | 6700 | 0.0043 |
| 2.5656 | 6750 | 0.0043 |
| 2.5846 | 6800 | 0.0042 |
| 2.6036 | 6850 | 0.0044 |
| 2.6226 | 6900 | 0.0037 |
| 2.6416 | 6950 | 0.005 |
| 2.6606 | 7000 | 0.0041 |
| 2.6796 | 7050 | 0.0042 |
| 2.6986 | 7100 | 0.0035 |
| 2.7176 | 7150 | 0.0043 |
| 2.7366 | 7200 | 0.0046 |
| 2.7556 | 7250 | 0.005 |
| 2.7746 | 7300 | 0.0036 |
| 2.7936 | 7350 | 0.004 |
| 2.8126 | 7400 | 0.0048 |
| 2.8316 | 7450 | 0.0038 |
| 2.8506 | 7500 | 0.004 |
| 2.8696 | 7550 | 0.0045 |
| 2.8886 | 7600 | 0.0046 |
| 2.9076 | 7650 | 0.0044 |
| 2.9266 | 7700 | 0.005 |
| 2.9456 | 7750 | 0.0039 |
| 2.9647 | 7800 | 0.0048 |
| 2.9837 | 7850 | 0.0031 |
| 3.0027 | 7900 | 0.0044 |
| 3.0217 | 7950 | 0.0018 |
| 3.0407 | 8000 | 0.0017 |
| 3.0597 | 8050 | 0.0019 |
| 3.0787 | 8100 | 0.0019 |
| 3.0977 | 8150 | 0.0017 |
| 3.1167 | 8200 | 0.0021 |
| 3.1357 | 8250 | 0.0024 |
| 3.1547 | 8300 | 0.0025 |
| 3.1737 | 8350 | 0.002 |
| 3.1927 | 8400 | 0.0022 |
| 3.2117 | 8450 | 0.0021 |
| 3.2307 | 8500 | 0.0021 |
| 3.2497 | 8550 | 0.0017 |
| 3.2687 | 8600 | 0.0018 |
| 3.2877 | 8650 | 0.002 |
| 3.3067 | 8700 | 0.0021 |
| 3.3257 | 8750 | 0.0017 |
| 3.3447 | 8800 | 0.0022 |
| 3.3637 | 8850 | 0.0019 |
| 3.3827 | 8900 | 0.0018 |
| 3.4017 | 8950 | 0.0022 |
| 3.4208 | 9000 | 0.0022 |
| 3.4398 | 9050 | 0.0019 |
| 3.4588 | 9100 | 0.0023 |
| 3.4778 | 9150 | 0.0023 |
| 3.4968 | 9200 | 0.0018 |
| 3.5158 | 9250 | 0.002 |
| 3.5348 | 9300 | 0.0018 |
| 3.5538 | 9350 | 0.0022 |
| 3.5728 | 9400 | 0.0024 |
| 3.5918 | 9450 | 0.002 |
| 3.6108 | 9500 | 0.0021 |
| 3.6298 | 9550 | 0.002 |
| 3.6488 | 9600 | 0.0032 |
| 3.6678 | 9650 | 0.0021 |
| 3.6868 | 9700 | 0.002 |
| 3.7058 | 9750 | 0.002 |
| 3.7248 | 9800 | 0.0023 |
| 3.7438 | 9850 | 0.0021 |
| 3.7628 | 9900 | 0.0022 |
| 3.7818 | 9950 | 0.0016 |
| 3.8008 | 10000 | 0.0017 |
| 3.8198 | 10050 | 0.0015 |
| 3.8388 | 10100 | 0.0022 |
| 3.8578 | 10150 | 0.0018 |
| 3.8769 | 10200 | 0.0022 |
| 3.8959 | 10250 | 0.0027 |
| 3.9149 | 10300 | 0.0027 |
| 3.9339 | 10350 | 0.0018 |
| 3.9529 | 10400 | 0.0017 |
| 3.9719 | 10450 | 0.0016 |
| 3.9909 | 10500 | 0.0023 |
| 4.0099 | 10550 | 0.0015 |
| 4.0289 | 10600 | 0.0012 |
| 4.0479 | 10650 | 0.0012 |
| 4.0669 | 10700 | 0.0012 |
| 4.0859 | 10750 | 0.001 |
| 4.1049 | 10800 | 0.001 |
| 4.1239 | 10850 | 0.0011 |
| 4.1429 | 10900 | 0.0013 |
| 4.1619 | 10950 | 0.0011 |
| 4.1809 | 11000 | 0.0011 |
| 4.1999 | 11050 | 0.0011 |
| 4.2189 | 11100 | 0.0012 |
| 4.2379 | 11150 | 0.001 |
| 4.2569 | 11200 | 0.0014 |
| 4.2759 | 11250 | 0.0011 |
| 4.2949 | 11300 | 0.0009 |
| 4.3139 | 11350 | 0.0012 |
| 4.3330 | 11400 | 0.001 |
| 4.3520 | 11450 | 0.001 |
| 4.3710 | 11500 | 0.0011 |
| 4.3900 | 11550 | 0.001 |
| 4.4090 | 11600 | 0.0012 |
| 4.4280 | 11650 | 0.0014 |
| 4.4470 | 11700 | 0.0012 |
| 4.4660 | 11750 | 0.0011 |
| 4.4850 | 11800 | 0.0013 |
| 4.5040 | 11850 | 0.0014 |
| 4.5230 | 11900 | 0.0014 |
| 4.5420 | 11950 | 0.0013 |
| 4.5610 | 12000 | 0.0012 |
| 4.5800 | 12050 | 0.0011 |
| 4.5990 | 12100 | 0.0011 |
| 4.6180 | 12150 | 0.0011 |
| 4.6370 | 12200 | 0.0013 |
| 4.6560 | 12250 | 0.001 |
| 4.6750 | 12300 | 0.0009 |
| 4.6940 | 12350 | 0.001 |
| 4.7130 | 12400 | 0.0013 |
| 4.7320 | 12450 | 0.001 |
| 4.7510 | 12500 | 0.001 |
| 4.7700 | 12550 | 0.0009 |
| 4.7891 | 12600 | 0.001 |
| 4.8081 | 12650 | 0.0012 |
| 4.8271 | 12700 | 0.001 |
| 4.8461 | 12750 | 0.0015 |
| 4.8651 | 12800 | 0.0009 |
| 4.8841 | 12850 | 0.0011 |
| 4.9031 | 12900 | 0.0009 |
| 4.9221 | 12950 | 0.0013 |
| 4.9411 | 13000 | 0.0011 |
| 4.9601 | 13050 | 0.0013 |
| 4.9791 | 13100 | 0.001 |
| 4.9981 | 13150 | 0.001 |
@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",
}
@inproceedings{hadsell2006dimensionality,
author={Hadsell, R. and Chopra, S. and LeCun, Y.},
booktitle={2006 IEEE Computer Society Conference on Computer Vision and Pattern Recognition (CVPR'06)},
title={Dimensionality Reduction by Learning an Invariant Mapping},
year={2006},
volume={2},
number={},
pages={1735-1742},
doi={10.1109/CVPR.2006.100}
}
Base model
BAAI/bge-m3