bkai-fine-tuned-legal

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

Model Details

Model Description

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

Model Sources

Full Model Architecture

SentenceTransformer(
  (0): Transformer({'max_seq_length': 256, 'do_lower_case': False, 'architecture': '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("huyydangg/thuvienphapluat_embedding_v6")
# Run inference
sentences = [
    'cho mình hỏi về cách tính thanh_toán tiền_lương làm tăng giờ đối_với công_chức nhà_nước . tiền_lương một tháng để tính tăng giờ có bao_gồm phụ_cấp không ?',
    'tiền_lương để tính tăng giờ đối_với công_chức có bao_gồm phụ_cấp không ?',
    'trách_nhiệm pháp_lý của người sử_dụng lao_động khi người lao_động tử_vong do tai_nạn giao_thông trong quá_trình làm_việc " , " quyền_lợi của người lao_động tử_vong do tai_nạn lao_động ngoài trụ_sở làm_việc',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 768]

# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[ 1.0000,  0.8958, -0.1026],
#         [ 0.8958,  1.0000, -0.0500],
#         [-0.1026, -0.0500,  1.0000]])

Evaluation

Metrics

Information Retrieval

Metric Value
cosine_accuracy@1 0.7492
cosine_accuracy@3 0.8526
cosine_accuracy@5 0.8839
cosine_accuracy@10 0.9138
cosine_precision@1 0.7492
cosine_precision@3 0.2842
cosine_precision@5 0.1768
cosine_precision@10 0.0914
cosine_recall@1 0.7492
cosine_recall@3 0.8526
cosine_recall@5 0.8839
cosine_recall@10 0.9138
cosine_ndcg@10 0.8333
cosine_mrr@10 0.8073
cosine_map@100 0.81

Information Retrieval

Metric Value
cosine_accuracy@1 0.7454
cosine_accuracy@3 0.8508
cosine_accuracy@5 0.8808
cosine_accuracy@10 0.9114
cosine_precision@1 0.7454
cosine_precision@3 0.2836
cosine_precision@5 0.1762
cosine_precision@10 0.0911
cosine_recall@1 0.7454
cosine_recall@3 0.8508
cosine_recall@5 0.8808
cosine_recall@10 0.9114
cosine_ndcg@10 0.8303
cosine_mrr@10 0.8041
cosine_map@100 0.8069

Information Retrieval

Metric Value
cosine_accuracy@1 0.7381
cosine_accuracy@3 0.8438
cosine_accuracy@5 0.8738
cosine_accuracy@10 0.9067
cosine_precision@1 0.7381
cosine_precision@3 0.2813
cosine_precision@5 0.1748
cosine_precision@10 0.0907
cosine_recall@1 0.7381
cosine_recall@3 0.8438
cosine_recall@5 0.8738
cosine_recall@10 0.9067
cosine_ndcg@10 0.8239
cosine_mrr@10 0.7972
cosine_map@100 0.8001

Information Retrieval

Metric Value
cosine_accuracy@1 0.7227
cosine_accuracy@3 0.8283
cosine_accuracy@5 0.8625
cosine_accuracy@10 0.8983
cosine_precision@1 0.7227
cosine_precision@3 0.2761
cosine_precision@5 0.1725
cosine_precision@10 0.0898
cosine_recall@1 0.7227
cosine_recall@3 0.8283
cosine_recall@5 0.8625
cosine_recall@10 0.8983
cosine_ndcg@10 0.8112
cosine_mrr@10 0.7832
cosine_map@100 0.7863

Information Retrieval

Metric Value
cosine_accuracy@1 0.6948
cosine_accuracy@3 0.804
cosine_accuracy@5 0.8423
cosine_accuracy@10 0.8802
cosine_precision@1 0.6948
cosine_precision@3 0.268
cosine_precision@5 0.1685
cosine_precision@10 0.088
cosine_recall@1 0.6948
cosine_recall@3 0.804
cosine_recall@5 0.8423
cosine_recall@10 0.8802
cosine_ndcg@10 0.7874
cosine_mrr@10 0.7577
cosine_map@100 0.7613

Training Details

Training Dataset

json

  • Dataset: json
  • Size: 172,688 training samples
  • Columns: anchor and positive
  • Approximate statistics based on the first 1000 samples:
    anchor positive
    type string string
    details
    • min: 5 tokens
    • mean: 47.78 tokens
    • max: 256 tokens
    • min: 4 tokens
    • mean: 19.27 tokens
    • max: 80 tokens
  • Samples:
    anchor positive
    hàng_hóa có tổng_trị_giá hải_quan bao_nhiêu thì được miễn thuế_xuất_khẩu , thuế_nhập_khẩu ? tổng_trị_giá hải_quan được miễn thuế_xuất_khẩu , thuế_nhập_khẩu
    mình thanh_toán phí sửa_chữa cho nước_ngoài thì thanh_toán thuế nhà_thầu gồm mục nào , khi sửa_chữa máy_móc thực_hiện_tại việt_nam ? quy_định về thuế nhà_thầu đối_với thanh_toán phí sửa_chữa máy_móc cho nhà_thầu nước_ngoài tại việt_nam
    đồng_hồ điện nhà tôi và 2 hộ khác đang gắn trên trụ điện ở đất của một nhà hàng_xóm ( trụ điện này đã có từ lâu ) . nay nhà đó yêu_cầu chúng_tôi dời đồng_hồ điện đi chỗ khác với lý_do dây_điện trong đất nhà họ , họ sợ bị điện giật . việc họ bắt người khác dời đồng_hồ điện như_vậy có đúng quy_định pháp_luật hay không ? và nếu chủ nhà có cột điện như_vậy thì xử_lý ra sao ? quyền và nghĩa_vụ liên_quan đến vị_trí lắp_đặt đồng_hồ điện trên trụ điện đặt trên đất của người khác và biện_pháp xử_lý theo pháp_luật việt_nam
  • Loss: MatryoshkaLoss with these parameters:
    {
        "loss": "CachedMultipleNegativesSymmetricRankingLoss",
        "matryoshka_dims": [
            768,
            512,
            256,
            128,
            64
        ],
        "matryoshka_weights": [
            1,
            1,
            1,
            1,
            1
        ],
        "n_dims_per_step": -1
    }
    

Evaluation Dataset

json

  • Dataset: json
  • Size: 21,586 evaluation samples
  • Columns: anchor and positive
  • Approximate statistics based on the first 1000 samples:
    anchor positive
    type string string
    details
    • min: 5 tokens
    • mean: 48.05 tokens
    • max: 256 tokens
    • min: 5 tokens
    • mean: 19.81 tokens
    • max: 105 tokens
  • Samples:
    anchor positive
    xin cung_cấp thông_tư 15 / 2022 / tt - bqp ngày 10 / 02 / 2022 của bộ_trưởng bộ quốc_phòng_ban_hành điều_lệ công_tác bảo_vệ môi_trường của quân_đội nhân_dân việt_nam văn_bản thông_tư 15 / 2022 / tt - bqp ngày 10 / 02 / 2022 về điều_lệ công_tác bảo_vệ môi_trường của quân_đội nhân_dân việt_nam
    trường_hợp bhtn là trích tiền ra nộp cho bhxh tỉnh hay là tự trích ra trả cho người lao_động luôn ? cách_thức quản_lý và chi_trả kinh_phí bảo_hiểm_thất_nghiệp tại việt_nam ( nộp vào quỹ bhxh tỉnh hay chi trực_tiếp cho người lao_động )
    cho xin thêm văn_bản pháp_lý hướng_dẫn quy_trình kỹ_thuật_số 5,6,7,8 của bộ y_tế ban_hành ? văn_bản pháp_lý hướng_dẫn quy_trình kỹ_thuật_số 5 , 6 , 7 , 8 của bộ y_tế
  • Loss: MatryoshkaLoss with these parameters:
    {
        "loss": "CachedMultipleNegativesSymmetricRankingLoss",
        "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: 12
  • per_device_eval_batch_size: 12
  • gradient_accumulation_steps: 24
  • learning_rate: 3e-05
  • weight_decay: 0.15
  • max_grad_norm: 0.65
  • num_train_epochs: 12
  • lr_scheduler_type: cosine
  • warmup_ratio: 0.15
  • fp16: True
  • load_best_model_at_end: True
  • group_by_length: True
  • 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: 12
  • per_device_eval_batch_size: 12
  • per_gpu_train_batch_size: None
  • per_gpu_eval_batch_size: None
  • gradient_accumulation_steps: 24
  • eval_accumulation_steps: None
  • torch_empty_cache_steps: None
  • learning_rate: 3e-05
  • weight_decay: 0.15
  • adam_beta1: 0.9
  • adam_beta2: 0.999
  • adam_epsilon: 1e-08
  • max_grad_norm: 0.65
  • num_train_epochs: 12
  • max_steps: -1
  • lr_scheduler_type: cosine
  • lr_scheduler_kwargs: {}
  • warmup_ratio: 0.15
  • 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: None
  • 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: True
  • 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: None
  • hub_always_push: False
  • hub_revision: None
  • gradient_checkpointing: False
  • gradient_checkpointing_kwargs: None
  • include_inputs_for_metrics: False
  • include_for_metrics: []
  • 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
  • include_tokens_per_second: False
  • include_num_input_tokens_seen: False
  • neftune_noise_alpha: None
  • optim_target_modules: None
  • batch_eval_metrics: False
  • eval_on_start: False
  • use_liger_kernel: False
  • liger_kernel_config: None
  • eval_use_gather_object: False
  • average_tokens_across_devices: False
  • prompts: None
  • batch_sampler: no_duplicates
  • multi_dataset_batch_sampler: proportional
  • router_mapping: {}
  • learning_rate_mapping: {}

Training Logs

Epoch Step Training Loss Validation Loss dim_768_cosine_ndcg@10 dim_512_cosine_ndcg@10 dim_256_cosine_ndcg@10 dim_128_cosine_ndcg@10 dim_64_cosine_ndcg@10
1.0 600 0.1485 0.0549 0.7989 0.7960 0.7876 0.7658 0.7262
2.0 1200 0.0417 0.0412 0.7845 0.7797 0.7637 0.7405 0.7100
3.0 1800 0.0223 0.0376 0.8183 0.8159 0.8074 0.7920 0.7626
4.0 2400 0.0155 0.0345 0.8057 0.8034 0.7933 0.7746 0.7482
5.0 3000 0.0125 0.0332 0.8298 0.8261 0.8184 0.8043 0.7759
6.0 3600 0.01 0.0296 0.8298 0.827 0.8188 0.8059 0.7798
7.0 4200 0.0087 0.0311 0.8333 0.8303 0.8239 0.8112 0.7874
  • The bold row denotes the saved checkpoint.

Framework Versions

  • Python: 3.10.12
  • Sentence Transformers: 5.1.0
  • Transformers: 4.55.2
  • PyTorch: 2.8.0+cu128
  • Accelerate: 1.10.0
  • Datasets: 4.0.0
  • Tokenizers: 0.21.4

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}
}
Downloads last month
26
Safetensors
Model size
135M params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for huyydangg/thuvienphapluat_embedding_v6

Finetuned
(35)
this model

Evaluation results