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': 8192, '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("sentence_transformers_model_id")
# Run inference
sentences = [
'nội_dung đánh_giá xếp loại chất_lượng kiểm_soát viên tại doanh_nghiệp do bộ công_thương làm đại_diện chủ sở_hữu vốn nhà_nước gồm những gì',
'điều truy_cứu trách_nhiệm hình_sự trong một_số trường_hợp cụ_thể trường_hợp người cho vay_lãi nặng nhằm thu lợi bất_chính từ đồng trở lên nhưng vì nguyên_nhân ngoài ý_muốn mà người cho vay chưa thu lợi bất_chính hoặc đã thu lợi bất_chính dưới đồng thì bị truy_cứu trách_nhiệm hình_sự theo khung hình_phạt tương_ứng với tổng_số tiền thu lợi bất_chính mà họ nhằm đạt được việc xác_định số tiền thu lợi bất_chính được thực_hiện theo hướng_dẫn tại điều nghị_quyết này khi quyết_định_hình_phạt tòa_án áp_dụng điều và khoản điều của bộ_luật hình_sự về phạm_tội chưa đạt',
'thành_phần phiên_hòa giải đối_thoại tại tòa_án thành_phần phiên_hòa giải đối_thoại gồm có a hòa giải_viên b các bên người đại_diện người phiên_dịch c người được mời tham_gia hòa giải đối_thoại trong trường_hợp cần_thiết các bên có_thể trực_tiếp hoặc ủy quyền cho người đại_diện tham_gia hòa giải đối_thoại đồng_thời phải thông_báo bằng văn_bản về họ tên địa_chỉ của người đại_diện cho bên kia và hòa giải viên biết đối_với hòa giải việc ly_hôn các bên trong quan_hệ vợ_chồng phải trực_tiếp tham_gia hòa giải quyền và nghĩa_vụ của người đại_diện của các bên được xác_định theo quy_định của bộ luật dân_sự người bị kiện trong khiếu_kiện hành_chính có_thể ủy quyền cho người đại_diện tham_gia đối_thoại người đại_diện theo ủy quyền phải có đầy_đủ thẩm_quyền để giải_quyết khiếu_kiện',
]
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]
question, pos_neg, and label| question | pos_neg | label | |
|---|---|---|---|
| type | string | string | int |
| details |
|
|
|
| question | pos_neg | label |
|---|---|---|
hồ_sơ đề_nghị đưa hàng_hóa_nhập_khẩu về bảo_quản của người khai hải_quan gồm những thành_phần_nào |
dự_án đầu_tư khởi_nghiệp sáng_tạo là dự_án đầu_tư thực_hiện ý_tưởng trên cơ_sở khai_thác tài_sản trí_tuệ công_nghệ mô_hình kinh_doanh mới và có khả_năng tăng_trưởng nhanh |
0 |
giai_đoạn ủ_bệnh của bệnh đậu_mùa khỉ là bao_nhiêu ngày |
cấp thẻ bảo_hiểm y_tế đối_tượng bảo_trợ xã_hội đang hưởng trợ_cấp xã_hội hàng tháng được cấp thẻ bảo_hiểm y_tế theo quy_định của pháp_luật về bảo_hiểm y_tế trường_hợp đối_tượng quy_định tại khoản điều này thuộc diện được cấp nhiều loại thẻ bảo_hiểm y_tế thì chỉ được cấp một thẻ bảo_hiểm y_tế có quyền_lợi bảo_hiểm y_tế cao nhất |
0 |
trường_hợp khiếu_nại quyết_định hành_chính thì quyết_định bị khiếu_nại có buộc phải tạm đình_chỉ thi_hành hay không |
tạm đình_chỉ việc thi_hành_quyết_định hành_chính bị khiếu_nại trong quá_trình giải_quyết khiếu_nại nếu xét thấy việc thi_hành_quyết_định hành_chính bị khiếu_nại sẽ gây hậu_quả khó khắc_phục thì người giải_quyết khiếu_nại ra quyết_định tạm đình_chỉ việc thi_hành_quyết_định hành_chính bị khiếu_nại thời_hạn tạm đình_chỉ không vượt quá thời_gian còn lại của thời_hạn giải_quyết khiếu_nại khi xét thấy lý_do của việc tạm đình_chỉ không còn thì người giải_quyết khiếu_nại phải ra quyết_định hủy bỏ ngay quyết_định tạm đình_chỉ |
1 |
ContrastiveLoss with these parameters:{
"distance_metric": "SiameseDistanceMetric.COSINE_DISTANCE",
"margin": 0.5,
"size_average": true
}
per_device_train_batch_size: 2learning_rate: 2e-05weight_decay: 0.01num_train_epochs: 1warmup_ratio: 0.1fp16: Truefp16_full_eval: Trueoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: noprediction_loss_only: Trueper_device_train_batch_size: 2per_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.01adam_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: Falseuse_ipex: Falsebf16: Falsefp16: Truefp16_opt_level: O1half_precision_backend: autobf16_full_eval: Falsefp16_full_eval: Truetf32: 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: 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: 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: Falseaverage_tokens_across_devices: Falseprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportional| Epoch | Step | Training Loss |
|---|---|---|
| 0.0010 | 100 | 0.0289 |
| 0.0021 | 200 | 0.0306 |
| 0.0031 | 300 | 0.0322 |
| 0.0042 | 400 | 0.0307 |
| 0.0052 | 500 | 0.0288 |
| 0.0063 | 600 | 0.0327 |
| 0.0073 | 700 | 0.0287 |
| 0.0084 | 800 | 0.027 |
| 0.0094 | 900 | 0.0259 |
| 0.0105 | 1000 | 0.0249 |
| 0.0115 | 1100 | 0.029 |
| 0.0126 | 1200 | 0.0287 |
| 0.0136 | 1300 | 0.028 |
| 0.0146 | 1400 | 0.0259 |
| 0.0157 | 1500 | 0.0209 |
| 0.0167 | 1600 | 0.0213 |
| 0.0178 | 1700 | 0.0237 |
| 0.0188 | 1800 | 0.022 |
| 0.0199 | 1900 | 0.0202 |
| 0.0209 | 2000 | 0.0182 |
| 0.0220 | 2100 | 0.0223 |
| 0.0230 | 2200 | 0.0211 |
| 0.0241 | 2300 | 0.0155 |
| 0.0251 | 2400 | 0.0186 |
| 0.0262 | 2500 | 0.0171 |
| 0.0272 | 2600 | 0.0174 |
| 0.0283 | 2700 | 0.0172 |
| 0.0293 | 2800 | 0.0178 |
| 0.0303 | 2900 | 0.0174 |
| 0.0314 | 3000 | 0.0184 |
| 0.0324 | 3100 | 0.0168 |
| 0.0335 | 3200 | 0.0183 |
@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