Edit model card

vietnamese-bi-encoder-fine-tuning-for-law-chatbot

This is a sentence-transformers model finetuned from bkai-foundation-models/vietnamese-bi-encoder. 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.

Model Details

Model Description

  • Model Type: Sentence Transformer
  • Base model: bkai-foundation-models/vietnamese-bi-encoder
  • Maximum Sequence Length: 256 tokens
  • Output Dimensionality: 768 tokens
  • Similarity Function: Cosine Similarity
  • Language: vn
  • License: apache-2.0

Model Sources

Full Model Architecture

SentenceTransformer(
  (0): Transformer({'max_seq_length': 256, 'do_lower_case': False}) with Transformer model: RobertaModel 
  (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})
)

Usage

Direct Usage (Sentence Transformers)

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("maiduchuy321/vietnamese-bi-encoder-fine-tuning-for-law-chatbot")
# Run inference
sentences = [
    'Thời gian giải quyết thủ tục hành chính đối với 01 bộ hồ sơ quảng cáo thực phẩm?',
    'Theo quy định tại khoản 5 Điều 27 Nghị định 15/2018/NĐ-CP: Trong thời hạn 10 ngày làm việc, kể từ ngày nhận đủ hồ sơ hợp lệ, cơ quan tiếp nhận hồ sơ có trách nhiệm xem xét hồ sơ và trả kết quả theo Mẫu số 11 Phụ lục I ban hành kèm theo Nghị định 15/2018/NĐ-CP. Thời hạn này được tính từ ngày đóng dấu đến của cơ quan tiếp nhận hồ sơ nếu hồ sơ được gửi qua đường bưu điện hoặc ngày hồ sơ hoàn chỉnh được tiếp nhận trên hệ thống dịch vụ công trực tuyến.Trong trường hợp không đồng ý với nội dung quảng cáo của tổ chức, cá nhân hoặc yêu cầu sửa đổi, bổ sung, cơ quan tiếp nhận hồ sơ phải có văn bản nêu rõ lý do và căn cứ pháp lý của việc yêu cầu. Trong thời hạn 10 ngày làm việc kể từ khi nhận hồ sơ sửa đổi, bổ sung, cơ quan tiếp nhận hồ sơ thẩm định hồ sơ và có văn bản trả lời. Sau 90 ngày làm việc kể từ khi có công văn yêu cầu sửa đổi, bổ sung nếu tổ chức, cá nhân không sửa đổi, bổ sung thì hồ sơ không còn giá trị.',
    'Ngoài các hồ sơ, tài liệu gửi 1 lần và gửi hàng năm theo chế độ quy định, chủ đầu tư gửi KBNN các hồ sơ, tài liệu có liên quan theo quy định tại tiết 1.5.1, mục 1.5, và 1.5.1, mục 1.6, điểm 1, phần II, Thông tư số 113/2008/TT-BTC ngày 27/11/2008 của BTC cụ thể: Hồ sơ cam kết chi thường xuyên:- Hợp đồng mua bán hàng hoá, dịch vụ có giá trị từ 100 triệu đồng trở lên (gửi lần đầu hoặc khi có điều chỉnh hợp đồng);- Đề nghị cam kết chi hoặc đề nghị điều chỉnh cam kết chi.Hồ sơ cam kết chi đầu tư: - Hợp đồng có giá trị từ 500 triệu đồng trở lên (gửi lần đầu khi đề nghị cam kết chi hoặc gửi khi có điều chỉnh hợp đồng);- Đề nghị cam kết chi hoặc đề nghị điều chỉnh cam kết chi.',
]
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]

Evaluation

Metrics

Information Retrieval

Metric Value
cosine_accuracy@1 0.5192
cosine_accuracy@3 0.7035
cosine_accuracy@5 0.7704
cosine_accuracy@10 0.8433
cosine_precision@1 0.5192
cosine_precision@3 0.2345
cosine_precision@5 0.1541
cosine_precision@10 0.0843
cosine_recall@1 0.5192
cosine_recall@3 0.7035
cosine_recall@5 0.7704
cosine_recall@10 0.8433
cosine_ndcg@10 0.6785
cosine_mrr@10 0.6261
cosine_map@100 0.6315

Information Retrieval

Metric Value
cosine_accuracy@1 0.51
cosine_accuracy@3 0.7058
cosine_accuracy@5 0.7642
cosine_accuracy@10 0.8402
cosine_precision@1 0.51
cosine_precision@3 0.2353
cosine_precision@5 0.1528
cosine_precision@10 0.084
cosine_recall@1 0.51
cosine_recall@3 0.7058
cosine_recall@5 0.7642
cosine_recall@10 0.8402
cosine_ndcg@10 0.673
cosine_mrr@10 0.6197
cosine_map@100 0.6252

Information Retrieval

Metric Value
cosine_accuracy@1 0.5023
cosine_accuracy@3 0.6951
cosine_accuracy@5 0.7634
cosine_accuracy@10 0.8349
cosine_precision@1 0.5023
cosine_precision@3 0.2317
cosine_precision@5 0.1527
cosine_precision@10 0.0835
cosine_recall@1 0.5023
cosine_recall@3 0.6951
cosine_recall@5 0.7634
cosine_recall@10 0.8349
cosine_ndcg@10 0.6663
cosine_mrr@10 0.6125
cosine_map@100 0.6182

Information Retrieval

Metric Value
cosine_accuracy@1 0.4839
cosine_accuracy@3 0.6674
cosine_accuracy@5 0.7481
cosine_accuracy@10 0.821
cosine_precision@1 0.4839
cosine_precision@3 0.2225
cosine_precision@5 0.1496
cosine_precision@10 0.0821
cosine_recall@1 0.4839
cosine_recall@3 0.6674
cosine_recall@5 0.7481
cosine_recall@10 0.821
cosine_ndcg@10 0.6487
cosine_mrr@10 0.5939
cosine_map@100 0.6001

Information Retrieval

Metric Value
cosine_accuracy@1 0.4462
cosine_accuracy@3 0.6382
cosine_accuracy@5 0.7158
cosine_accuracy@10 0.7988
cosine_precision@1 0.4462
cosine_precision@3 0.2127
cosine_precision@5 0.1432
cosine_precision@10 0.0799
cosine_recall@1 0.4462
cosine_recall@3 0.6382
cosine_recall@5 0.7158
cosine_recall@10 0.7988
cosine_ndcg@10 0.6178
cosine_mrr@10 0.5604
cosine_map@100 0.5667

Training Details

Training Dataset

Unnamed Dataset

  • Size: 11,711 training samples
  • Columns: Câu hỏi and Câu trả lời
  • Approximate statistics based on the first 1000 samples:
    Câu hỏi Câu trả lời
    type string string
    details
    • min: 6 tokens
    • mean: 38.26 tokens
    • max: 256 tokens
    • min: 4 tokens
    • mean: 143.99 tokens
    • max: 256 tokens
  • Samples:
    Câu hỏi Câu trả lời
    Phòng thử nghiệm của tổ chức, doanh nghiệp chỉ thực hiện hoạt động thử nghiệm phục vụ kiểm soát chất lượng sản phẩm do chính tổ chức, doanh nghiệp sản xuất ra thì có phải thực hiện đăng ký hoạt động thử nghiệm theo Nghị định số 107/2016/NĐ-CP không? Tại khoản 1 Điều 2 Nghị định số 107/2016/NĐ-CP quy định Nghị định này áp dụng đối với các tổ chức, doanh nghiệp có hoạt động kinh doanh dịch vụ đánh giá sự phù hợp (thử nghiệm, chứng nhận, giám định, kiểm định) trên lãnh thổ Việt Nam. Do đó, trong trường hợp này, tổ chức, doanh nghiệp không phải thực hiện đăng ký hoạt động thử nghiệm theo quy định tại Nghị định số 107/2016/NĐ-CP. Trường hợp, tổ chức, doanh nghiệp có nhu cầu cung cấp dịch vụ thử nghiệm thì phải thực hiện đăng ký hoạt động thử nghiệm theo quy định tại Nghị định số 107/2016/NĐ-CP.
    Sửa đổi, bổ sung Giấy chứng nhận đủ điều kiện hoạt động điểm cung cấp dịch vụ trò chơi điện tử công cộng trong trường hợp nào?; cách thức thực hiện như thế nào; thời gian thực thực hiện trong bao lâu? Sửa đổi, bổ sung trong thời hạn hiệu lực của Giấy chứng nhận đủ điều kiện hoạt động điểm cung cấp dịch vụ trò chơi điện tử công cộng, chủ điểm cung cấp dịch vụ trò chơi điện tử công cộng phải làm thủ tục sửa đổi, bổ sung giấy chứng nhận đủ điều kiện hoạt động điểm cung cấp dịch vụ trò chơi điện tử công cộng đã được cấp thuộc một trong các trường hợp sau đây: Thay đổi tên điểm cung cấp dịch vụ trò chơi điện tử công cộng; Thay đổi chủ điểm cung cấp dịch vụ trò chơi điện tử công cộng đối với trường hợp chủ điểm là cá nhân hoặc thay đổi người quản lý trực tiếp điểm cung cấp dịch vụ trò chơi điện tử công cộng đối với trường hợp chủ điểm là tổ chức, doanh nghiệp; Cách thức thực hiện: cá nhân có thể gửi hồ sơ trực tiếp hoặc gửi trực tuyến qua cổng dịch vụ công tỉnh Hà Giang; Thời gian thực hiện trong 05 ngày làm việc, kể từ ngày nhận đủ hồ sơ hợp lệ.
    Đối với trường hợp đại lý đã được cấp trước đây có được phép hoạt động đến hết thời hạn trong Giấy chứng nhận đủ điều kiện kinh doanh dược không? Hay hướng dẫn các đại lý chuyển đổi qua quầy thuốc ngay khi Nghị định 54/2017/NĐ-CP ngày 08/5/2017 của Chính phủ có hiệu lực? Theo quy định của Luật Dược 2016 không còn loại hình bán lẻ thuốc là đại lý thuốc. Khoản 1 Điều 115 Luật dược quy định về điều khoản chuyển tiếp, theo đó:“Cơ sở kinh doanh dược đã được cấp Giấy chứng nhận đủ điều kiện kinh doanh dượctheo quy định của Luật dược 34/2005/QH11 được tiếp tục kinh doanh thuốc cho đếnhết thời hạn hiệu lực của Giấy chứng nhận đủ điều kiện kinh doanh dược”. Nhưvậy, các đại lý bán lẻ thuốc đã được cấp Giấy chứng nhận đủ điều kiện kinhdoanh dược được phép hoạt động đến hết thời hạn ghi trên Giấy chứng nhận đủđiều kiện kinh doanh dược. Việc các đại lý muốn chuyển đổi thành quầy thuốc thìphải đáp ứng các quy định về điều kiện và địa bàn hoạt động đối với quầy thuốc
  • Loss: MatryoshkaLoss with these parameters:
    {
        "loss": "MultipleNegativesRankingLoss",
        "matryoshka_dims": [
            768,
            512,
            256,
            128,
            64
        ],
        "matryoshka_weights": [
            1,
            1,
            1,
            1,
            1
        ],
        "n_dims_per_step": -1
    }
    

Training Hyperparameters

Non-Default Hyperparameters

  • eval_strategy: epoch
  • per_device_train_batch_size: 32
  • per_device_eval_batch_size: 16
  • gradient_accumulation_steps: 32
  • learning_rate: 2e-05
  • num_train_epochs: 15
  • lr_scheduler_type: cosine
  • warmup_ratio: 0.1
  • fp16: True
  • tf32: False
  • load_best_model_at_end: True
  • optim: adamw_torch_fused
  • batch_sampler: no_duplicates

All Hyperparameters

Click to expand
  • overwrite_output_dir: False
  • do_predict: False
  • eval_strategy: epoch
  • prediction_loss_only: True
  • per_device_train_batch_size: 32
  • per_device_eval_batch_size: 16
  • per_gpu_train_batch_size: None
  • per_gpu_eval_batch_size: None
  • gradient_accumulation_steps: 32
  • eval_accumulation_steps: None
  • learning_rate: 2e-05
  • weight_decay: 0.0
  • adam_beta1: 0.9
  • adam_beta2: 0.999
  • adam_epsilon: 1e-08
  • max_grad_norm: 1.0
  • num_train_epochs: 15
  • max_steps: -1
  • lr_scheduler_type: cosine
  • lr_scheduler_kwargs: {}
  • warmup_ratio: 0.1
  • warmup_steps: 0
  • log_level: passive
  • log_level_replica: warning
  • log_on_each_node: True
  • logging_nan_inf_filter: True
  • save_safetensors: True
  • save_on_each_node: False
  • save_only_model: False
  • restore_callback_states_from_checkpoint: False
  • no_cuda: False
  • use_cpu: False
  • use_mps_device: False
  • seed: 42
  • data_seed: None
  • jit_mode_eval: False
  • use_ipex: False
  • bf16: False
  • fp16: True
  • fp16_opt_level: O1
  • half_precision_backend: auto
  • bf16_full_eval: False
  • fp16_full_eval: False
  • tf32: False
  • local_rank: 0
  • ddp_backend: None
  • tpu_num_cores: None
  • tpu_metrics_debug: False
  • debug: []
  • dataloader_drop_last: False
  • dataloader_num_workers: 0
  • dataloader_prefetch_factor: None
  • past_index: -1
  • disable_tqdm: False
  • remove_unused_columns: True
  • label_names: None
  • load_best_model_at_end: True
  • ignore_data_skip: False
  • fsdp: []
  • fsdp_min_num_params: 0
  • fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}
  • fsdp_transformer_layer_cls_to_wrap: None
  • accelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}
  • deepspeed: None
  • label_smoothing_factor: 0.0
  • optim: adamw_torch_fused
  • optim_args: None
  • adafactor: False
  • group_by_length: False
  • length_column_name: length
  • ddp_find_unused_parameters: None
  • ddp_bucket_cap_mb: None
  • ddp_broadcast_buffers: False
  • dataloader_pin_memory: True
  • dataloader_persistent_workers: False
  • skip_memory_metrics: True
  • use_legacy_prediction_loop: False
  • push_to_hub: False
  • resume_from_checkpoint: None
  • hub_model_id: None
  • hub_strategy: every_save
  • hub_private_repo: False
  • hub_always_push: False
  • gradient_checkpointing: False
  • gradient_checkpointing_kwargs: None
  • include_inputs_for_metrics: False
  • eval_do_concat_batches: True
  • fp16_backend: auto
  • push_to_hub_model_id: None
  • push_to_hub_organization: None
  • mp_parameters:
  • auto_find_batch_size: False
  • full_determinism: False
  • torchdynamo: None
  • ray_scope: last
  • ddp_timeout: 1800
  • torch_compile: False
  • torch_compile_backend: None
  • torch_compile_mode: None
  • dispatch_batches: None
  • split_batches: None
  • include_tokens_per_second: False
  • include_num_input_tokens_seen: False
  • neftune_noise_alpha: None
  • optim_target_modules: None
  • batch_eval_metrics: False
  • batch_sampler: no_duplicates
  • multi_dataset_batch_sampler: proportional

Training Logs

Epoch Step Training Loss dim_128_cosine_map@100 dim_256_cosine_map@100 dim_512_cosine_map@100 dim_64_cosine_map@100 dim_768_cosine_map@100
0.8743 10 3.9132 - - - - -
0.9617 11 - 0.4759 0.5066 0.5205 0.4333 0.5227
1.7486 20 2.3057 - - - - -
1.9235 22 - 0.5345 0.5541 0.5686 0.4968 0.5756
2.6230 30 1.3986 - - - - -
2.9727 34 - 0.5586 0.5826 0.5958 0.5223 0.5979
3.4973 40 0.954 - - - - -
3.9344 45 - 0.5739 0.5948 0.6079 0.5370 0.6066
4.3716 50 0.6417 - - - - -
4.9836 57 - 0.5865 0.6066 0.6135 0.5488 0.6152
5.2459 60 0.4711 - - - - -
5.9454 68 - 0.5898 0.6140 0.6170 0.5572 0.6196
6.1202 70 0.3451 - - - - -
6.9945 80 0.2679 0.5957 0.6118 0.6212 0.5627 0.6210
7.8689 90 0.2066 - - - - -
7.9563 91 - 0.5973 0.6140 0.6253 0.5643 0.6268
8.7432 100 0.1844 - - - - -
8.9180 102 - 0.5971 0.6189 0.6271 0.5621 0.6281
9.6175 110 0.1604 - - - - -
9.9672 114 - 0.5993 0.6190 0.6273 0.5646 0.6307
10.4918 120 0.1507 - - - - -
10.9290 125 - 0.5976 0.6181 0.6258 0.5668 0.6305
11.3661 130 0.1307 - - - - -
11.9781 137 - 0.5990 0.6166 0.6251 0.5671 0.6318
12.2404 140 0.1275 - - - - -
12.9399 148 - 0.6002 0.6174 0.6259 0.5665 0.6314
13.1148 150 0.1204 - - - - -
13.9891 160 0.1227 0.6004 0.6176 0.6253 0.5668 0.6316
14.4262 165 - 0.6001 0.6182 0.6252 0.5667 0.6315
  • The bold row denotes the saved checkpoint.

Framework Versions

  • Python: 3.10.13
  • Sentence Transformers: 3.0.1
  • Transformers: 4.41.2
  • PyTorch: 2.1.2
  • Accelerate: 0.30.1
  • Datasets: 2.19.1
  • Tokenizers: 0.19.1

Citation

BibTeX

Sentence Transformers

@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",
}

MatryoshkaLoss

@misc{kusupati2024matryoshka,
    title={Matryoshka Representation Learning}, 
    author={Aditya Kusupati and Gantavya Bhatt and Aniket Rege and Matthew Wallingford and Aditya Sinha and Vivek Ramanujan and William Howard-Snyder and Kaifeng Chen and Sham Kakade and Prateek Jain and Ali Farhadi},
    year={2024},
    eprint={2205.13147},
    archivePrefix={arXiv},
    primaryClass={cs.LG}
}

MultipleNegativesRankingLoss

@misc{henderson2017efficient,
    title={Efficient Natural Language Response Suggestion for Smart Reply}, 
    author={Matthew Henderson and Rami Al-Rfou and Brian Strope and Yun-hsuan Sung and Laszlo Lukacs and Ruiqi Guo and Sanjiv Kumar and Balint Miklos and Ray Kurzweil},
    year={2017},
    eprint={1705.00652},
    archivePrefix={arXiv},
    primaryClass={cs.CL}
}
Downloads last month
455
Safetensors
Model size
135M params
Tensor type
F32
·

Finetuned from

Evaluation results