Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper
•
1908.10084
•
Published
•
11
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.
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})
)
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("tintnguyen/vietnamese-bi-encoder-ft")
# Run inference
sentences = [
'tên thật của tỉnh drava banovina là gì',
'Drava Banovina ::: Drava Banovina hoặc Drava Banate (tiếng Slovenia: Dravska banovina) là một tỉnh (banovina) của Vương quốc Nam Tư từ năm 1929 đến năm 1941. Tỉnh này bao gồm hầu hết ngày nay Slovenia và được đặt tên cho Drava sông. Thành phố thủ đô của Drava Banovina là Ljubljana.',
'Mùa bão Tây Bắc Thái Bình Dương 1986 ::: Mùa bão năm 1986 ở Tây Bắc Thái Bình Dương không có giới hạn chính thức; nó chạy quanh năm vào năm 1986, nhưng hầu hết các cơn bão nhiệt đới có xu hướng hình thành ở tây bắc Thái Bình Dương giữa tháng Năm và tháng Mười Hai. Những ngày này thường phân định thời kỳ mỗi năm khi hầu hết các cơn bão nhiệt đới hình thành ở tây bắc Thái Bình Dương. Bão nhiệt đới hình thành trong toàn bộ lưu vực phía tây Thái Bình Dương đã được Trung tâm Cảnh báo Bão chung đặt tên. Áp thấp nhiệt đới xâm nhập hoặc hình thành trong khu vực trách nhiệm của Philippines được đặt tên bởi Cơ quan Dịch vụ Khí quyển, Địa vật lý và Thiên văn học Philippines hoặc PAGASA. Điều này thường có thể dẫn đến cùng một cơn bão có hai tên.',
]
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]
InformationRetrievalEvaluator on ir-eval{'aaa_cosine_accuracy@1': 0.6559, 'aaa_cosine_accuracy@3': 0.7988, 'aaa_cosine_accuracy@5': 0.8473, 'aaa_cosine_accuracy@10': 0.8915, 'aaa_cosine_precision@1': 0.6559, 'aaa_cosine_precision@3': 0.4683333333333332, 'aaa_cosine_precision@5': 0.39014000000000004, 'aaa_cosine_precision@10': 0.29126, 'aaa_cosine_recall@1': 0.14735861230027672, 'aaa_cosine_recall@3': 0.2534958821819028, 'aaa_cosine_recall@5': 0.3139822545058687, 'aaa_cosine_recall@10': 0.3978179383957577, 'aaa_cosine_ndcg@10': 0.4994592874617665, 'aaa_cosine_mrr@10': 0.7369935317460269, 'aaa_cosine_map@100': 0.3890462930756453}
anchor and positive| anchor | positive | |
|---|---|---|
| type | string | string |
| details |
|
|
| anchor | positive |
|---|---|
đặng văn hoàn từng giữ chức vụ nào |
Đặng Văn Hoàn ::: Đặng Văn Hoàn là chính trị gia người Việt Nam. Ông từng giữ chức vụ Chủ tịch Ủy ban Mặt trận Tổ quốc Việt Nam tỉnh Quảng Bình. |
đặng văn hoàn là người nào |
Đặng Văn Hoàn ::: Đặng Văn Hoàn là chính trị gia người Việt Nam. Ông từng giữ chức vụ Chủ tịch Ủy ban Mặt trận Tổ quốc Việt Nam tỉnh Quảng Bình. |
đặng văn hoàn là ai |
Đặng Văn Hoàn ::: Đặng Văn Hoàn là chính trị gia người Việt Nam. Ông từng giữ chức vụ Chủ tịch Ủy ban Mặt trận Tổ quốc Việt Nam tỉnh Quảng Bình. |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim"
}
per_device_train_batch_size: 64per_device_eval_batch_size: 32learning_rate: 2e-05num_train_epochs: 2warmup_ratio: 0.1fp16: Truebatch_sampler: no_duplicatesoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: noprediction_loss_only: Trueper_device_train_batch_size: 64per_device_eval_batch_size: 32per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 1eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 2e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 2max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: {}warmup_ratio: 0.1warmup_steps: 0log_level: passivelog_level_replica: warninglog_on_each_node: Truelogging_nan_inf_filter: Truesave_safetensors: Truesave_on_each_node: Falsesave_only_model: Falserestore_callback_states_from_checkpoint: Falseno_cuda: Falseuse_cpu: Falseuse_mps_device: Falseseed: 42data_seed: Nonejit_mode_eval: Falseuse_ipex: Falsebf16: Falsefp16: Truefp16_opt_level: O1half_precision_backend: autobf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonelocal_rank: 0ddp_backend: Nonetpu_num_cores: Nonetpu_metrics_debug: Falsedebug: []dataloader_drop_last: Falsedataloader_num_workers: 0dataloader_prefetch_factor: Nonepast_index: -1disable_tqdm: Falseremove_unused_columns: Truelabel_names: Noneload_best_model_at_end: Falseignore_data_skip: Falsefsdp: []fsdp_min_num_params: 0fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}fsdp_transformer_layer_cls_to_wrap: Noneaccelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}deepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torchoptim_args: Noneadafactor: Falsegroup_by_length: Falselength_column_name: lengthddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falsedataloader_pin_memory: Truedataloader_persistent_workers: Falseskip_memory_metrics: Trueuse_legacy_prediction_loop: Falsepush_to_hub: Falseresume_from_checkpoint: Nonehub_model_id: Nonehub_strategy: every_savehub_private_repo: Falsehub_always_push: Falsegradient_checkpointing: Falsegradient_checkpointing_kwargs: Noneinclude_inputs_for_metrics: Falseinclude_for_metrics: []eval_do_concat_batches: Truefp16_backend: autopush_to_hub_model_id: Nonepush_to_hub_organization: Nonemp_parameters: auto_find_batch_size: Falsefull_determinism: Falsetorchdynamo: Noneray_scope: lastddp_timeout: 1800torch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Nonedispatch_batches: Nonesplit_batches: Noneinclude_tokens_per_second: Falseinclude_num_input_tokens_seen: Falseneftune_noise_alpha: Noneoptim_target_modules: Nonebatch_eval_metrics: Falseeval_on_start: Falseuse_liger_kernel: Falseeval_use_gather_object: Falseaverage_tokens_across_devices: Falseprompts: Nonebatch_sampler: no_duplicatesmulti_dataset_batch_sampler: proportional| Epoch | Step | Training Loss |
|---|---|---|
| 0.0202 | 500 | 0.3446 |
| 0.0404 | 1000 | 0.3366 |
| 0.0606 | 1500 | 0.4109 |
| 0.0809 | 2000 | 0.1684 |
| 0.1011 | 2500 | 0.2029 |
| 0.1213 | 3000 | 0.1815 |
| 0.1415 | 3500 | 0.1493 |
| 0.1617 | 4000 | 0.1606 |
| 0.1819 | 4500 | 0.1221 |
| 0.2021 | 5000 | 0.1488 |
| 0.2223 | 5500 | 0.1751 |
| 0.2426 | 6000 | 0.2354 |
| 0.2628 | 6500 | 0.1252 |
| 0.2830 | 7000 | 0.1352 |
| 0.3032 | 7500 | 0.1798 |
| 0.3234 | 8000 | 0.1166 |
| 0.3436 | 8500 | 0.1247 |
| 0.3638 | 9000 | 0.1664 |
| 0.3841 | 9500 | 0.1451 |
| 0.4043 | 10000 | 0.1391 |
| 0.4245 | 10500 | 0.3064 |
| 0.4447 | 11000 | 0.373 |
| 0.4649 | 11500 | 0.2125 |
| 0.4851 | 12000 | 0.1839 |
| 0.5053 | 12500 | 0.3237 |
| 0.5255 | 13000 | 0.4 |
| 0.5458 | 13500 | 0.2788 |
| 0.5660 | 14000 | 0.2936 |
| 0.5862 | 14500 | 0.1388 |
| 0.6064 | 15000 | 0.1581 |
| 0.6266 | 15500 | 0.1876 |
| 0.6468 | 16000 | 0.1569 |
| 0.6670 | 16500 | 0.1575 |
| 0.6873 | 17000 | 0.2999 |
| 0.7075 | 17500 | 0.2072 |
| 0.7277 | 18000 | 0.2041 |
| 0.7479 | 18500 | 0.2705 |
| 0.7681 | 19000 | 0.3727 |
| 0.7883 | 19500 | 0.2635 |
| 0.8085 | 20000 | 0.2007 |
| 0.8288 | 20500 | 0.1417 |
| 0.8490 | 21000 | 0.1682 |
| 0.8692 | 21500 | 0.1665 |
| 0.8894 | 22000 | 0.0305 |
| 0.9096 | 22500 | 0.0184 |
| 0.9298 | 23000 | 0.0159 |
| 0.9500 | 23500 | 0.0166 |
| 0.9702 | 24000 | 0.0149 |
| 0.9905 | 24500 | 0.0158 |
| 1.0107 | 25000 | 0.0725 |
| 1.0309 | 25500 | 0.1099 |
| 1.0511 | 26000 | 0.2281 |
| 1.0713 | 26500 | 0.1607 |
| 1.0915 | 27000 | 0.0796 |
| 1.1117 | 27500 | 0.0998 |
| 1.1320 | 28000 | 0.0603 |
| 1.1522 | 28500 | 0.0815 |
| 1.1724 | 29000 | 0.0754 |
| 1.1926 | 29500 | 0.0873 |
| 1.2128 | 30000 | 0.079 |
| 1.2330 | 30500 | 0.0748 |
| 1.2532 | 31000 | 0.1438 |
| 1.2734 | 31500 | 0.0575 |
| 1.2937 | 32000 | 0.1203 |
| 1.3139 | 32500 | 0.0585 |
| 1.3341 | 33000 | 0.0626 |
| 1.3543 | 33500 | 0.0641 |
| 1.3745 | 34000 | 0.0953 |
| 1.3947 | 34500 | 0.0625 |
| 1.4149 | 35000 | 0.1376 |
| 1.4352 | 35500 | 0.309 |
| 1.4554 | 36000 | 0.1851 |
| 1.4756 | 36500 | 0.1268 |
| 1.4958 | 37000 | 0.1762 |
| 1.5160 | 37500 | 0.3293 |
| 1.5362 | 38000 | 0.2692 |
| 1.5564 | 38500 | 0.2661 |
| 1.5766 | 39000 | 0.139 |
| 1.5969 | 39500 | 0.0764 |
| 1.6171 | 40000 | 0.1381 |
| 1.6373 | 40500 | 0.0821 |
| 1.6575 | 41000 | 0.0868 |
| 1.6777 | 41500 | 0.1709 |
| 1.6979 | 42000 | 0.1946 |
| 1.7181 | 42500 | 0.1325 |
| 1.7384 | 43000 | 0.1217 |
| 1.7586 | 43500 | 0.2898 |
| 1.7788 | 44000 | 0.2789 |
| 1.7990 | 44500 | 0.1743 |
| 1.8192 | 45000 | 0.1075 |
| 1.8394 | 45500 | 0.1036 |
| 1.8596 | 46000 | 0.1409 |
| 1.8799 | 46500 | 0.0504 |
| 1.9001 | 47000 | 0.0114 |
| 1.9203 | 47500 | 0.009 |
| 1.9405 | 48000 | 0.0083 |
| 1.9607 | 48500 | 0.0082 |
| 1.9809 | 49000 | 0.0079 |
@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",
}
@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}
}