Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 13
How to use jameswatanabegoogle2024/adl-hw3-reranker with sentence-transformers:
from sentence_transformers import CrossEncoder
model = CrossEncoder("jameswatanabegoogle2024/adl-hw3-reranker")
query = "Which planet is known as the Red Planet?"
passages = [
"Venus is often called Earth's twin because of its similar size and proximity.",
"Mars, known for its reddish appearance, is often referred to as the Red Planet.",
"Jupiter, the largest planet in our solar system, has a prominent red spot.",
"Saturn, famous for its rings, is sometimes mistaken for the Red Planet."
]
scores = model.predict([(query, passage) for passage in passages])
print(scores)This is a Cross Encoder model finetuned from cross-encoder/ms-marco-MiniLM-L12-v2 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 = [
['Besides the album Fight Like a Girl, are there any other interesting aspects about this article?', 'Fight Like a Girl (Bomshel song) "Fight Like a Girl" is a song recorded by American country music duo Bomshel. It was released in February 2009 as the second single and title track from their debut album "Fight Like a Girl", which was released on October 20, 2009 via Curb Records. Co-written by the duo\'s two members, Kristy Osmunson and Kelley Shepard, along with Bob Regan. The song received mixed reviews from critics who found the lyrical content cliché and indifferent to other similar songs. " Fight Like a Girl" peaked at number 30 on the "Billboard" Hot Country Songs chart. The accompanying music video for the song was directed by Eric Welch and features Bombshel performing with their guitars in front of different backgrounds. The song is a mid-tempo mostly accompanied by electric guitar. The song\'s lyrics tell of a young girl who is facing problems in her life, such as being teased on the playground at school. Her mother gives her advice by telling her to "fight like a girl." Leeann Ward of Country Universe gave the song a C rating, calling the lyrics "potentially cliched." C.M. Wilcox of The 9513, despite saying that "the singing isn\'t completely unlikeable and neither is the song," gave it a thumbs-down and compared its theme to Brooks & Dunn\'s "Cowgirls Don\'t Cry. " Bobby Peacock described the song more positively in his review of the album, saying that it had a more commercial sound than the rest of the album, but adding that it was "an appropriate introduction to the rebooted Bomshel." A music video, directed by Eric Welch, was released for the song on May 20, 2009.'],
['Did Ricky Martin try again for Menudo?', 'Charlie Masso Carlos Javier Rivera Masso (born June 13, 1969 in San Juan, Puerto Rico) is a Puerto Rican singer and actor. Masso is a former member of Menudo, joining the band at the height of Menudo\'s worldwide fame. He replaced Rene Farrait and quickly became a fan favorite with his participation on the albums of "Por Amor" and "Una Aventura Llamada Menudo", which was the soundtrack of Menudo\'s second movie. Charlie recorded 14 albums with Menudo, two were nominated for a Grammy Award for Best Latin Pop Album in 1984 and 85. Masso began his life as a Menudo the very moment that one of Menudo\'s members of the group\'s "golden era," Farrait, left the group. However, Masso\'s presence helped extend the golden era an additional three years, and when he left the group in 1987, he was the last member of the group\'s golden years to leave. Masso was a member of Menudo during their most commercially successful period in the States, which included the group\'s highest-charting U.S. single, "Hold Me" (#62 on the Billboard Hot 100.) Masso\'s bandmates included Xavier Serbia, Johnny Lozada, Ricky Melendez, Miguel Cancel, Ray Reyes, Roy Rosselló, Robby Rosa and Ricky Martin, among others. He returned to Menudo to complete a tour in Brazil, their 1987 Summer in the Streets tour, after Robby Rosa quit the group, to introduce new member Ruben Gomez and for their last tour in the Philippines when Ralphy Rodriguez was pulled out of the group by his parents late that year.'],
['Other than family, are there any other interesting aspects about the article on Vincent Price?', 'Vincent Price filmography This is the filmography of Vincent Price (May 27, 1911 – October 25, 1993), which includes appearances in theatre and television. Price made his theatre debut in the Gate Theatre\'s production of "Chicago" (1935), followed by work on Broadway. Under contract to Universal, Price traveled to Hollywood, making his screen debut in "Service de Luxe" (1938). By the 1960s, Vincent Price was working almost exclusively in the horror genre and teen film genres. Price\'s final film was "Edward Scissorhands" (1990) and the TV movie "The Heart of Justice" (1992) was his last screen appearance. Price died in Los Angeles, California on October 25, 1993.'],
['who is the leader of The Aquabats?', 'Chronicled in both live-action and animated segments, The Aquabats! Super Show! is centered around the adventures of The Aquabats, a group of superhero rock musicians who travel the countryside on a self-appointed mission to fight evil and "destroy boredom", protecting the world from the villains and creatures who threaten to destroy it while aiming to become a famous rock and roll band in their own right. The Aquabats consist of singer The MC Bat Commander (Christian Jacobs), the swaggering leader of the group; bassist Crash McLarson (Chad Larson), who can grow up to 100 feet in size; drummer Ricky Fitness (Richard Falomir), who has the power of super speed; guitarist EagleBones Falconhawk (Ian Fowles), who\'s armed with a laser-shooting electric guitar; and keyboardist Jimmy the Robot (James R. Briggs, Jr.), an android. Despite their superhuman strengths and abilities, The Aquabats are quite bumbling, disorganized, and sometimes cowardly when faced with danger; this has in fact led them to be labeled "the world\'s most inept superheroes". The band lives and travels by way of their "Battletram", a modified recreational vehicle which, despite its small exterior, has an implausibly massive interior (similar to the TARDIS from Doctor Who or The Big Bologna from The Kids From C.A.P.E.R. ), which contains, among many things, a science lab, a command center, and a living room. The Aquabats\' origin story was left intentionally vague throughout the series, a choice Jacobs explains was done for the sake of the viewer\'s imagination, as kids are more accepting of the inherent absurdity of the premise than adults tend to be: "\'There\'s five guys.'],
["Where was Frank Zappa's father from?", 'Zappa Plays Zappa Zappa Plays Zappa (previously momentarily renamed as Dweezil Zappa Plays Frank Zappa) is an American tribute act led by Dweezil Zappa, the eldest son of late American composer and musician Frank Zappa, devoted to performing the music of Frank Zappa. The band debuted in 2006 with shows in Europe, Canada, and the United States during May and June (the tour was also known as "Zappa Plays Zappa: Tour de Frank"\'). The shows presented a collection of Frank Zappa\'s rock-oriented compositions from the 1960s to the late 1970s. Apart from Dweezil Zappa on lead guitar, many of the band members previously played with Frank Zappa. Among those, Napoleon Murphy Brock (sax, flute, and vocals) was an integral part of the band, while drummer/vocalist Terry Bozzio and guitarist Steve Vai performed as guests in parts of the shows. At several shows the live band played along with audio and video recordings of Frank Zappa himself, notably portions of "Chunga\'s Revenge", "Dumb All Over", "Cosmik Debris", and "Muffin Man". After a break, the band played again in the U.S. during the fall of 2006, including a show in New York on October 31. This revived Frank Zappa\'s tradition of playing Halloween shows in New York. A DVD documenting the 2006 tour was released in early 2008. In July and August 2007, the band played a North American tour, with a core lineup similar to that of the 2006 band. The band then played in Europe during September and October before returning to the US, starting with another Halloween show in New York. Special guest on the tour was vocalist and guitarist Ray White, a Zappa stalwart performer in the 1970s and early 1980s.'],
]
scores = model.predict(pairs)
print(scores.shape)
# (5,)
# Or rank different texts based on similarity to a single text
ranks = model.rank(
'Besides the album Fight Like a Girl, are there any other interesting aspects about this article?',
[
'Fight Like a Girl (Bomshel song) "Fight Like a Girl" is a song recorded by American country music duo Bomshel. It was released in February 2009 as the second single and title track from their debut album "Fight Like a Girl", which was released on October 20, 2009 via Curb Records. Co-written by the duo\'s two members, Kristy Osmunson and Kelley Shepard, along with Bob Regan. The song received mixed reviews from critics who found the lyrical content cliché and indifferent to other similar songs. " Fight Like a Girl" peaked at number 30 on the "Billboard" Hot Country Songs chart. The accompanying music video for the song was directed by Eric Welch and features Bombshel performing with their guitars in front of different backgrounds. The song is a mid-tempo mostly accompanied by electric guitar. The song\'s lyrics tell of a young girl who is facing problems in her life, such as being teased on the playground at school. Her mother gives her advice by telling her to "fight like a girl." Leeann Ward of Country Universe gave the song a C rating, calling the lyrics "potentially cliched." C.M. Wilcox of The 9513, despite saying that "the singing isn\'t completely unlikeable and neither is the song," gave it a thumbs-down and compared its theme to Brooks & Dunn\'s "Cowgirls Don\'t Cry. " Bobby Peacock described the song more positively in his review of the album, saying that it had a more commercial sound than the rest of the album, but adding that it was "an appropriate introduction to the rebooted Bomshel." A music video, directed by Eric Welch, was released for the song on May 20, 2009.',
'Charlie Masso Carlos Javier Rivera Masso (born June 13, 1969 in San Juan, Puerto Rico) is a Puerto Rican singer and actor. Masso is a former member of Menudo, joining the band at the height of Menudo\'s worldwide fame. He replaced Rene Farrait and quickly became a fan favorite with his participation on the albums of "Por Amor" and "Una Aventura Llamada Menudo", which was the soundtrack of Menudo\'s second movie. Charlie recorded 14 albums with Menudo, two were nominated for a Grammy Award for Best Latin Pop Album in 1984 and 85. Masso began his life as a Menudo the very moment that one of Menudo\'s members of the group\'s "golden era," Farrait, left the group. However, Masso\'s presence helped extend the golden era an additional three years, and when he left the group in 1987, he was the last member of the group\'s golden years to leave. Masso was a member of Menudo during their most commercially successful period in the States, which included the group\'s highest-charting U.S. single, "Hold Me" (#62 on the Billboard Hot 100.) Masso\'s bandmates included Xavier Serbia, Johnny Lozada, Ricky Melendez, Miguel Cancel, Ray Reyes, Roy Rosselló, Robby Rosa and Ricky Martin, among others. He returned to Menudo to complete a tour in Brazil, their 1987 Summer in the Streets tour, after Robby Rosa quit the group, to introduce new member Ruben Gomez and for their last tour in the Philippines when Ralphy Rodriguez was pulled out of the group by his parents late that year.',
'Vincent Price filmography This is the filmography of Vincent Price (May 27, 1911 – October 25, 1993), which includes appearances in theatre and television. Price made his theatre debut in the Gate Theatre\'s production of "Chicago" (1935), followed by work on Broadway. Under contract to Universal, Price traveled to Hollywood, making his screen debut in "Service de Luxe" (1938). By the 1960s, Vincent Price was working almost exclusively in the horror genre and teen film genres. Price\'s final film was "Edward Scissorhands" (1990) and the TV movie "The Heart of Justice" (1992) was his last screen appearance. Price died in Los Angeles, California on October 25, 1993.',
'Chronicled in both live-action and animated segments, The Aquabats! Super Show! is centered around the adventures of The Aquabats, a group of superhero rock musicians who travel the countryside on a self-appointed mission to fight evil and "destroy boredom", protecting the world from the villains and creatures who threaten to destroy it while aiming to become a famous rock and roll band in their own right. The Aquabats consist of singer The MC Bat Commander (Christian Jacobs), the swaggering leader of the group; bassist Crash McLarson (Chad Larson), who can grow up to 100 feet in size; drummer Ricky Fitness (Richard Falomir), who has the power of super speed; guitarist EagleBones Falconhawk (Ian Fowles), who\'s armed with a laser-shooting electric guitar; and keyboardist Jimmy the Robot (James R. Briggs, Jr.), an android. Despite their superhuman strengths and abilities, The Aquabats are quite bumbling, disorganized, and sometimes cowardly when faced with danger; this has in fact led them to be labeled "the world\'s most inept superheroes". The band lives and travels by way of their "Battletram", a modified recreational vehicle which, despite its small exterior, has an implausibly massive interior (similar to the TARDIS from Doctor Who or The Big Bologna from The Kids From C.A.P.E.R. ), which contains, among many things, a science lab, a command center, and a living room. The Aquabats\' origin story was left intentionally vague throughout the series, a choice Jacobs explains was done for the sake of the viewer\'s imagination, as kids are more accepting of the inherent absurdity of the premise than adults tend to be: "\'There\'s five guys.',
'Zappa Plays Zappa Zappa Plays Zappa (previously momentarily renamed as Dweezil Zappa Plays Frank Zappa) is an American tribute act led by Dweezil Zappa, the eldest son of late American composer and musician Frank Zappa, devoted to performing the music of Frank Zappa. The band debuted in 2006 with shows in Europe, Canada, and the United States during May and June (the tour was also known as "Zappa Plays Zappa: Tour de Frank"\'). The shows presented a collection of Frank Zappa\'s rock-oriented compositions from the 1960s to the late 1970s. Apart from Dweezil Zappa on lead guitar, many of the band members previously played with Frank Zappa. Among those, Napoleon Murphy Brock (sax, flute, and vocals) was an integral part of the band, while drummer/vocalist Terry Bozzio and guitarist Steve Vai performed as guests in parts of the shows. At several shows the live band played along with audio and video recordings of Frank Zappa himself, notably portions of "Chunga\'s Revenge", "Dumb All Over", "Cosmik Debris", and "Muffin Man". After a break, the band played again in the U.S. during the fall of 2006, including a show in New York on October 31. This revived Frank Zappa\'s tradition of playing Halloween shows in New York. A DVD documenting the 2006 tour was released in early 2008. In July and August 2007, the band played a North American tour, with a core lineup similar to that of the 2006 band. The band then played in Europe during September and October before returning to the US, starting with another Halloween show in New York. Special guest on the tour was vocalist and guitarist Ray White, a Zappa stalwart performer in the 1970s and early 1980s.',
]
)
# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]
devCERerankingEvaluator with these parameters:{
"at_k": 10
}
| Metric | Value |
|---|---|
| map | 0.995 |
| mrr@10 | 0.995 |
| ndcg@10 | 0.9972 |
sentence_0, sentence_1, and label| sentence_0 | sentence_1 | label | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence_0 | sentence_1 | label |
|---|---|---|
Besides the album Fight Like a Girl, are there any other interesting aspects about this article? |
Fight Like a Girl (Bomshel song) "Fight Like a Girl" is a song recorded by American country music duo Bomshel. It was released in February 2009 as the second single and title track from their debut album "Fight Like a Girl", which was released on October 20, 2009 via Curb Records. Co-written by the duo's two members, Kristy Osmunson and Kelley Shepard, along with Bob Regan. The song received mixed reviews from critics who found the lyrical content cliché and indifferent to other similar songs. " Fight Like a Girl" peaked at number 30 on the "Billboard" Hot Country Songs chart. The accompanying music video for the song was directed by Eric Welch and features Bombshel performing with their guitars in front of different backgrounds. The song is a mid-tempo mostly accompanied by electric guitar. The song's lyrics tell of a young girl who is facing problems in her life, such as being teased on the playground at school. Her mother gives her advice by telling her to "fight like a girl." Leean... |
0.0 |
Did Ricky Martin try again for Menudo? |
Charlie Masso Carlos Javier Rivera Masso (born June 13, 1969 in San Juan, Puerto Rico) is a Puerto Rican singer and actor. Masso is a former member of Menudo, joining the band at the height of Menudo's worldwide fame. He replaced Rene Farrait and quickly became a fan favorite with his participation on the albums of "Por Amor" and "Una Aventura Llamada Menudo", which was the soundtrack of Menudo's second movie. Charlie recorded 14 albums with Menudo, two were nominated for a Grammy Award for Best Latin Pop Album in 1984 and 85. Masso began his life as a Menudo the very moment that one of Menudo's members of the group's "golden era," Farrait, left the group. However, Masso's presence helped extend the golden era an additional three years, and when he left the group in 1987, he was the last member of the group's golden years to leave. Masso was a member of Menudo during their most commercially successful period in the States, which included the group's highest-charting U.S. single, "Hold ... |
0.0 |
Other than family, are there any other interesting aspects about the article on Vincent Price? |
Vincent Price filmography This is the filmography of Vincent Price (May 27, 1911 – October 25, 1993), which includes appearances in theatre and television. Price made his theatre debut in the Gate Theatre's production of "Chicago" (1935), followed by work on Broadway. Under contract to Universal, Price traveled to Hollywood, making his screen debut in "Service de Luxe" (1938). By the 1960s, Vincent Price was working almost exclusively in the horror genre and teen film genres. Price's final film was "Edward Scissorhands" (1990) and the TV movie "The Heart of Justice" (1992) was his last screen appearance. Price died in Los Angeles, California on October 25, 1993. |
0.0 |
BinaryCrossEntropyLoss with these parameters:{
"activation_fn": "torch.nn.modules.linear.Identity",
"pos_weight": null
}
eval_strategy: stepsper_device_train_batch_size: 64per_device_eval_batch_size: 64overwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 64per_device_eval_batch_size: 64per_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: 3max_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: Falseuse_ipex: 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_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: 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: Falseneftune_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: Falseprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | dev_ndcg@10 |
|---|---|---|---|
| 0.2030 | 500 | 0.4906 | - |
| 0.2497 | 615 | - | 0.9657 |
| 0.4060 | 1000 | 0.1561 | - |
| 0.4994 | 1230 | - | 0.9874 |
| 0.6090 | 1500 | 0.1198 | - |
| 0.7491 | 1845 | - | 0.9917 |
| 0.8120 | 2000 | 0.1023 | - |
| 0.9988 | 2460 | - | 0.9899 |
| 1.0 | 2463 | - | 0.9899 |
| 1.0150 | 2500 | 0.0871 | - |
| 1.2180 | 3000 | 0.0725 | - |
| 1.2485 | 3075 | - | 0.9917 |
| 1.4210 | 3500 | 0.0727 | - |
| 1.4982 | 3690 | - | 0.9935 |
| 1.6240 | 4000 | 0.0679 | - |
| 1.7479 | 4305 | - | 0.9935 |
| 1.8270 | 4500 | 0.0635 | - |
| 1.9976 | 4920 | - | 0.9954 |
| 2.0 | 4926 | - | 0.9954 |
| 2.0300 | 5000 | 0.0619 | - |
| 2.2330 | 5500 | 0.0513 | - |
| 2.2473 | 5535 | - | 0.9954 |
| 2.4361 | 6000 | 0.0509 | - |
| 2.4970 | 6150 | - | 0.9972 |
@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
microsoft/MiniLM-L12-H384-uncased