Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper โข 1908.10084 โข Published โข 19
How to use RR52/adl2026-hw2-reranker with sentence-transformers:
from sentence_transformers import CrossEncoder
model = CrossEncoder("RR52/adl2026-hw2-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 BAAI/bge-reranker-base 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 = [
['user: I really liked that sensitive skin concentrate I bought before, but I need a body cream for lighter skin tones now.\nassistant: Got it! Are you looking for something with a bit of tint or just moisturizing?\nuser: Just a light BB cream type thing for my body, something simple like my radiance wipes were.\nassistant: Okay, so a gentle body BB cream to even out skin tone?\nuser: Yeah exactly, something for lighter skin tones, 7.5 ounce size maybe.', 'SKIN79 Super Plus Beblesh Balm Pink BB 40g All Day Lasting BB Cream - Made In Korea\nBrand: SKIN79 Category: Beauty & Personal Care > Makeup > Face > BB Creams Features: 3 effects functional beblesh balm NEW 2005 PACKAGE whitening, wrinkles improvement Intercept ultraviolet rays UV A and B excellent cover function by composition of make-up base and foundation can correct your irregularly different skin tones naturally excellent for your skin adhesion and sebum control Details: Brand: SKIN79 Scent: Unscented Item Form: Balm Active Ingredients: Damask Rose Water, Niacinamide, Schisandra Extract Unit Count: 1.00 Count Is Discontinued By Manufacturer: No Package Dimensions: 4.02 x 2.05 x 2.01 inches; 1.41 Ounces Item model number: hot pink UPC: 794437141886 784190681859 Manufacturer: SKIN79'],
['user: I really liked that sensitive skin concentrate I bought before, but I need a body cream for lighter skin tones now.\nassistant: Got it! Are you looking for something with a bit of tint or just moisturizing?\nuser: Just a light BB cream type thing for my body, something simple like my radiance wipes were.\nassistant: Okay, so a gentle body BB cream to even out skin tone?\nuser: Yeah exactly, something for lighter skin tones, 7.5 ounce size maybe.', "COVERGIRL Clean Matte BB Cream Light 520 For Oily Skin, (packaging may vary) - 1 Fl Oz (1 Count)\nBrand: COVERGIRL Category: Beauty & Personal Care > Makeup > Face > BB Creams Features: Won't clog pores Lasts all day Oil Free BB Cream Suitable BB Cream for sensitive skin Description: Product Description COVERGIRL Clean Matte BB Cream For Light Skin provides the perfect amount of coverage to even skin tone, hide blemishes and keep you shine free all day! Brand Story By CoverGirl Details: Brand: COVERGIRL Item Form: Capsule Active Ingredients: Chloride,silica,sodium benzoate,sodium chloride Unit Count: 1 Fl Oz Number of Items: 1 Is Discontinued By Manufacturer: No Product Dimensions: 1.62 x 0.75 x 4.33 inches; 0.99 Ounces Item model number: 10022700251121 UPC: 022700251124 Manufacturer: Coty Beauty"],
['user: I really liked that sensitive skin concentrate I bought before, but I need a body cream for lighter skin tones now.\nassistant: Got it! Are you looking for something with a bit of tint or just moisturizing?\nuser: Just a light BB cream type thing for my body, something simple like my radiance wipes were.\nassistant: Okay, so a gentle body BB cream to even out skin tone?\nuser: Yeah exactly, something for lighter skin tones, 7.5 ounce size maybe.', "Puritan's Pride Arnica Cream-4 oz Cream\nBrand: Puritan's Pride Category: Beauty & Personal Care > Skin Care > Body > Moisturizers > Creams Details: Brand: Puritan's Pride Item Form: Cream Unit Count: 4 Ounce Number of Items: 1 Use for: Whole Body Is Discontinued By Manufacturer: No Package Dimensions: 2.8 x 2.7 x 2.3 inches; 2.4 Ounces Item model number: SG_B00MCJVFF6_US UPC: 766443549277"],
['user: I really liked that sensitive skin concentrate I bought before, but I need a body cream for lighter skin tones now.\nassistant: Got it! Are you looking for something with a bit of tint or just moisturizing?\nuser: Just a light BB cream type thing for my body, something simple like my radiance wipes were.\nassistant: Okay, so a gentle body BB cream to even out skin tone?\nuser: Yeah exactly, something for lighter skin tones, 7.5 ounce size maybe.', 'Rimmel London BB Cream, Light\nCategory: Beauty Description: Broad Spectrum SPF 25 Sunscreen 1 Fl oz 30 ml'],
['user: I really liked that sensitive skin concentrate I bought before, but I need a body cream for lighter skin tones now.\nassistant: Got it! Are you looking for something with a bit of tint or just moisturizing?\nuser: Just a light BB cream type thing for my body, something simple like my radiance wipes were.\nassistant: Okay, so a gentle body BB cream to even out skin tone?\nuser: Yeah exactly, something for lighter skin tones, 7.5 ounce size maybe.', "L'Oreal Paris Magic Skin Beautifier BB Cream, Fair, 1.0 Ounces\nCategory: Beauty Description: Our first multi-tasking bare skin beautifying cream enhance skinโs 6 dimensions of flawlessness leaving skin perfectly nude and natural."],
]
scores = model.predict(pairs)
print(scores.shape)
# (5,)
# Or rank different texts based on similarity to a single text
ranks = model.rank(
'user: I really liked that sensitive skin concentrate I bought before, but I need a body cream for lighter skin tones now.\nassistant: Got it! Are you looking for something with a bit of tint or just moisturizing?\nuser: Just a light BB cream type thing for my body, something simple like my radiance wipes were.\nassistant: Okay, so a gentle body BB cream to even out skin tone?\nuser: Yeah exactly, something for lighter skin tones, 7.5 ounce size maybe.',
[
'SKIN79 Super Plus Beblesh Balm Pink BB 40g All Day Lasting BB Cream - Made In Korea\nBrand: SKIN79 Category: Beauty & Personal Care > Makeup > Face > BB Creams Features: 3 effects functional beblesh balm NEW 2005 PACKAGE whitening, wrinkles improvement Intercept ultraviolet rays UV A and B excellent cover function by composition of make-up base and foundation can correct your irregularly different skin tones naturally excellent for your skin adhesion and sebum control Details: Brand: SKIN79 Scent: Unscented Item Form: Balm Active Ingredients: Damask Rose Water, Niacinamide, Schisandra Extract Unit Count: 1.00 Count Is Discontinued By Manufacturer: No Package Dimensions: 4.02 x 2.05 x 2.01 inches; 1.41 Ounces Item model number: hot pink UPC: 794437141886 784190681859 Manufacturer: SKIN79',
"COVERGIRL Clean Matte BB Cream Light 520 For Oily Skin, (packaging may vary) - 1 Fl Oz (1 Count)\nBrand: COVERGIRL Category: Beauty & Personal Care > Makeup > Face > BB Creams Features: Won't clog pores Lasts all day Oil Free BB Cream Suitable BB Cream for sensitive skin Description: Product Description COVERGIRL Clean Matte BB Cream For Light Skin provides the perfect amount of coverage to even skin tone, hide blemishes and keep you shine free all day! Brand Story By CoverGirl Details: Brand: COVERGIRL Item Form: Capsule Active Ingredients: Chloride,silica,sodium benzoate,sodium chloride Unit Count: 1 Fl Oz Number of Items: 1 Is Discontinued By Manufacturer: No Product Dimensions: 1.62 x 0.75 x 4.33 inches; 0.99 Ounces Item model number: 10022700251121 UPC: 022700251124 Manufacturer: Coty Beauty",
"Puritan's Pride Arnica Cream-4 oz Cream\nBrand: Puritan's Pride Category: Beauty & Personal Care > Skin Care > Body > Moisturizers > Creams Details: Brand: Puritan's Pride Item Form: Cream Unit Count: 4 Ounce Number of Items: 1 Use for: Whole Body Is Discontinued By Manufacturer: No Package Dimensions: 2.8 x 2.7 x 2.3 inches; 2.4 Ounces Item model number: SG_B00MCJVFF6_US UPC: 766443549277",
'Rimmel London BB Cream, Light\nCategory: Beauty Description: Broad Spectrum SPF 25 Sunscreen 1 Fl oz 30 ml',
"L'Oreal Paris Magic Skin Beautifier BB Cream, Fair, 1.0 Ounces\nCategory: Beauty Description: Our first multi-tasking bare skin beautifying cream enhance skinโs 6 dimensions of flawlessness leaving skin perfectly nude and natural.",
]
)
# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]
query, docs, and labels| query | docs | labels | |
|---|---|---|---|
| type | string | list | list |
| details |
|
|
|
| query | docs | labels |
|---|---|---|
user: I really liked that sensitive skin concentrate I bought before, but I need a body cream for lighter skin tones now. |
['SKIN79 Super Plus Beblesh Balm Pink BB 40g All Day Lasting BB Cream - Made In Korea\nBrand: SKIN79 Category: Beauty & Personal Care > Makeup > Face > BB Creams Features: 3 effects functional beblesh balm NEW 2005 PACKAGE whitening, wrinkles improvement Intercept ultraviolet rays UV A and B excellent cover function by composition of make-up base and foundation can correct your irregularly different skin tones naturally excellent for your skin adhesion and sebum control Details: Brand: SKIN79 Scent: Unscented Item Form: Balm Active Ingredients: Damask Rose Water, Niacinamide, Schisandra Extract Unit Count: 1.00 Count Is Discontinued By Manufacturer: No Package Dimensions: 4.02 x 2.05 x 2.01 inches; 1.41 Ounces Item model number: hot pink UPC: 794437141886 784190681859 Manufacturer: SKIN79', "COVERGIRL Clean Matte BB Cream Light 520 For Oily Skin, (packaging may vary) - 1 Fl Oz (1 Count)\nBrand: COVERGIRL Category: Beauty & Personal Care > Makeup > Face > BB Creams Features: Won't clog ... |
[0.0, 0.0, 0.0, 0.0, 0.0, ...] |
user: I've been happy with that silk protein hair treatment and my foaming face scrub, but my hair's been feeling kinda weak lately. |
['Mizani Scalp Care Calming Scalp Lotion |Dandruff Treatment | Nourishes & Soothes Scalp | For Curly Hair | 4 Fl Oz\nBrand: MIZANI Category: Beauty & Personal Care > Salon & Spa > Hair Care > Hair & Scalp Treatments Details: Brand: MIZANI Hair Type: Curly Product Benefits: A nourishing lotion to soothe and treat dry scalp. Primes hair with a healthy no,dandruff shine. Item Form: Lotion,Oil Scent: Eucalyptus Is Discontinued By Manufacturer: No Product Dimensions: 1.25 x 2.19 x 6.06 inches; 4.66 Ounces Item model number: 955600 UPC: 884486493859 884486307361 Manufacturer: Mizani Country of Origin: USA', 'Renpure Plant-Based Beauty Tea Tree Lemon Sage Refreshing Moisture Scalp Serum, 4 Fluid Ounces\nBrand: RENPURE Category: Beauty & Personal Care > Hair Care Features: Scalp Serum: The perfect partner to our scalp scrub, this scalp serum uses plant based conditioning nutrients to give your scalp a fresh finish; Tea tree oil and ginger mint cool and invigorate Invigorating Nutrients: Our Te... |
[0.0, 0.0, 1.0, 0.0, 0.0, ...] |
user: I want a collectible figure from a movie I like. Something small to put on my shelf would be nice. |
["Funko Pop Marvel: Marvel Studios 10 - Gamora (Gold Chrome) Collectible Figure, Multicolor\nBrand: Funko Category: Toys & Games > Toy Figures & Playsets > Action Figures Features: From Marvel Studios 10, Gamora (Gold Chrome), as a stylized POP vinyl from Funko! Stylized collectable stands 3 ยพ inches tall, perfect for any Marvel Studios 10 fan! Collect and display all Marvel Studios 10 figures from Funko! Funko pop! is the 2017 toy of the year and people's choice award winner Description: From Marvel Studios 10, Gamora (gold chrome), as a stylized pop vinyl from Funko! figure stands 3 3/4 inches and comes in a window display box. Check out the other Marvel Studios 10 figures from Funko! collect them all! Details: Product Dimensions: 3.54 x 2.95 x 3.54 inches Item Weight: 3.53 ounces Item model number: 33519 Manufacturer recommended age: 6 years and up Best Sellers Rank: {'Toys & Games': 119252, 'Action Figures': 7062} Is Discontinued By Manufacturer: No Release date: November 27, 2018 ... |
[0.0, 0.0, 0.0, 0.0, 0.0, ...] |
LambdaLoss with these parameters:{
"weighting_scheme": "sentence_transformers.cross_encoder.losses.LambdaLoss.NDCGLoss2PPScheme",
"k": null,
"sigma": 1.0,
"eps": 1e-10,
"reduction_log": "binary",
"activation_fn": "torch.nn.modules.linear.Identity",
"mini_batch_size": null
}
per_device_train_batch_size: 4gradient_accumulation_steps: 4learning_rate: 2e-05weight_decay: 0.01num_train_epochs: 1.0warmup_ratio: 0.1bf16: Trueoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: noprediction_loss_only: Trueper_device_train_batch_size: 4per_device_eval_batch_size: 8per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 4eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 2e-05weight_decay: 0.01adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 1.0max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: {}warmup_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: 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}parallelism_config: Nonedeepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torch_fusedoptim_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 |
|---|---|---|
| 0.0662 | 20 | 0.6081 |
| 0.1325 | 40 | 0.4911 |
| 0.1987 | 60 | 0.3882 |
| 0.2649 | 80 | 0.3833 |
| 0.3311 | 100 | 0.3534 |
| 0.3974 | 120 | 0.3549 |
| 0.4636 | 140 | 0.3329 |
| 0.5298 | 160 | 0.3258 |
| 0.5960 | 180 | 0.3598 |
| 0.6623 | 200 | 0.356 |
| 0.7285 | 220 | 0.3405 |
| 0.7947 | 240 | 0.3487 |
| 0.8609 | 260 | 0.3551 |
| 0.9272 | 280 | 0.3589 |
| 0.9934 | 300 | 0.3399 |
@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",
}
@inproceedings{wang2018lambdaloss,
title={The LambdaLoss Framework for Ranking Metric Optimization},
author={Wang, Xuanhui and Li, Cheng and Golbandi, Nadav and Bendersky, Michael and Najork, Marc},
booktitle={Proceedings of the 27th ACM international conference on information and knowledge management},
pages={1313--1322},
year={2018}
}
Base model
BAAI/bge-reranker-base