Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 13
This is a Cross Encoder model finetuned from BAAI/bge-reranker-v2-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 = [
['Which film whose director was born first, Willy The Private Detective or No.7 Cherry Lane?', 'No.7 Cherry Lane. No.7 Cherry Lane is a 2019 Hong Kong-Chinese animated film directed by Yonfan, with animation by Zhang Gang. It was selected to compete for the Golden Lion at the 76th Venice International Film Festival. It was also selected for the 2019 Toronto International Film Festival as a Special Presentation. At the Venice Film Festival, the film won the Best Screenplay Award.'],
['Do both Jaundya Na Balasaheb and Expecting Love films have the directors from the same country?', 'Joshiy. Joshiy (born 19 July 1952) is an Indian film director from Varkala of Trivandrum in Kerala who works in the Malayalam film industry. He made his debut with "Tiger Salim" (1978) and has directed over 90 films including films with Mammootty and Mohanlal. He has also directed a few Hindi and Tamil films. In the beginning of his career, he received national fame when he directed "Dharm Aur Qanoon" (1984) starring Rajesh Khanna and Dharmendra in the lead roles, with Khanna in double roles.'],
['Who is the spouse of the composer of film Saagar (Film)?', 'Ghar Sansar. Ghar Sansar (English: House - Family; Hindi: घर संसार) is a 1986 Indian drama film, produced by Vimal Kumar under the Shivam Chitrya banner and directed by K. Bapaiah. It stars Jeetendra, Sridevi in the lead roles and music composed by Rajesh Roshan. The film is remake of the Telugu movie "Maga Maharaju" (1983), starring Chiranjeevi, Suhasini in the pivotal roles.'],
['What is the date of death of the director of film Out Of The Wreck?', "William Desmond Taylor. William Desmond Taylor (born William Cunningham Deane-Tanner, 26 April 1872 – 1 February 1922) was an Anglo-Irish-American director and actor. A popular figure in the growing Hollywood motion picture colony of the 1910s and early 1920s, he directed 59 silent films between 1914 and 1922 and acted in 27 between 1913 and 1915. Taylor's murder on 1 February 1922, along with other Hollywood scandals, such as the Roscoe Arbuckle trial, led to a frenzy of sensationalist and often fabricated newspaper reports. The murder remains an official cold case."],
['Are both Charles Liedts and Lea Lublin from the same country?', 'Lea Lublin. Lea Lublin( born 1929, Brest, Poland, died in 1999, Paris, France) was an Argentine- French performance artist. Her involvement with feminist movements and themes included the WACK! Art and the Feminist Revolution in Los Angeles in 2007.'],
]
scores = model.predict(pairs)
print(scores.shape)
# (5,)
# Or rank different texts based on similarity to a single text
ranks = model.rank(
'Which film whose director was born first, Willy The Private Detective or No.7 Cherry Lane?',
[
'No.7 Cherry Lane. No.7 Cherry Lane is a 2019 Hong Kong-Chinese animated film directed by Yonfan, with animation by Zhang Gang. It was selected to compete for the Golden Lion at the 76th Venice International Film Festival. It was also selected for the 2019 Toronto International Film Festival as a Special Presentation. At the Venice Film Festival, the film won the Best Screenplay Award.',
'Joshiy. Joshiy (born 19 July 1952) is an Indian film director from Varkala of Trivandrum in Kerala who works in the Malayalam film industry. He made his debut with "Tiger Salim" (1978) and has directed over 90 films including films with Mammootty and Mohanlal. He has also directed a few Hindi and Tamil films. In the beginning of his career, he received national fame when he directed "Dharm Aur Qanoon" (1984) starring Rajesh Khanna and Dharmendra in the lead roles, with Khanna in double roles.',
'Ghar Sansar. Ghar Sansar (English: House - Family; Hindi: घर संसार) is a 1986 Indian drama film, produced by Vimal Kumar under the Shivam Chitrya banner and directed by K. Bapaiah. It stars Jeetendra, Sridevi in the lead roles and music composed by Rajesh Roshan. The film is remake of the Telugu movie "Maga Maharaju" (1983), starring Chiranjeevi, Suhasini in the pivotal roles.',
"William Desmond Taylor. William Desmond Taylor (born William Cunningham Deane-Tanner, 26 April 1872 – 1 February 1922) was an Anglo-Irish-American director and actor. A popular figure in the growing Hollywood motion picture colony of the 1910s and early 1920s, he directed 59 silent films between 1914 and 1922 and acted in 27 between 1913 and 1915. Taylor's murder on 1 February 1922, along with other Hollywood scandals, such as the Roscoe Arbuckle trial, led to a frenzy of sensationalist and often fabricated newspaper reports. The murder remains an official cold case.",
'Lea Lublin. Lea Lublin( born 1929, Brest, Poland, died in 1999, Paris, France) was an Argentine- French performance artist. Her involvement with feminist movements and themes included the WACK! Art and the Feminist Revolution in Los Angeles in 2007.',
]
)
# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]
validation and train_subsetCEBinaryClassificationEvaluator| Metric | validation | train_subset |
|---|---|---|
| accuracy | 0.9167 | 0.896 |
| accuracy_threshold | 0.8516 | 0.8184 |
| f1 | 0.9145 | 0.9013 |
| f1_threshold | 0.8516 | 0.375 |
| precision | 0.9394 | 0.8736 |
| recall | 0.8908 | 0.9308 |
| average_precision | 0.9575 | 0.9317 |
sentence_0, sentence_1, and label| sentence_0 | sentence_1 | label | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence_0 | sentence_1 | label |
|---|---|---|
Which film whose director was born first, Willy The Private Detective or No.7 Cherry Lane? |
No.7 Cherry Lane. No.7 Cherry Lane is a 2019 Hong Kong-Chinese animated film directed by Yonfan, with animation by Zhang Gang. It was selected to compete for the Golden Lion at the 76th Venice International Film Festival. It was also selected for the 2019 Toronto International Film Festival as a Special Presentation. At the Venice Film Festival, the film won the Best Screenplay Award. |
1.0 |
Do both Jaundya Na Balasaheb and Expecting Love films have the directors from the same country? |
Joshiy. Joshiy (born 19 July 1952) is an Indian film director from Varkala of Trivandrum in Kerala who works in the Malayalam film industry. He made his debut with "Tiger Salim" (1978) and has directed over 90 films including films with Mammootty and Mohanlal. He has also directed a few Hindi and Tamil films. In the beginning of his career, he received national fame when he directed "Dharm Aur Qanoon" (1984) starring Rajesh Khanna and Dharmendra in the lead roles, with Khanna in double roles. |
0.0 |
Who is the spouse of the composer of film Saagar (Film)? |
Ghar Sansar. Ghar Sansar (English: House - Family; Hindi: घर संसार) is a 1986 Indian drama film, produced by Vimal Kumar under the Shivam Chitrya banner and directed by K. Bapaiah. It stars Jeetendra, Sridevi in the lead roles and music composed by Rajesh Roshan. The film is remake of the Telugu movie "Maga Maharaju" (1983), starring Chiranjeevi, Suhasini in the pivotal roles. |
0.0 |
BinaryCrossEntropyLoss with these parameters:{
"activation_fn": "torch.nn.modules.linear.Identity",
"pos_weight": null
}
eval_strategy: stepsper_device_train_batch_size: 2per_device_eval_batch_size: 2overwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 2per_device_eval_batch_size: 2per_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}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: Falseeval_on_start: Falseeval_use_gather_object: Falseprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | validation_average_precision | train_subset_average_precision |
|---|---|---|---|---|
| 0.1048 | 250 | - | 0.9151 | 0.8899 |
| 0.2096 | 500 | 0.6265 | 0.9387 | 0.9006 |
| 0.3145 | 750 | - | 0.9362 | 0.8994 |
| 0.4193 | 1000 | 0.4662 | 0.9397 | 0.9053 |
| 0.5241 | 1250 | - | 0.9482 | 0.9118 |
| 0.6289 | 1500 | 0.4724 | 0.9488 | 0.9143 |
| 0.7338 | 1750 | - | 0.9502 | 0.9147 |
| 0.8386 | 2000 | 0.4707 | 0.9509 | 0.9120 |
| 0.9434 | 2250 | - | 0.9522 | 0.9147 |
| 1.0 | 2385 | - | 0.9552 | - |
| 1.0482 | 2500 | 0.4326 | 0.9478 | 0.9138 |
| 1.1530 | 2750 | - | 0.9575 | 0.9317 |
@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-reranker-v2-m3