Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 13
How to use thaiquangphat/edukg_retrieval with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("thaiquangphat/edukg_retrieval")
sentences = [
"Cậu bé Wilkins là kẻ ngu_ngốc lớn nhất mà tôi từng thấy .",
"Ông nhìn vào nó cẩn_thận trong khi xoay nó trong tay của mình .",
"Tôi nghĩ Wilkins là một kẻ ngốc .",
"Tôi coi Wilkins là một trong những người thông_minh nhất thế_giới ."
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from BAAI/bge-m3. It maps sentences & paragraphs to a 1024-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': 8192, 'do_lower_case': False, 'architecture': 'XLMRobertaModel'})
(1): Pooling({'word_embedding_dimension': 1024, 'pooling_mode_cls_token': True, 'pooling_mode_mean_tokens': False, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': True})
(2): Normalize()
)
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("thaiquangphat/edukg_retrieval")
# Run inference
sentences = [
'John thuộc về truyền_thống nào ?',
'John thuộc học_viện nào ?',
'Tại_sao Giăng không có truyền_thống ?',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 1024]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[1.0000, 0.8059, 0.0845],
# [0.8059, 1.0000, 0.0498],
# [0.0845, 0.0498, 1.0000]])
all-nli-devTripletEvaluator| Metric | Value |
|---|---|
| cosine_accuracy | 0.935 |
anchor, positive, and negative| anchor | positive | negative | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| anchor | positive | negative |
|---|---|---|
Trong thời_gian bình_luận , APHIS cũng tổ_chức bốn phiên điều_trần công_khai trong đó nhận được bình_luận bằng miệng và bằng văn_bản . |
APHIS đã tổ_chức hơn ba phiên điều_trần công_khai trong thời_gian bình_luận . |
APHIS đã tổ_chức hơn năm phiên điều_trần công_khai trong thời_gian bình_luận . |
Nếu họ có bất_kỳ manh_mối nào , hay 103 thì toàn_bộ việc sẽ vẫn nằm trong danh_mục tội_phạm chưa được phát_hiện ? |
Họ có thật_sự nghĩ rằng nó sẽ được giấu kín không ? |
Họ không nghĩ rằng nó sẽ không được phát_hiện , trên thực_tế họ biết nó sẽ được phát_hiện . |
Không , tôi nhớ khi tôi đang học đại_học tôi cũng không có thời_gian để làm những thứ đó . |
Khi tôi đang học đại_học , tôi cũng không có thời_gian để làm những việc như_vậy . |
Khi tôi đang học đại_học , tôi có nhiều thời_gian để làm những việc như_vậy . |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim",
"gather_across_devices": false
}
anchor, positive, and negative| anchor | positive | negative | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| anchor | positive | negative |
|---|---|---|
Năm 1982 và 1983 , de Kooning , không bị phân tâm bởi một thế_giới bên ngoài mà anh ta không_thể hiểu được nữa , vẽ với tốc_độ chưa từng có , hoàn_thành gần một bức tranh một tuần . |
De Kooning vẽ khoảng 50 bức tranh mỗi năm trong năm 1982 và 1983 . |
De Kooning không vẽ bất_kỳ bức tranh nào trong những năm 1980 . |
Uh một_chút ừ ừ |
Chỉ một_chút thôi . |
Chắc_chắn là rất nhiều . |
Bạn có sử_dụng rất nhiều thẻ tín_dụng hoặc tài_khoản thanh_toán của bạn khi bạn ra ngoài và mua những thứ |
Bạn có thường dùng thẻ tín_dụng để mua_sắm hay bạn thích sử_dụng tài_khoản thanh_toán của mình ? |
Tôi không muốn biết nếu bạn sử_dụng thẻ tín_dụng hoặc tài_khoản thanh_toán của bạn . |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim",
"gather_across_devices": false
}
eval_strategy: stepsper_device_train_batch_size: 4per_device_eval_batch_size: 4learning_rate: 1e-05num_train_epochs: 5warmup_ratio: 0.1fp16: Trueload_best_model_at_end: Truebatch_sampler: no_duplicatesoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 4per_device_eval_batch_size: 4per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 1eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 1e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 5max_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: 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: Trueignore_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}parallelism_config: Nonedeepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torchoptim_args: Noneadafactor: Falsegroup_by_length: Falselength_column_name: lengthproject: huggingfacetrackio_space_id: trackioddp_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: Nonehub_always_push: Falsehub_revision: Nonegradient_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: Noneinclude_tokens_per_second: Falseinclude_num_input_tokens_seen: noneftune_noise_alpha: Noneoptim_target_modules: Nonebatch_eval_metrics: Falseeval_on_start: Falseuse_liger_kernel: Falseliger_kernel_config: Noneeval_use_gather_object: Falseaverage_tokens_across_devices: Trueprompts: Nonebatch_sampler: no_duplicatesmulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | Validation Loss | all-nli-dev_cosine_accuracy |
|---|---|---|---|---|
| 0.0005 | 1 | 0.5395 | - | - |
| 0.0479 | 100 | 0.3501 | - | - |
| 0.0958 | 200 | 0.3403 | - | - |
| 0.1437 | 300 | 0.2836 | - | - |
| 0.1916 | 400 | 0.2915 | - | - |
| 0.2395 | 500 | 0.3073 | - | - |
| 0.2874 | 600 | 0.3386 | - | - |
| 0.3352 | 700 | 0.273 | - | - |
| 0.3831 | 800 | 0.271 | - | - |
| 0.4310 | 900 | 0.264 | - | - |
| 0.4789 | 1000 | 0.3396 | 0.2744 | 0.9200 |
| 0.5268 | 1100 | 0.2826 | - | - |
| 0.5747 | 1200 | 0.2761 | - | - |
| 0.6226 | 1300 | 0.2394 | - | - |
| 0.6705 | 1400 | 0.2768 | - | - |
| 0.7184 | 1500 | 0.2574 | - | - |
| 0.7663 | 1600 | 0.2854 | - | - |
| 0.8142 | 1700 | 0.3389 | - | - |
| 0.8621 | 1800 | 0.3172 | - | - |
| 0.9100 | 1900 | 0.3292 | - | - |
| 0.9579 | 2000 | 0.21 | 0.3338 | 0.9290 |
| 1.0057 | 2100 | 0.2504 | - | - |
| 1.0536 | 2200 | 0.1347 | - | - |
| 1.1015 | 2300 | 0.1377 | - | - |
| 1.1494 | 2400 | 0.1718 | - | - |
| 1.1973 | 2500 | 0.1623 | - | - |
| 1.2452 | 2600 | 0.1232 | - | - |
| 1.2931 | 2700 | 0.1777 | - | - |
| 1.3410 | 2800 | 0.1279 | - | - |
| 1.3889 | 2900 | 0.1391 | - | - |
| 1.4368 | 3000 | 0.1176 | 0.3022 | 0.9290 |
| 1.4847 | 3100 | 0.136 | - | - |
| 1.5326 | 3200 | 0.1753 | - | - |
| 1.5805 | 3300 | 0.1605 | - | - |
| 1.6284 | 3400 | 0.1475 | - | - |
| 1.6762 | 3500 | 0.159 | - | - |
| 1.7241 | 3600 | 0.1709 | - | - |
| 1.7720 | 3700 | 0.131 | - | - |
| 1.8199 | 3800 | 0.1507 | - | - |
| 1.8678 | 3900 | 0.0933 | - | - |
| 1.9157 | 4000 | 0.1253 | 0.2923 | 0.9300 |
| 1.9636 | 4100 | 0.1527 | - | - |
| 2.0115 | 4200 | 0.1645 | - | - |
| 2.0594 | 4300 | 0.0759 | - | - |
| 2.1073 | 4400 | 0.0309 | - | - |
| 2.1552 | 4500 | 0.0389 | - | - |
| 2.2031 | 4600 | 0.0233 | - | - |
| 2.2510 | 4700 | 0.0364 | - | - |
| 2.2989 | 4800 | 0.0423 | - | - |
| 2.3467 | 4900 | 0.0506 | - | - |
| 2.3946 | 5000 | 0.0766 | 0.3016 | 0.9350 |
@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}
}
Base model
BAAI/bge-m3