Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 12
This is a Cross Encoder model finetuned from BAAI/bge-m3 using the sentence-transformers library. It computes scores for pairs of texts, which can be used for text reranking and semantic search.
First install the Sentence Transformers library:
pip install -U sentence-transformers
Then you can load this model and run inference.
from sentence_transformers import CrossEncoder
# Download from the 🤗 Hub
model = CrossEncoder("cross_encoder_model_id")
# Get scores for pairs of texts
pairs = [
['When did the operator of SS Nomadic go out of business?', 'SS "Nomadic" was a steamship of the White Star Line. She was laid down in 1891, in yard 236 at Harland and Wolff Shipyards, Belfast, as a livestock carrier and completed on 14 April 1891.\n\nIn ancient times, Antrim was inhabited by a Celtic people called the Darini. In the early Middle Ages, southern County Antrim was part of the Kingdom of Ulidia, ruled by the Dál Fiatach clans Keenan and MacDonlevy/McDunlavey; the north was part of Dál Riada, which stretched into what is now western Scotland over the Irish Sea. Dál Riada was ruled by the O\'Lynch clan, who were vassals of the Ulidians. Besides the Ulidians and Dál Riada, there were the Dál nAraide of lower County Antrim, and the Cruthin, who were pre-Gaelic Celts and probably related to the Picts of Britain. Between the 8th and 11th centuries Antrim was exposed to the inroads of the Vikings.\n\nWhite Star Line Former type Partnership Industry Shipping, transportation Fate merged with Cunard Line Successor Cunard White Star Line Founded 1845 (1845) in Liverpool, England Defunct 1934 Area served Transatlantic Parent Ismay, Imrie and Co. Website www.cunard.co.uk'],
['Who founded the college Lawrence Humphrey attended?', "Lawrence Humphrey (or Laurence Humfrey) DD (1527? – 1 February 1590) was an English theologian, who was President of Magdalen College, Oxford, and Dean successively of Gloucester and Winchester.\n\nProminent theatre companies in Oklahoma include, in the capital city, Oklahoma City Theatre Company, Carpenter Square Theatre, Oklahoma Shakespeare in the Park, and CityRep. CityRep is a professional company affording equity points to those performers and technical theatre professionals. In Tulsa, Oklahoma's oldest resident professional company is American Theatre Company, and Theatre Tulsa is the oldest community theatre company west of the Mississippi. Other companies in Tulsa include Heller Theatre and Tulsa Spotlight Theater. The cities of Norman, Lawton, and Stillwater, among others, also host well-reviewed community theatre companies.\n\nHe was President of Magdalen College, Oxford, from 1480 to 1507; previously he had been a Fellow of New College, Oxford, and was brought in by William Waynflete. He was Vice-Chancellor of the University of Oxford in 1484–5, and Chancellor of the University of Oxford in 1502."],
['What was the new record label of the performer of Fame (The Game)?', "In Europe and Australia, the system was released to two separate marketing regions. One region consisted of most of mainland Europe (excluding Italy), and distribution there was handled by a number of different companies, with Nintendo responsible for most cartridge releases. Most of this region saw a 1986 release. Mattel handled distribution for the other region, consisting of the United Kingdom, Ireland, Canada, Italy, Australia and New Zealand, starting the following year. Not until the 1990s did Nintendo's newly created European branch direct distribution throughout Europe.\n\nBoeing 747 Boeing 747 - 100 of Pan American World Airways, the 747's launch customer, in September 1978 Role Wide - body jet airliner National origin United States Manufacturer Boeing Commercial Airplanes First flight February 9, 1969 Introduction January 22, 1970 with Pan American World Airways Status In service Primary users British Airways Lufthansa Korean Air Atlas Air Produced 1968 -- present Number built 1,544 as of April 2018 Program cost US $1 billion at roll - out (1968) 7.0 billion today Unit cost 747 - 100: US $24 million (1972) 747 - 200: US $39 million (1976) 747 - 300: US $83 million (1982) Variants Boeing 747SP Boeing 747 - 400 Boeing 747 - 8 Boeing VC - 25 Boeing E-4 Developed into Boeing YAL - 1 Boeing Dreamlifter\n\nThe Drinkard Singers were an American gospel singing group, most successful in the late 1950s and important in the careers of singers Cissy Houston, Dionne Warwick, Dee Dee Warwick, and Judy Clay."],
['When was the publisher of Crux launched?', 'Sleep Dank, also known as Sleep Da Danker or Sleepdank, is an American rapper signed to the late Mac Dre\'s label Thizz Entertainment.\n\nStrasbourg, well known as centre of humanism, has a long history of excellence in higher-education, at the crossroads of French and German intellectual traditions. Although Strasbourg had been annexed by the Kingdom of France in 1683, it still remained connected to the German-speaking intellectual world throughout the 18th century and the university attracted numerous students from the Holy Roman Empire, including Goethe, Metternich and Montgelas, who studied law in Strasbourg, among the most prominent. Nowadays, Strasbourg is known to offer among the best university courses in France, after Paris.\n\nGrinspoon is an Australian rock band from Lismore, New South Wales formed in 1995 and fronted by Phil Jamieson on vocals and guitar with Pat Davern on guitar, Joe Hansen on bass guitar and Kristian Hopes on drums. Also in 1995, they won the Triple J-sponsored Unearthed competition for Lismore, with their post-grunge song "Sickfest". Their name was taken from Dr. Lester Grinspoon an Associate Professor Emeritus of Psychiatry at Harvard Medical School, who supports marijuana for medical use.'],
['In what ways did Kanye draw inspiration from U2, Led Zeppelin, and the performer of Coming Down Again?', 'Titus Lucretius Tricipitinus was a politician and military leader in the early days of the Roman Republic. Twice, in the years 508 and 504 BC, he was elected Roman Consul, alongside Publius Valerius Poplicola. Also a military leader, he was victorious against Lars Porsena during his first consulate. According to Livy, he led the Roman army together with Valerius against the Sabines in 504 BC and both consuls were awarded the honour of a triumph, however the Fasti Triumphales only mention the triumph of Valerius, in May 504 BC.\n\nFresh off spending the previous year touring the world with U2 on their Vertigo Tour, West felt inspired to compose anthemic rap songs that could operate more efficiently in large arenas. To this end, West incorporated the synthesizer into his hip-hop production, utilized slower tempos, and experimented with electronic music and influenced by music of the 1980s. In addition to U2, West drew musical inspiration from arena rock bands such as The Rolling Stones and Led Zeppelin in terms of melody and chord progression. To make his next effort, the third in a planned tetralogy of education-themed studio albums, more introspective and personal in lyricism, West listened to folk and country singer-songwriters Bob Dylan and Johnny Cash in hopes of developing methods to augment his wordplay and storytelling ability.\n\n"Coming Down Again" is a song by the Rolling Stones featured on their 1973 album "Goats Head Soup". It is sung as a duet by Keith Richards and Mick Jagger.'],
]
scores = model.predict(pairs)
print(scores.shape)
# (5,)
# Or rank different texts based on similarity to a single text
ranks = model.rank(
'When did the operator of SS Nomadic go out of business?',
[
'SS "Nomadic" was a steamship of the White Star Line. She was laid down in 1891, in yard 236 at Harland and Wolff Shipyards, Belfast, as a livestock carrier and completed on 14 April 1891.\n\nIn ancient times, Antrim was inhabited by a Celtic people called the Darini. In the early Middle Ages, southern County Antrim was part of the Kingdom of Ulidia, ruled by the Dál Fiatach clans Keenan and MacDonlevy/McDunlavey; the north was part of Dál Riada, which stretched into what is now western Scotland over the Irish Sea. Dál Riada was ruled by the O\'Lynch clan, who were vassals of the Ulidians. Besides the Ulidians and Dál Riada, there were the Dál nAraide of lower County Antrim, and the Cruthin, who were pre-Gaelic Celts and probably related to the Picts of Britain. Between the 8th and 11th centuries Antrim was exposed to the inroads of the Vikings.\n\nWhite Star Line Former type Partnership Industry Shipping, transportation Fate merged with Cunard Line Successor Cunard White Star Line Founded 1845 (1845) in Liverpool, England Defunct 1934 Area served Transatlantic Parent Ismay, Imrie and Co. Website www.cunard.co.uk',
"Lawrence Humphrey (or Laurence Humfrey) DD (1527? – 1 February 1590) was an English theologian, who was President of Magdalen College, Oxford, and Dean successively of Gloucester and Winchester.\n\nProminent theatre companies in Oklahoma include, in the capital city, Oklahoma City Theatre Company, Carpenter Square Theatre, Oklahoma Shakespeare in the Park, and CityRep. CityRep is a professional company affording equity points to those performers and technical theatre professionals. In Tulsa, Oklahoma's oldest resident professional company is American Theatre Company, and Theatre Tulsa is the oldest community theatre company west of the Mississippi. Other companies in Tulsa include Heller Theatre and Tulsa Spotlight Theater. The cities of Norman, Lawton, and Stillwater, among others, also host well-reviewed community theatre companies.\n\nHe was President of Magdalen College, Oxford, from 1480 to 1507; previously he had been a Fellow of New College, Oxford, and was brought in by William Waynflete. He was Vice-Chancellor of the University of Oxford in 1484–5, and Chancellor of the University of Oxford in 1502.",
"In Europe and Australia, the system was released to two separate marketing regions. One region consisted of most of mainland Europe (excluding Italy), and distribution there was handled by a number of different companies, with Nintendo responsible for most cartridge releases. Most of this region saw a 1986 release. Mattel handled distribution for the other region, consisting of the United Kingdom, Ireland, Canada, Italy, Australia and New Zealand, starting the following year. Not until the 1990s did Nintendo's newly created European branch direct distribution throughout Europe.\n\nBoeing 747 Boeing 747 - 100 of Pan American World Airways, the 747's launch customer, in September 1978 Role Wide - body jet airliner National origin United States Manufacturer Boeing Commercial Airplanes First flight February 9, 1969 Introduction January 22, 1970 with Pan American World Airways Status In service Primary users British Airways Lufthansa Korean Air Atlas Air Produced 1968 -- present Number built 1,544 as of April 2018 Program cost US $1 billion at roll - out (1968) 7.0 billion today Unit cost 747 - 100: US $24 million (1972) 747 - 200: US $39 million (1976) 747 - 300: US $83 million (1982) Variants Boeing 747SP Boeing 747 - 400 Boeing 747 - 8 Boeing VC - 25 Boeing E-4 Developed into Boeing YAL - 1 Boeing Dreamlifter\n\nThe Drinkard Singers were an American gospel singing group, most successful in the late 1950s and important in the careers of singers Cissy Houston, Dionne Warwick, Dee Dee Warwick, and Judy Clay.",
'Sleep Dank, also known as Sleep Da Danker or Sleepdank, is an American rapper signed to the late Mac Dre\'s label Thizz Entertainment.\n\nStrasbourg, well known as centre of humanism, has a long history of excellence in higher-education, at the crossroads of French and German intellectual traditions. Although Strasbourg had been annexed by the Kingdom of France in 1683, it still remained connected to the German-speaking intellectual world throughout the 18th century and the university attracted numerous students from the Holy Roman Empire, including Goethe, Metternich and Montgelas, who studied law in Strasbourg, among the most prominent. Nowadays, Strasbourg is known to offer among the best university courses in France, after Paris.\n\nGrinspoon is an Australian rock band from Lismore, New South Wales formed in 1995 and fronted by Phil Jamieson on vocals and guitar with Pat Davern on guitar, Joe Hansen on bass guitar and Kristian Hopes on drums. Also in 1995, they won the Triple J-sponsored Unearthed competition for Lismore, with their post-grunge song "Sickfest". Their name was taken from Dr. Lester Grinspoon an Associate Professor Emeritus of Psychiatry at Harvard Medical School, who supports marijuana for medical use.',
'Titus Lucretius Tricipitinus was a politician and military leader in the early days of the Roman Republic. Twice, in the years 508 and 504 BC, he was elected Roman Consul, alongside Publius Valerius Poplicola. Also a military leader, he was victorious against Lars Porsena during his first consulate. According to Livy, he led the Roman army together with Valerius against the Sabines in 504 BC and both consuls were awarded the honour of a triumph, however the Fasti Triumphales only mention the triumph of Valerius, in May 504 BC.\n\nFresh off spending the previous year touring the world with U2 on their Vertigo Tour, West felt inspired to compose anthemic rap songs that could operate more efficiently in large arenas. To this end, West incorporated the synthesizer into his hip-hop production, utilized slower tempos, and experimented with electronic music and influenced by music of the 1980s. In addition to U2, West drew musical inspiration from arena rock bands such as The Rolling Stones and Led Zeppelin in terms of melody and chord progression. To make his next effort, the third in a planned tetralogy of education-themed studio albums, more introspective and personal in lyricism, West listened to folk and country singer-songwriters Bob Dylan and Johnny Cash in hopes of developing methods to augment his wordplay and storytelling ability.\n\n"Coming Down Again" is a song by the Rolling Stones featured on their 1973 album "Goats Head Soup". It is sung as a duet by Keith Richards and Mick Jagger.',
]
)
# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]
explorer-validationCECorrelationEvaluator| Metric | Value |
|---|---|
| pearson | 0.8782 |
| spearman | 0.8642 |
sentence_0, sentence_1, and label| sentence_0 | sentence_1 | label | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence_0 | sentence_1 | label |
|---|---|---|
When did the operator of SS Nomadic go out of business? |
SS "Nomadic" was a steamship of the White Star Line. She was laid down in 1891, in yard 236 at Harland and Wolff Shipyards, Belfast, as a livestock carrier and completed on 14 April 1891. |
1.0 |
Who founded the college Lawrence Humphrey attended? |
Lawrence Humphrey (or Laurence Humfrey) DD (1527? – 1 February 1590) was an English theologian, who was President of Magdalen College, Oxford, and Dean successively of Gloucester and Winchester. |
1.0 |
What was the new record label of the performer of Fame (The Game)? |
In Europe and Australia, the system was released to two separate marketing regions. One region consisted of most of mainland Europe (excluding Italy), and distribution there was handled by a number of different companies, with Nintendo responsible for most cartridge releases. Most of this region saw a 1986 release. Mattel handled distribution for the other region, consisting of the United Kingdom, Ireland, Canada, Italy, Australia and New Zealand, starting the following year. Not until the 1990s did Nintendo's newly created European branch direct distribution throughout Europe. |
0.0 |
BinaryCrossEntropyLoss with these parameters:{
"activation_fn": "torch.nn.modules.linear.Identity",
"pos_weight": null
}
eval_strategy: stepsper_device_train_batch_size: 4per_device_eval_batch_size: 4num_train_epochs: 1overwrite_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: 5e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1num_train_epochs: 1max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: {}warmup_ratio: 0.0warmup_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: 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}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 | explorer-validation_spearman |
|---|---|---|---|
| 0.2131 | 500 | 0.5622 | 0.8333 |
| 0.4263 | 1000 | 0.4409 | 0.8522 |
| 0.6394 | 1500 | 0.3972 | 0.8593 |
| 0.8525 | 2000 | 0.3861 | 0.8642 |
@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",
}
Base model
BAAI/bge-m3