Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 15
How to use Trelis/all-MiniLM-L12-v2-ft-pairs with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("Trelis/all-MiniLM-L12-v2-ft-pairs")
sentences = [
"What is the definition of 'Advantage' in Touch Rugby International Rules?",
"1\twhen a Change of Possession takes place due to a player in Possession \nmaking contact with the Sideline or any ground outside the Field of Play, \nprior to a Touch being made; or\n13.6.2\twhen the ball not in Possession of a player makes contact with the \nSideline or any ground outside the Field of Play.\n13.7\tA player may not perform a Tap in replacement of a Rollball.\nRuling = The offending Team must return to the Mark and perform the Rollball.\n13.8\tAn attacking player, other than the player performing the Rollball, may receive \nthe ball at the Rollball and shall do so without delay. That player is referred to as \nthe Half.\n13.9\tThe Half may control the ball with a foot prior to picking up the ball. \n13.10\tA player ceases to be the Half once the ball is passed to another player.\n13.11\tDefending players are not to interfere with the performance of the Rollball or the \nHalf. \nRuling = A Penalty to the Attacking Team at a point ten (10) metres directly Forward of the \nInfringement.\n13.12\tPlayers of the Defending Team must not move Forward of the Onside position \nuntil the Half has made contact with the ball, unless directed to do so by the \nReferee or in accordance with 13.12.1.\n13.12.1\tWhen the Half is not within one (1) metre of the Rollball, Onside players \nof the Defending Team may move Forward as soon as the player \nperforming the Rollball releases the ball. If the Half is not in position and \na defending player moves Forward and makes contact with the ball, a \nChange of Possession results.\n13.13\tIf in the act of performing the Rollball, the Attacking player makes contact with \nthe Sideline or any ground outside the Field of Play a Change of Possession will \noccur with the Rollball to be taken seven (7) metres in field.\n13.14\tAfter a Touch is made between the Dead Ball Line and the seven (7) metre line, \nan Attacking Team is permitted to Rollball on the seven (7) metre line at a point \ndirectly in line with where the Touch was made.\nFIT Playing Rules - 5th Edition\n12\nCOPYRIGHT © Touch Football Australia",
" distance beyond the Defending Try Line.\nRuling = A Penalty to the Attacking Team at the point of the Infringement or on the seven (7) \nmetre line directly Forward of the Infringement.\n15.4\tWhen a Rollball occurs within Defending Team’s Seven Metre Zone or a Penalty \nTap within ten (10) metres of the Defending Team’s Try Line, all players from the \nDefending Team must have both feet on or behind their Try Line and no other \npart of the body in contact with the ground Forward of their Try Line.\nRuling = A Penalty to the Attacking Team at the seven (7) metre line directly Forward of the \npoint of the Infringement.\n15.5\tAfter effecting the Touch, the defending player must retire the required seven \n(7) metres or to the Defending Try Line as indicated by the Referee without \ninterfering with the Attacking Team.\nRuling = A Penalty to the Attacking Team ten (10) metres Forward of the Infringement or if \non the Defensive Try Line, on the seven (7) metre line.\nFIT Playing Rules - 5th Edition\nCOPYRIGHT © Touch Football Australia 2020\n13\n16 Obstruction \n16.1\tA player in Possession must not run or otherwise move behind other attacking \nplayers or the Referee in an attempt to avoid an Imminent Touch.\nRuling = A Penalty to the non-offending Team at the point of the Infringement. \n16.2\tThe player in Possession is not to hold or otherwise impede a defending player \nin any way.\nRuling = A Penalty to the non-offending Team at the point of the Infringement. \n16.3\tAn attacking player in support of the player in Possession may move as \nnecessary to achieve a supporting position but must not grab, hold, push or \notherwise deliberately interfere with a defending player attempting to make a \nTouch\nRuling = A Penalty to the non-offending Team at the point of the Infringement or on the \nseven (7) metre line if the Infringement occurs in the In-Goal Area. \n16.4\tPlayers in the Defending Team may not obstruct or interfere with an attacking \nplayer.\nRuling = A Penalty to the non-offending Team at the point of the In",
" without delay. While in a position at the end of the Field of Play, \nthe Team coach(s) or Team official must remain no closer than five (5) metres \nfrom the Dead Ball Line and must not coach or communicate (verbal or non-\nverbal) with either Team or the Referees.\n7 Commencement and Recommencement of Play \n7.1\tTeam captains are to toss a coin in the presence of the Referee(s) with the \nwinning captain’s Team having the choice of the direction the Team wishes \nto run in the first half; the choice of Interchange Areas for the duration of the \nmatch, including any extra time; and the choice of which team will commence \nthe match in Possession.\n7.2\tA player of the Attacking Team is to commence the match with a Tap at the \ncentre of the Halfway Line following the indication to commence play from the \nReferee.\n7.3\tFor the recommencement of play following a Half Time break, Teams shall \nchange directions and the Team not commencing the match with Possession is \nto re-start the match with a Tap.\n7.4\tFor the recommencement of play following the scoring of a Try, the Team \nagainst which the Try was conceded will recommence play with a Tap.\n7.5\tA Tap may not be taken until all attacking Players are in an Onside position.\nRuling = The Player will be directed to return to the Mark and to take the Tap again.\nFIT Playing Rules - 5th Edition\nCOPYRIGHT © Touch Football Australia 2020\n7\n7.6\tA Tap may not be taken until at least four (4) defending players are in an Onside \nposition or unless directed to so by the Referee. Where the number of players \non the field from the Defending Team falls below four (4), all players must be in \nan Onside position for a Tap to be taken unless directed to do so by the Referee.\nRuling = The Player will be directed to return to the Mark and to take the Tap again.\n7.7\tThe Tap to commence or recommence play must be performed without delay.\nRuling = A Penalty to the non-offending team at the centre of the Halfway line.\n8 Match Duration \n \n8.1\tA match is 40 minutes in duration, consisting of two (2) x 20 minute"
]
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-L12-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': 128, 'do_lower_case': False}) with Transformer model: 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("Trelis/all-MiniLM-L12-v2-ft-pairs")
# Run inference
sentences = [
'Can an attacking player pass the ball into a defending player intentionally seeking a rebound or a restart of the Touch count?',
' a player enters the Field of Play but does not impede the scoring of a Try the \noffending player will be sent to the Sin Bin.\n17.8\tFollowing a Try, players may Interchange at will, without having to wait for the \nplayer to enter the Interchange Area, but must do so prior to the Tap being taken \nto recommence play.\n18\u2002 Penalty \n18.1\tThe Tap must be performed in accordance with the Definitions.\nRuling = The Referee will instruct the offending Team to return to the Mark and perform the \nTap again.\n18.2\tFor Infringements that occur between seven (7) metre lines, the Mark for the \nPenalty Tap is at the point of Infringement unless otherwise indicated by the \nReferee. \n18.3\tFor Infringements that occur within the Seven Metre Zone the Tap must be \ntaken at the nearest seven (7) metre line.\n18.4\tFor Infringements that occur beyond the Field of Play or in the In-Goal Area \nthe Mark is seven (7) metres infield from the Sideline, or directly Forward of \nthe Infringement on the seven (7) metre line nearest the Infringement or at a \nposition indicated by the Referee.\n18.5\tThe Mark must be indicated by the Referee before a Penalty Tap is taken.\n18.6\tThe Penalty Tap must be performed without delay after the Referee indicates \nthe Mark.\nRuling = A Penalty to the non-offending team at the point of Infringement.\n18.7\tA player may perform a Rollball instead of a Penalty Tap and the player who \nreceives the ball does not become the Half.\n18.8\tIf the Defending Team is penalised three (3) times upon entering their Seven \nMetre Zone during a single Possession, the last offending player will be given an \nExclusion until the end of that Possession.\n18.9\tA Penalty Try is awarded if any action by a player, Team official or spectator, \ndeemed by the Referee to be contrary to the Rules or spirit of the game clearly \nprevents the Attacking Team from scoring a Try.\nFIT Playing Rules - 5th Edition\nCOPYRIGHT © Touch Football Australia 2020\n15\n19\u2002 Advantage \n19.1\tWhere a Defending Team player is Offside at a Tap or',
' without delay.\nRuling = A Penalty to the non-offending team at the centre of the Halfway line.\n8\u2002 Match Duration \n \n8.1\tA match is 40 minutes in duration, consisting of two (2) x 20 minute halves with \na Half Time break.\n8.1.1\tThere is no time off for injury during a match.\n8.2\tLocal competition and tournament conditions may vary the duration of a match.\n8.3\tWhen time expires, play is to continue until the next Touch or Dead Ball and End \nof Play is signaled by the Referee. \n8.3.1\tShould a Penalty be awarded during this period, the Penalty is to be taken.\n8.4\tIf a match is abandoned in any circumstances other than those referred to in \nclause 24.1.6 the NTA or NTA competition provider in its sole discretion shall \ndetermine the result of the match.\n9\u2002 Possession \n \n9.1\tThe Team with the ball is entitled to six (6) Touches prior to a Change of \nPossession. \n9.2\tOn the Change of Possession due to an intercept, the first Touch will be zero (0) \nTouch. \n9.3\tFollowing the sixth Touch or a loss of Possession due to any other means, the \nball must be returned to the Mark without delay.\nRuling = A deliberate delay in the changeover procedure will result in a Penalty awarded to \nthe non-offending Team ten (10) metres Forward of the Mark for the Change of Possession.\n9.4\tIf the ball is dropped or passed and goes to ground during play, a Change of \nPossession results.\nRuling = The Mark for the Change of Possession is where the ball makes initial contact with \nthe ground.\n9.5\tIf the ball, while still under the control of the Half, contacts the ground in the In-\nGoal Area, Possession is lost.\nRuling = Play will restart with a Rollball at the nearest point on the seven (7) metre line.\nFIT Playing Rules - 5th Edition\n8\nCOPYRIGHT © Touch Football Australia 2020\n9.6\tIf a player mishandles the ball and even if in an effort to gain control, the ball \nis accidentally knocked Forward into any other Player, a Change of Possession \nresults.\n10\u2002 The Touch \n10.1\tA Touch may be made',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 384]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [3, 3]
eval_strategy: stepsper_device_train_batch_size: 32per_device_eval_batch_size: 32learning_rate: 1e-05num_train_epochs: 1lr_scheduler_type: cosinewarmup_ratio: 0.3bf16: Trueoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 32per_device_eval_batch_size: 32per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 1eval_accumulation_steps: Nonelearning_rate: 1e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 1max_steps: -1lr_scheduler_type: cosinelr_scheduler_kwargs: {}warmup_ratio: 0.3warmup_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: Truefp16: Falsefp16_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: Falseeval_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: Falsebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportional| Epoch | Step | Training Loss | loss |
|---|---|---|---|
| 0.1364 | 6 | 7.9127 | 6.9307 |
| 0.2727 | 12 | 7.5286 | 6.2160 |
| 0.4091 | 18 | 6.479 | 5.4784 |
| 0.5455 | 24 | 5.9214 | 5.0664 |
| 0.6818 | 30 | 5.5053 | 4.9428 |
| 0.8182 | 36 | 5.7077 | 4.8511 |
| 0.9545 | 42 | 5.3669 | 4.8320 |
@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",
}
@online{kexuefm-8847,
title={CoSENT: A more efficient sentence vector scheme than Sentence-BERT},
author={Su Jianlin},
year={2022},
month={Jan},
url={https://kexue.fm/archives/8847},
}
Base model
microsoft/MiniLM-L12-H384-uncased