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("huyydangg/thuvienphapluat_embedding_v7")
sentences = [
'người lao_động muốn đơn_phương chấm_dứt hợp_đồng lao_động đúng pháp_luật cần báo trước bao_lâu theo quy_định đối_với hợp_đồng xác_định thời_hạn và hợp_đồng không xác_định thời_hạn ? nếu người lao_động báo trước nghỉ_việc sớm hơn thời_gian quy_định thì có ảnh_hưởng gì không ? ví_dụ , trường_hợp ngày 01 / 03 báo nghỉ_việc nhưng ngày 05 / 03 nghỉ thật thì có phải bồi_thường không ? trong trường_hợp đơn_phương chấm_dứt hợp_đồng lao_động trái pháp_luật , người lao_động sẽ bị ảnh_hưởng những gì ? người sử_dụng lao_động có phải trả sổ bảo_hiểm và giấy_tờ khác cho người lao_động khi chấm_dứt hợp_đồng lao_động , kể_cả khi chấm_dứt trái pháp_luật , không ? quy_định bao_lâu phải trả những giấy_tờ này ? nếu người sử_dụng lao_động không trả , người lao_động dựa vào căn_cứ pháp_lý nào để yêu_cầu trả lại ? việc chấm_dứt hợp_đồng lao_động trong trường_hợp trên ảnh_hưởng đến quyền_lợi bảo_hiểm xã_hội ( bảo_hiểm xã_hội ) như thế_nào ?',
'quy_định về đơn_phương chấm_dứt hợp_đồng lao_động , nghĩa_vụ bồi_thường , trả giấy_tờ liên_quan và ảnh_hưởng đến quyền_lợi bảo_hiểm xã_hội tại việt_nam',
'quy_định pháp_luật về chế_độ nghỉ_mát cho người lao_động tại công_ty thư_viện pháp_luật',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
similarities = model.similarity(embeddings, embeddings)
print(similarities)
Evaluation
Metrics
Information Retrieval
Metric |
Value |
cosine_accuracy@1 |
0.7313 |
cosine_accuracy@3 |
0.8409 |
cosine_accuracy@5 |
0.8711 |
cosine_accuracy@10 |
0.906 |
cosine_precision@1 |
0.7313 |
cosine_precision@3 |
0.2803 |
cosine_precision@5 |
0.1742 |
cosine_precision@10 |
0.0906 |
cosine_recall@1 |
0.7313 |
cosine_recall@3 |
0.8409 |
cosine_recall@5 |
0.8711 |
cosine_recall@10 |
0.906 |
cosine_ndcg@10 |
0.82 |
cosine_mrr@10 |
0.7924 |
cosine_map@100 |
0.7954 |
Information Retrieval
Metric |
Value |
cosine_accuracy@1 |
0.7253 |
cosine_accuracy@3 |
0.8363 |
cosine_accuracy@5 |
0.8683 |
cosine_accuracy@10 |
0.9033 |
cosine_precision@1 |
0.7253 |
cosine_precision@3 |
0.2788 |
cosine_precision@5 |
0.1737 |
cosine_precision@10 |
0.0903 |
cosine_recall@1 |
0.7253 |
cosine_recall@3 |
0.8363 |
cosine_recall@5 |
0.8683 |
cosine_recall@10 |
0.9033 |
cosine_ndcg@10 |
0.8158 |
cosine_mrr@10 |
0.7876 |
cosine_map@100 |
0.7907 |
Information Retrieval
Metric |
Value |
cosine_accuracy@1 |
0.7141 |
cosine_accuracy@3 |
0.8262 |
cosine_accuracy@5 |
0.8597 |
cosine_accuracy@10 |
0.8965 |
cosine_precision@1 |
0.7141 |
cosine_precision@3 |
0.2754 |
cosine_precision@5 |
0.1719 |
cosine_precision@10 |
0.0896 |
cosine_recall@1 |
0.7141 |
cosine_recall@3 |
0.8262 |
cosine_recall@5 |
0.8597 |
cosine_recall@10 |
0.8965 |
cosine_ndcg@10 |
0.8065 |
cosine_mrr@10 |
0.7776 |
cosine_map@100 |
0.7808 |
Information Retrieval
Metric |
Value |
cosine_accuracy@1 |
0.6954 |
cosine_accuracy@3 |
0.81 |
cosine_accuracy@5 |
0.8444 |
cosine_accuracy@10 |
0.8817 |
cosine_precision@1 |
0.6954 |
cosine_precision@3 |
0.27 |
cosine_precision@5 |
0.1689 |
cosine_precision@10 |
0.0882 |
cosine_recall@1 |
0.6954 |
cosine_recall@3 |
0.81 |
cosine_recall@5 |
0.8444 |
cosine_recall@10 |
0.8817 |
cosine_ndcg@10 |
0.7897 |
cosine_mrr@10 |
0.7601 |
cosine_map@100 |
0.7637 |
Information Retrieval
Metric |
Value |
cosine_accuracy@1 |
0.6646 |
cosine_accuracy@3 |
0.7825 |
cosine_accuracy@5 |
0.82 |
cosine_accuracy@10 |
0.8617 |
cosine_precision@1 |
0.6646 |
cosine_precision@3 |
0.2608 |
cosine_precision@5 |
0.164 |
cosine_precision@10 |
0.0862 |
cosine_recall@1 |
0.6646 |
cosine_recall@3 |
0.7825 |
cosine_recall@5 |
0.82 |
cosine_recall@10 |
0.8617 |
cosine_ndcg@10 |
0.7635 |
cosine_mrr@10 |
0.732 |
cosine_map@100 |
0.7359 |
Training Details
Training Dataset
json
- Dataset: json
- Size: 186,840 training samples
- Columns:
anchor
and positive
- Approximate statistics based on the first 1000 samples:
|
anchor |
positive |
type |
string |
string |
details |
- min: 4 tokens
- mean: 44.83 tokens
- max: 256 tokens
|
- min: 6 tokens
- mean: 19.54 tokens
- max: 71 tokens
|
- Samples:
anchor |
positive |
trên giấy_tờ đất có chiều ngang 7 m , nhà có làm giấy tay cam_kết “ chừa 1 lối đi 1 m đến cuối đất ” cho hàng_xóm tiện đường vào thăm mộ , có quyền không chừa 1 m đó được không ? |
quyền và nghĩa_vụ về chừa lối đi trên đất theo thỏa_thuận dân_sự |
chế_độ nghỉ thai_sản khi nghỉ trùng với thời_gian nghỉ_hè ? |
xử_lý chế_độ nghỉ thai_sản khi trùng với thời_gian nghỉ_hè theo pháp_luật việt_nam |
hành_vi lùi xe ô_tô không có tín_hiệu báo trước sẽ bị xử_phạt bao_nhiêu ? |
lùi xe ô_tô không có tín_hiệu báo trước sẽ bị xử_phạt bao_nhiêu ? |
- 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: 23,356 evaluation samples
- Columns:
anchor
and positive
- Approximate statistics based on the first 1000 samples:
|
anchor |
positive |
type |
string |
string |
details |
- min: 4 tokens
- mean: 46.01 tokens
- max: 256 tokens
|
- min: 5 tokens
- mean: 19.13 tokens
- max: 68 tokens
|
- Samples:
anchor |
positive |
vi_phạm về hàng_hóa nhập lậu theo quy_định tại khoản 5 điều 15 nghị_định 98 / 2020 / nghị_định - cp ? |
xử_lý vi_phạm liên_quan đến hàng_hóa nhập lậu theo khoản 5 điều 15 nghị_định 98 / 2020 / nghị_định - cp |
doanh_nghiệp có phải tính thêm 0.5 tiếng nghỉ_ngơi cho người lao_động và ghi_nhận làm thêm giờ là 2.5 tiếng trong trường_hợp nhân_viên làm thêm tới 19 : 00 và không nghỉ_ngơi mà về luôn , theo quy_định tại điều 5 về nghỉ trong giờ làm_việc ? |
quy_định về tính giờ nghỉ_ngơi và làm thêm giờ theo bộ_luật lao_động việt_nam |
trong vụ án hình_sự về ma_túy , đối_tượng liên_quan qua lấy lời khai bị phát_hiện sử_dụng trái_phép chất ma_túy , trong trường_hợp này có phải lập biên_bản vi_phạm hành_chính không , nếu có thì mẫu biên_bản hiện được sử_dụng là mẫu nào ? mẫu quyết_định xử_phạt hiện được sử_dụng là mẫu nào ? |
quy_định lập biên_bản và quyết_định xử_phạt hành_chính khi người liên_quan trong vụ án hình_sự về ma_túy bị phát_hiện sử_dụng trái_phép chất ma_túy |
- 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 |
649 |
0.1555 |
0.0598 |
0.7979 |
0.7951 |
0.7828 |
0.7554 |
0.7122 |
2.0 |
1298 |
0.052 |
0.0512 |
0.8034 |
0.8003 |
0.7911 |
0.7703 |
0.7323 |
3.0 |
1947 |
0.0298 |
0.0496 |
0.8155 |
0.8129 |
0.805 |
0.7892 |
0.7564 |
4.0 |
2596 |
0.0207 |
0.0519 |
0.8200 |
0.8158 |
0.8065 |
0.7897 |
0.7635 |
- 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}
}