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:
- 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
model = SentenceTransformer("sentence_transformers_model_id")
sentences = [
'Ngân_hàng hợp_tác_xã có nhu_cầu thành_lập chi_nhánh để làm gì ?',
'Thông_tư 09 / 2018 / TT - NHNN quy_định về mạng_lưới hoạt_động của tổ_chức tín_dụng là hợp_tác_xã do Ngân_hàng Nhà_nước Việt_Nam ban_hành Điều 10 Điều_kiện thành_lập chi_nhánh Khoản 1 Có nhu_cầu thành_lập chi_nhánh để phục_vụ các quỹ tín_dụng nhân_dân trên địa_bàn dự_kiến thành_lập chi_nhánh .',
'Vừa_rồi Tôi và em_trai có ra vịnh gần nhà và có đánh_bắt khoảng trên 20kg cá_bỗng , và đã bị lập biên_bản về hành_vi này anh_chị cho tôi hỏi trường_hợp này gia_đình tôi sẽ bị xử_phạt như thế_nào ? Tôi cảm_ơn rất nhiều .',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
similarities = model.similarity(embeddings, embeddings)
print(similarities)
Evaluation
Metrics
Information Retrieval
| Metric |
Value |
| cosine_accuracy@1 |
0.4284 |
| cosine_accuracy@3 |
0.5928 |
| cosine_accuracy@5 |
0.6512 |
| cosine_accuracy@10 |
0.7233 |
| cosine_precision@1 |
0.4284 |
| cosine_precision@3 |
0.1976 |
| cosine_precision@5 |
0.1302 |
| cosine_precision@10 |
0.0723 |
| cosine_recall@1 |
0.4284 |
| cosine_recall@3 |
0.5928 |
| cosine_recall@5 |
0.6512 |
| cosine_recall@10 |
0.7233 |
| cosine_ndcg@10 |
0.572 |
| cosine_mrr@10 |
0.524 |
| cosine_map@100 |
0.5316 |
Information Retrieval
| Metric |
Value |
| cosine_accuracy@1 |
0.427 |
| cosine_accuracy@3 |
0.5922 |
| cosine_accuracy@5 |
0.6504 |
| cosine_accuracy@10 |
0.7216 |
| cosine_precision@1 |
0.427 |
| cosine_precision@3 |
0.1974 |
| cosine_precision@5 |
0.1301 |
| cosine_precision@10 |
0.0722 |
| cosine_recall@1 |
0.427 |
| cosine_recall@3 |
0.5922 |
| cosine_recall@5 |
0.6504 |
| cosine_recall@10 |
0.7216 |
| cosine_ndcg@10 |
0.5706 |
| cosine_mrr@10 |
0.5227 |
| cosine_map@100 |
0.5303 |
Information Retrieval
| Metric |
Value |
| cosine_accuracy@1 |
0.4201 |
| cosine_accuracy@3 |
0.5871 |
| cosine_accuracy@5 |
0.6474 |
| cosine_accuracy@10 |
0.7165 |
| cosine_precision@1 |
0.4201 |
| cosine_precision@3 |
0.1957 |
| cosine_precision@5 |
0.1295 |
| cosine_precision@10 |
0.0716 |
| cosine_recall@1 |
0.4201 |
| cosine_recall@3 |
0.5871 |
| cosine_recall@5 |
0.6474 |
| cosine_recall@10 |
0.7165 |
| cosine_ndcg@10 |
0.5649 |
| cosine_mrr@10 |
0.5167 |
| cosine_map@100 |
0.5245 |
Information Retrieval
| Metric |
Value |
| cosine_accuracy@1 |
0.414 |
| cosine_accuracy@3 |
0.5765 |
| cosine_accuracy@5 |
0.6385 |
| cosine_accuracy@10 |
0.7102 |
| cosine_precision@1 |
0.414 |
| cosine_precision@3 |
0.1922 |
| cosine_precision@5 |
0.1277 |
| cosine_precision@10 |
0.071 |
| cosine_recall@1 |
0.414 |
| cosine_recall@3 |
0.5765 |
| cosine_recall@5 |
0.6385 |
| cosine_recall@10 |
0.7102 |
| cosine_ndcg@10 |
0.5579 |
| cosine_mrr@10 |
0.5096 |
| cosine_map@100 |
0.5172 |
Information Retrieval
| Metric |
Value |
| cosine_accuracy@1 |
0.3983 |
| cosine_accuracy@3 |
0.5587 |
| cosine_accuracy@5 |
0.6187 |
| cosine_accuracy@10 |
0.6915 |
| cosine_precision@1 |
0.3983 |
| cosine_precision@3 |
0.1862 |
| cosine_precision@5 |
0.1237 |
| cosine_precision@10 |
0.0691 |
| cosine_recall@1 |
0.3983 |
| cosine_recall@3 |
0.5587 |
| cosine_recall@5 |
0.6187 |
| cosine_recall@10 |
0.6915 |
| cosine_ndcg@10 |
0.5402 |
| cosine_mrr@10 |
0.4923 |
| cosine_map@100 |
0.5004 |
Training Details
Training Dataset
json
- Dataset: json
- Size: 162,512 training samples
- Columns:
anchor and positive
- Approximate statistics based on the first 1000 samples:
|
anchor |
positive |
| type |
string |
string |
| details |
- min: 5 tokens
- mean: 17.43 tokens
- max: 138 tokens
|
- min: 5 tokens
- mean: 93.7 tokens
- max: 256 tokens
|
- Samples:
| anchor |
positive |
Có được ghi_nhận chi_phí cước đường_bộ của theo hoá_đơn của bên thuê xe ? |
Công_ty A sử_dụng dịch_vụ thuê xe theo tháng của công_ty B. Công_ty B có nhận được hóa đơn đầu_vào là cước đường_bộ . Vậy công_ty A có được ghi_nhận chi_phí hợp_lý cho các hóa_đơn cước đường_bộ này không ? |
Làm thêm có phải đóng BHXH không ? |
Luật Bảo_hiểm xã_hội 2014 Điều 85 Mức đóng và phương_thức đóng của người lao_động tham_gia_bảo_hiểm xã_hội bắt_buộc Khoản 3 Người lao_động không làm_việc và không hưởng tiền_lương từ 14 ngày làm_việc trở lên trong tháng thì không đóng bảo_hiểm xã_hội tháng đó . Thời_gian này không được tính để hưởng bảo_hiểm xã_hội , trừ trường_hợp nghỉ_việc hưởng chế_độ thai_sản . |
Chủ đầu_tư tự_lập hồ_sơ thiết_kế có cần phải có chứng_chỉ năng_lực không ? |
1 / Chủ đầu_tư tự_lập hồ_sơ thiết_kế báo_cáo kinh_tế kỹ_thuật thì yêu_cầu phải có chứng_chỉ hành_nghề không ? hay_là chỉ cần nhân_viên có bằng kỹ_sư theo đúng chuyên_ngành ? 2 / Trong trường_hợp chủ đầu_tư tự_lập hồ_sơ thiết_kế báo_cáo kinh_tế kỹ_thuật có được thực_hiện gói_thầu thi_công theo hình_thức tự thực_hiện không ? Kính nhờ LVPL tư_vấn giúp . |
- 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: 20,315 evaluation samples
- Columns:
anchor and positive
- Approximate statistics based on the first 1000 samples:
|
anchor |
positive |
| type |
string |
string |
| details |
- min: 5 tokens
- mean: 17.13 tokens
- max: 94 tokens
|
- min: 5 tokens
- mean: 94.98 tokens
- max: 256 tokens
|
- Samples:
| anchor |
positive |
Chính_sách bồi_thường , giải_phóng mặt_bằng đối_với dự_án trạm biến_áp theo pháp_luật Việt_Nam |
Chính_sách bồi_thường , giải_phóng mặt_bằng của dự_án trạm biến_áp đi qua phần đất của gia_đình có được pháp_luật quy_định không hay chỉ là thỏa_thuận giữa người dân và chủ đầu_tư dự_án ? |
Chi_phí nhận tiền USD hoặc phí ngân_hàng ngoại_tệ sẽ ghi theo tỷ_giá nào ? |
Khi em giao_dịch phát_sinh chi_phí nhận tiền USD hoặc phí ngân_hàng ngoại_tệ thì em đọc theo Thông_tư 200 / 2014 / TT - BTC thì tỷ_giá ghi_nhận là tỷ_giá bán của ngân_hàng phải không ? |
Đơn_vị sự_nghiệp có được ban_hành danh_mục mua_sắm tập_trung không ? |
Đơn_vị sự_nghiệp có tự ban_hành danh_mục mua_sắm tập_trung để thực_hiện việc mua_sắm theo phương_thức tập_trung được hay không
|
- 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 |
565 |
0.4082 |
0.1543 |
0.5250 |
0.5228 |
0.5179 |
0.5031 |
0.4774 |
| 2.0 |
1130 |
0.1442 |
0.1137 |
0.5340 |
0.5311 |
0.5238 |
0.5085 |
0.4847 |
| 3.0 |
1695 |
0.0898 |
0.0849 |
0.5440 |
0.5426 |
0.5361 |
0.5245 |
0.5034 |
| 4.0 |
2260 |
0.0612 |
0.0819 |
0.5458 |
0.5442 |
0.5378 |
0.5280 |
0.5063 |
| 5.0 |
2825 |
0.048 |
0.0778 |
0.5490 |
0.5463 |
0.5408 |
0.5323 |
0.5133 |
| 6.0 |
3390 |
0.0415 |
0.0679 |
0.5685 |
0.567 |
0.5614 |
0.5525 |
0.5331 |
| 7.0 |
3955 |
0.0324 |
0.0690 |
0.5720 |
0.5706 |
0.5649 |
0.5579 |
0.5402 |
- The bold row denotes the saved checkpoint.
Framework Versions
- Python: 3.10.12
- Sentence Transformers: 5.1.0
- Transformers: 4.55.0
- 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}
}