Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 15
How to use GozdeA/tennis-multi-return-v4 with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("GozdeA/tennis-multi-return-v4")
sentences = [
"What are the serving today for Djokovic?",
"serving for Djokovic?",
"last for Djokovic?",
"What is the serving today for Djokovic?"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from sentence-transformers/all-MiniLM-L6-v2. It maps sentences & paragraphs to a 384-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, 'architecture': 'BertModel'})
(1): Pooling({'word_embedding_dimension': 384, '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})
(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("GozdeA/tennis-multi-return-v4")
# Run inference
sentences = [
'Show me previous game result',
'what venue',
'How is the tactical battle between the player and Amanda Anismova playing out?',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 384]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[ 1.0000, 0.6952, -0.0128],
# [ 0.6952, 1.0000, 0.0505],
# [-0.0128, 0.0505, 1.0000]])
anchor, positive, and negative| anchor | positive | negative | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| anchor | positive | negative |
|---|---|---|
What is the this season for Djokovic? |
What's the this season for Djokovic? |
What is the attacking this set for Djokovic? |
who is projected? |
momentum shift? |
How does she's path to this round compare to Amanda Anismova's? |
What's the sets won for Sinner? |
Show me how many winners |
What's the last year for Djokovic? |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim"
}
anchor, positive, and negative| anchor | positive | negative | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| anchor | positive | negative |
|---|---|---|
What about Djokovic's games? |
What's the how many winners for Djokovic? |
ranking for the player? |
What is the next match for Djokovic? |
What are the next match for Djokovic? |
What is the pre match for Djokovic? |
What are the gaining momentum for Sinner? |
What is the gaining momentum for Sinner? |
What are the gaining control for Sinner? |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim"
}
per_device_train_batch_size: 16learning_rate: 2e-05num_train_epochs: 15warmup_ratio: 0.1fp16: Trueoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: noprediction_loss_only: Trueper_device_train_batch_size: 16per_device_eval_batch_size: 8per_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: 15max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_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: 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}parallelism_config: Nonedeepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torch_fusedoptim_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: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss |
|---|---|---|
| 0.0690 | 50 | 5.1095 |
| 0.1379 | 100 | 3.9909 |
| 0.2069 | 150 | 3.1963 |
| 0.2759 | 200 | 2.3301 |
| 0.3448 | 250 | 1.9904 |
| 0.4138 | 300 | 1.6705 |
| 0.4828 | 350 | 1.5659 |
| 0.5517 | 400 | 1.5497 |
| 0.6207 | 450 | 1.3563 |
| 0.6897 | 500 | 1.2982 |
| 0.7586 | 550 | 1.2509 |
| 0.8276 | 600 | 1.1737 |
| 0.8966 | 650 | 1.1486 |
| 0.9655 | 700 | 1.192 |
| 1.0345 | 750 | 0.9715 |
| 1.1034 | 800 | 1.0054 |
| 1.1724 | 850 | 1.0102 |
| 1.2414 | 900 | 0.9393 |
| 1.3103 | 950 | 0.9119 |
| 1.3793 | 1000 | 0.8589 |
| 1.4483 | 1050 | 0.9049 |
| 1.5172 | 1100 | 0.8774 |
| 1.5862 | 1150 | 0.8488 |
| 1.6552 | 1200 | 0.8382 |
| 1.7241 | 1250 | 0.7437 |
| 1.7931 | 1300 | 0.8023 |
| 1.8621 | 1350 | 0.7775 |
| 1.9310 | 1400 | 0.7756 |
| 2.0 | 1450 | 0.7273 |
| 2.0690 | 1500 | 0.6275 |
| 2.1379 | 1550 | 0.7331 |
| 2.2069 | 1600 | 0.629 |
| 2.2759 | 1650 | 0.7127 |
| 2.3448 | 1700 | 0.6503 |
| 2.4138 | 1750 | 0.7082 |
| 2.4828 | 1800 | 0.6939 |
| 2.5517 | 1850 | 0.6993 |
| 2.6207 | 1900 | 0.7067 |
| 2.6897 | 1950 | 0.6622 |
| 2.7586 | 2000 | 0.6499 |
| 2.8276 | 2050 | 0.6923 |
| 2.8966 | 2100 | 0.6208 |
| 2.9655 | 2150 | 0.5925 |
| 3.0345 | 2200 | 0.6697 |
| 3.1034 | 2250 | 0.6458 |
| 3.1724 | 2300 | 0.5709 |
| 3.2414 | 2350 | 0.5987 |
| 3.3103 | 2400 | 0.6252 |
| 3.3793 | 2450 | 0.6377 |
| 3.4483 | 2500 | 0.5739 |
| 3.5172 | 2550 | 0.6281 |
| 3.5862 | 2600 | 0.6186 |
| 3.6552 | 2650 | 0.5828 |
| 3.7241 | 2700 | 0.678 |
| 3.7931 | 2750 | 0.6257 |
| 3.8621 | 2800 | 0.5704 |
| 3.9310 | 2850 | 0.6151 |
| 4.0 | 2900 | 0.5898 |
| 4.0690 | 2950 | 0.5277 |
| 4.1379 | 3000 | 0.6128 |
| 4.2069 | 3050 | 0.6306 |
| 4.2759 | 3100 | 0.5739 |
| 4.3448 | 3150 | 0.5396 |
| 4.4138 | 3200 | 0.617 |
| 4.4828 | 3250 | 0.5119 |
| 4.5517 | 3300 | 0.6136 |
| 4.6207 | 3350 | 0.6303 |
| 4.6897 | 3400 | 0.6138 |
| 4.7586 | 3450 | 0.6214 |
| 4.8276 | 3500 | 0.5686 |
| 4.8966 | 3550 | 0.5901 |
| 4.9655 | 3600 | 0.6913 |
| 5.0345 | 3650 | 0.5706 |
| 5.1034 | 3700 | 0.6082 |
| 5.1724 | 3750 | 0.4755 |
| 5.2414 | 3800 | 0.5777 |
| 5.3103 | 3850 | 0.5515 |
| 5.3793 | 3900 | 0.5271 |
| 5.4483 | 3950 | 0.5816 |
| 5.5172 | 4000 | 0.5787 |
| 5.5862 | 4050 | 0.568 |
| 5.6552 | 4100 | 0.5593 |
| 5.7241 | 4150 | 0.542 |
| 5.7931 | 4200 | 0.5873 |
| 5.8621 | 4250 | 0.5647 |
| 5.9310 | 4300 | 0.6369 |
| 6.0 | 4350 | 0.5775 |
| 6.0690 | 4400 | 0.5324 |
| 6.1379 | 4450 | 0.5463 |
| 6.2069 | 4500 | 0.5234 |
| 6.2759 | 4550 | 0.4921 |
| 6.3448 | 4600 | 0.5716 |
| 6.4138 | 4650 | 0.6321 |
| 6.4828 | 4700 | 0.4881 |
| 6.5517 | 4750 | 0.5717 |
| 6.6207 | 4800 | 0.5922 |
| 6.6897 | 4850 | 0.5289 |
| 6.7586 | 4900 | 0.5182 |
| 6.8276 | 4950 | 0.5096 |
| 6.8966 | 5000 | 0.6062 |
| 6.9655 | 5050 | 0.6014 |
| 7.0345 | 5100 | 0.5033 |
| 7.1034 | 5150 | 0.4994 |
| 7.1724 | 5200 | 0.5842 |
| 7.2414 | 5250 | 0.5317 |
| 7.3103 | 5300 | 0.5112 |
| 7.3793 | 5350 | 0.5188 |
| 7.4483 | 5400 | 0.6174 |
| 7.5172 | 5450 | 0.484 |
| 7.5862 | 5500 | 0.5571 |
| 7.6552 | 5550 | 0.5043 |
| 7.7241 | 5600 | 0.5341 |
| 7.7931 | 5650 | 0.5225 |
| 7.8621 | 5700 | 0.5618 |
| 7.9310 | 5750 | 0.5537 |
| 8.0 | 5800 | 0.5811 |
| 8.0690 | 5850 | 0.5311 |
| 8.1379 | 5900 | 0.5585 |
| 8.2069 | 5950 | 0.5564 |
| 8.2759 | 6000 | 0.5469 |
| 8.3448 | 6050 | 0.5726 |
| 8.4138 | 6100 | 0.5329 |
| 8.4828 | 6150 | 0.55 |
| 8.5517 | 6200 | 0.5365 |
| 8.6207 | 6250 | 0.5847 |
| 8.6897 | 6300 | 0.5204 |
| 8.7586 | 6350 | 0.5112 |
| 8.8276 | 6400 | 0.5468 |
| 8.8966 | 6450 | 0.4871 |
| 8.9655 | 6500 | 0.5449 |
| 9.0345 | 6550 | 0.5237 |
| 9.1034 | 6600 | 0.5232 |
| 9.1724 | 6650 | 0.5075 |
| 9.2414 | 6700 | 0.5078 |
| 9.3103 | 6750 | 0.5366 |
| 9.3793 | 6800 | 0.5636 |
| 9.4483 | 6850 | 0.4743 |
| 9.5172 | 6900 | 0.4776 |
| 9.5862 | 6950 | 0.5571 |
| 9.6552 | 7000 | 0.56 |
| 9.7241 | 7050 | 0.5054 |
| 9.7931 | 7100 | 0.5431 |
| 9.8621 | 7150 | 0.5358 |
| 9.9310 | 7200 | 0.5395 |
| 10.0 | 7250 | 0.5394 |
| 10.0690 | 7300 | 0.57 |
| 10.1379 | 7350 | 0.4883 |
| 10.2069 | 7400 | 0.4884 |
| 10.2759 | 7450 | 0.4587 |
| 10.3448 | 7500 | 0.5076 |
| 10.4138 | 7550 | 0.5108 |
| 10.4828 | 7600 | 0.565 |
| 10.5517 | 7650 | 0.503 |
| 10.6207 | 7700 | 0.5645 |
| 10.6897 | 7750 | 0.509 |
| 10.7586 | 7800 | 0.4993 |
| 10.8276 | 7850 | 0.5464 |
| 10.8966 | 7900 | 0.5293 |
| 10.9655 | 7950 | 0.5384 |
| 11.0345 | 8000 | 0.5245 |
| 11.1034 | 8050 | 0.4647 |
| 11.1724 | 8100 | 0.4983 |
| 11.2414 | 8150 | 0.5168 |
| 11.3103 | 8200 | 0.5455 |
| 11.3793 | 8250 | 0.5069 |
| 11.4483 | 8300 | 0.5523 |
| 11.5172 | 8350 | 0.4875 |
| 11.5862 | 8400 | 0.4947 |
| 11.6552 | 8450 | 0.5022 |
| 11.7241 | 8500 | 0.5096 |
| 11.7931 | 8550 | 0.5768 |
| 11.8621 | 8600 | 0.5187 |
| 11.9310 | 8650 | 0.4883 |
| 12.0 | 8700 | 0.5039 |
| 12.0690 | 8750 | 0.527 |
| 12.1379 | 8800 | 0.5382 |
| 12.2069 | 8850 | 0.4912 |
| 12.2759 | 8900 | 0.5144 |
| 12.3448 | 8950 | 0.532 |
| 12.4138 | 9000 | 0.5233 |
| 12.4828 | 9050 | 0.4169 |
| 12.5517 | 9100 | 0.5278 |
| 12.6207 | 9150 | 0.5028 |
| 12.6897 | 9200 | 0.5227 |
| 12.7586 | 9250 | 0.4812 |
| 12.8276 | 9300 | 0.5299 |
| 12.8966 | 9350 | 0.5383 |
| 12.9655 | 9400 | 0.5245 |
| 13.0345 | 9450 | 0.5045 |
| 13.1034 | 9500 | 0.5619 |
| 13.1724 | 9550 | 0.4969 |
| 13.2414 | 9600 | 0.508 |
| 13.3103 | 9650 | 0.5095 |
| 13.3793 | 9700 | 0.5095 |
| 13.4483 | 9750 | 0.4886 |
| 13.5172 | 9800 | 0.5074 |
| 13.5862 | 9850 | 0.4761 |
| 13.6552 | 9900 | 0.4805 |
| 13.7241 | 9950 | 0.4559 |
| 13.7931 | 10000 | 0.5212 |
| 13.8621 | 10050 | 0.506 |
| 13.9310 | 10100 | 0.5086 |
| 14.0 | 10150 | 0.5232 |
| 14.0690 | 10200 | 0.5156 |
| 14.1379 | 10250 | 0.495 |
| 14.2069 | 10300 | 0.5226 |
| 14.2759 | 10350 | 0.4842 |
| 14.3448 | 10400 | 0.4514 |
| 14.4138 | 10450 | 0.4902 |
| 14.4828 | 10500 | 0.5068 |
| 14.5517 | 10550 | 0.5784 |
| 14.6207 | 10600 | 0.5646 |
| 14.6897 | 10650 | 0.4994 |
| 14.7586 | 10700 | 0.552 |
| 14.8276 | 10750 | 0.5216 |
| 14.8966 | 10800 | 0.5506 |
| 14.9655 | 10850 | 0.4286 |
@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
nreimers/MiniLM-L6-H384-uncased