SentenceTransformer based on vinai/phobert-base-v2

This is a sentence-transformers model finetuned from vinai/phobert-base-v2. 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: vinai/phobert-base-v2
  • Maximum Sequence Length: 256 tokens
  • Output Dimensionality: 768 dimensions
  • Similarity Function: Cosine Similarity

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("HiImHa/phobert-bi-encoder")
# Run inference
sentences = [
    'Tôi lái_xe không giữ khoảng_cách an_toàn dẫn đến va_chạm với xe phía trước thì bị xử_phạt như_thế_nào ?',
    '[ Nghị_định 168 _ 2024 _ NĐ-CP ] > Chương II > Điều 6 . Xử_phạt , trừ điểm giấy_phép lái_xe của người điều_khiển xe ô_tô , xe chở người bốn bánh có gắn động_cơ , xe chở hàng bốn bánh có gắn động_cơ và các loại xe tương_tự xe ô_tô vi_phạm quy_tắc giao_thông đường_bộ Theo Khoản 4 : Phạt tiền từ 2.000.000 đồng đến 3.000.000 đồng đối_với người điều_khiển xe thực_hiện một trong các hành_vi vi_phạm sau đây : Nội_dung Điểm l : Không giữ khoảng_cách an_toàn để xảy ra va_chạm với xe chạy liền trước hoặc không giữ khoảng_cách theo quy_định của biển_báo hiệu “ Cự_ly tối_thiểu giữa hai xe ” , trừ các hành_vi vi_phạm quy_định tại điểm d khoản 5 Điều này .',
    '[ Thông_tư 38 _ 2024 _ TT-BGTVT ] > Chương I > Điều 2 . Đối_tượng áp_dụng Nội_dung : Thông_tư này áp_dụng đối_với người lái_xe , người điều_khiển xe_máy chuyên_dùng và tổ_chức , cá_nhân liên_quan đến quản_lý và thực_hiện các quy_định về tốc_độ thiết_kế , tốc_độ khai_thác của đường_bộ và khoảng_cách an_toàn của xe_cơ_giới , xe_máy chuyên_dùng khi tham_gia giao_thông trên đường_bộ .',
]
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.8185, 0.1573],
#         [0.8185, 1.0000, 0.1459],
#         [0.1573, 0.1459, 1.0000]])

Evaluation

Metrics

Information Retrieval

Metric Value
cosine_accuracy@1 0.2298
cosine_accuracy@3 0.5875
cosine_accuracy@5 0.689
cosine_accuracy@10 0.7943
cosine_precision@1 0.2298
cosine_precision@3 0.1958
cosine_precision@5 0.1378
cosine_precision@10 0.0794
cosine_recall@1 0.2298
cosine_recall@3 0.5875
cosine_recall@5 0.689
cosine_recall@10 0.7943
cosine_ndcg@10 0.5122
cosine_mrr@10 0.4214
cosine_map@100 0.429

Training Details

Training Dataset

Unnamed Dataset

  • Size: 16,399 training samples
  • Columns: sentence_0 and sentence_1
  • Approximate statistics based on the first 1000 samples:
    sentence_0 sentence_1
    type string string
    details
    • min: 10 tokens
    • mean: 19.8 tokens
    • max: 36 tokens
    • min: 29 tokens
    • mean: 88.98 tokens
    • max: 250 tokens
  • Samples:
    sentence_0 sentence_1
    Những hành_vi nào của người được chở trên xe mô_tô , xe_gắn_máy bị xử_phạt từ 400.000 đến 600.000 đồng ? [ Nghị_định 168 _ 2024 _ NĐ-CP ] > Chương II > Điều 12 . Xử_phạt , trừ điểm giấy_phép lái_xe các hành_vi vi_phạm khác về quy_tắc giao_thông đường_bộ ; sử_dụng lòng_đường , vỉa_hè vào mục_đích khác Theo Khoản 5 : Phạt tiền từ 400.000 đồng đến 600.000 đồng đối_với người được chở trên xe mô_tô , xe_gắn_máy , các loại xe tương_tự xe mô_tô , các loại xe tương_tự xe_gắn_máy thực_hiện một trong các hành_vi vi_phạm sau đây : Nội_dung Điểm a : Bám , kéo , đẩy xe khác , vật khác , dẫn_dắt vật_nuôi , mang vác vật cồng_kềnh , đứng trên yên , giá đèo_hàng hoặc ngồi trên tay_lái của xe ;
    Tổng quãng đường đào_tạo thực_hành mà tôi phải đi khi nâng hạng từ B lên C là bao_nhiêu kilomet ? [ Thông_tư 35 _ 2024 _ TT-BGTVT ] > Chương I > Điều 8 . Đào_tạo nâng hạng giấy_phép lái_xe Theo Khoản 1 : Khối_lượng chương_trình và phân_bổ thời_gian đào_tạo tối_thiểu : Chi_tiết bảng ( Dòng 10 ) : SỐ TT : 3 | NỘI_DUNG : Tổng quãng đường đào_tạo thực_hành của 01 học_viên | ĐƠN_VỊ TÍNH : km | HẠNG GIẤY_PHÉP LÁI_XE - B lên C 1 : 120 | HẠNG GIẤY_PHÉP LÁI_XE - B lên C : 240 | HẠNG GIẤY_PHÉP LÁI_XE - B lên D 1 : 380 | HẠNG GIẤY_PHÉP LÁI_XE - B lên D 2 : 380 | HẠNG GIẤY_PHÉP LÁI_XE - B lên BE : 240
    Chi_phí để lập phương_án tổ_chức giao_thông cho một dự_án đường_cao_tốc mới được tính vào đâu ? [ Nghị_định 165 _ 2024 _ NĐ-CP ] > Chương_IV > Điều 26 . Lập , thẩm_định , phê_duyệt phương_án tổ_chức giao_thông trước khi đưa đường_cao_tốc vào khai_thác , phê_duyệt điều_chỉnh , bổ_sung phương_án tổ_chức giao_thông đường_cao_tốc trong thời_gian khai_thác Nội_dung Khoản 5 : Chi_phí lập phương_án tổ_chức giao_thông được tính trong chi_phí tư_vấn thiết_kế khi đầu_tư xây_dựng công_trình đường_cao_tốc ; chi_phí khảo_sát , lập phương_án tổ_chức giao_thông điều_chỉnh khi đường_cao_tốc đã đưa vào khai_thác được tính trong chi_phí quản_lý , vận_hành , khai_thác và bảo_trì đường_cao_tốc .
  • Loss: MultipleNegativesRankingLoss with these parameters:
    {
        "scale": 20.0,
        "similarity_fct": "cos_sim",
        "gather_across_devices": false
    }
    

Training Hyperparameters

Non-Default Hyperparameters

  • per_device_train_batch_size: 32
  • per_device_eval_batch_size: 32
  • num_train_epochs: 5
  • multi_dataset_batch_sampler: round_robin

All Hyperparameters

Click to expand
  • do_predict: False
  • eval_strategy: no
  • prediction_loss_only: True
  • per_device_train_batch_size: 32
  • per_device_eval_batch_size: 32
  • gradient_accumulation_steps: 1
  • eval_accumulation_steps: None
  • torch_empty_cache_steps: None
  • learning_rate: 5e-05
  • weight_decay: 0.0
  • adam_beta1: 0.9
  • adam_beta2: 0.999
  • adam_epsilon: 1e-08
  • max_grad_norm: 1
  • num_train_epochs: 5
  • max_steps: -1
  • lr_scheduler_type: linear
  • lr_scheduler_kwargs: None
  • warmup_ratio: None
  • warmup_steps: 0
  • log_level: passive
  • log_level_replica: warning
  • log_on_each_node: True
  • logging_nan_inf_filter: True
  • enable_jit_checkpoint: False
  • save_on_each_node: False
  • save_only_model: False
  • restore_callback_states_from_checkpoint: False
  • use_cpu: False
  • seed: 42
  • data_seed: None
  • bf16: False
  • fp16: False
  • bf16_full_eval: False
  • fp16_full_eval: False
  • tf32: None
  • local_rank: -1
  • ddp_backend: None
  • debug: []
  • dataloader_drop_last: False
  • dataloader_num_workers: 0
  • dataloader_prefetch_factor: None
  • disable_tqdm: False
  • remove_unused_columns: True
  • label_names: None
  • load_best_model_at_end: False
  • ignore_data_skip: False
  • fsdp: []
  • fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}
  • accelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}
  • parallelism_config: None
  • deepspeed: None
  • label_smoothing_factor: 0.0
  • optim: adamw_torch_fused
  • optim_args: None
  • group_by_length: False
  • length_column_name: length
  • project: huggingface
  • trackio_space_id: trackio
  • 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
  • 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_for_metrics: []
  • eval_do_concat_batches: True
  • auto_find_batch_size: False
  • full_determinism: False
  • ddp_timeout: 1800
  • torch_compile: False
  • torch_compile_backend: None
  • torch_compile_mode: None
  • include_num_input_tokens_seen: no
  • 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: True
  • use_cache: False
  • prompts: None
  • batch_sampler: batch_sampler
  • multi_dataset_batch_sampler: round_robin
  • router_mapping: {}
  • learning_rate_mapping: {}

Training Logs

Epoch Step Training Loss bi_eval_cosine_ndcg@10
1.0 257 - 0.4887
1.9455 500 0.4220 -
2.0 514 - 0.5036
3.0 771 - 0.5044
3.8911 1000 0.0569 -
4.0 1028 - 0.5122

Framework Versions

  • Python: 3.12.12
  • Sentence Transformers: 5.2.3
  • Transformers: 5.0.0
  • PyTorch: 2.10.0+cu128
  • Accelerate: 1.12.0
  • Datasets: 4.8.3
  • Tokenizers: 0.22.2

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

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
17
Safetensors
Model size
0.1B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for HiImHa/phobert-bi-encoder

Finetuned
(311)
this model

Papers for HiImHa/phobert-bi-encoder

Evaluation results