Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 15
How to use kallilikhitha123/finetuned-bge-reranker-2403 with sentence-transformers:
from sentence_transformers import CrossEncoder
model = CrossEncoder("kallilikhitha123/finetuned-bge-reranker-2403")
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-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("kallilikhitha123/finetuned-bge-reranker-2403")
# Get scores for pairs of texts
pairs = [
['bhargavi madhavi', 'bhargavi srinidhi'],
['navya kiara', 'navya tanvi'],
['manish', 'manisha'],
['anantha padmanabha', 'ananthpadmanabha'],
['nitin singh', 'n singh'],
]
scores = model.predict(pairs)
print(scores.shape)
# (5,)
# Or rank different texts based on similarity to a single text
ranks = model.rank(
'bhargavi madhavi',
[
'bhargavi srinidhi',
'navya tanvi',
'manisha',
'ananthpadmanabha',
'n singh',
]
)
# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]
entity-matching-evalCrossEncoderClassificationEvaluator| Metric | Value |
|---|---|
| accuracy | 0.9716 |
| accuracy_threshold | 0.9984 |
| f1 | 0.9762 |
| f1_threshold | 0.9965 |
| precision | 0.988 |
| recall | 0.9647 |
| average_precision | 0.9915 |
sentence1, sentence2, and label| sentence1 | sentence2 | label | |
|---|---|---|---|
| type | string | string | int |
| details |
|
|
|
| sentence1 | sentence2 | label |
|---|---|---|
whitefield bangalore |
whitefield chennai |
0 |
shastri nagar narangpura ahmedabad |
l-5-135 block shastri nagar ahmedabad gujarat |
0 |
plot 45 kukatpally hyderabad |
plot 45 kukatpally bangalore |
0 |
BinaryCrossEntropyLoss with these parameters:{
"activation_fn": "torch.nn.modules.linear.Identity",
"pos_weight": null
}
sentence1, sentence2, and label| sentence1 | sentence2 | label | |
|---|---|---|---|
| type | string | string | int |
| details |
|
|
|
| sentence1 | sentence2 | label |
|---|---|---|
bhargavi madhavi |
bhargavi srinidhi |
0 |
navya kiara |
navya tanvi |
0 |
manish |
manisha |
0 |
BinaryCrossEntropyLoss with these parameters:{
"activation_fn": "torch.nn.modules.linear.Identity",
"pos_weight": null
}
eval_strategy: stepsper_device_eval_batch_size: 16learning_rate: 2e-05weight_decay: 0.01warmup_steps: 73remove_unused_columns: Falseload_best_model_at_end: Truedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 8per_device_eval_batch_size: 16gradient_accumulation_steps: 1eval_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: 3max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_ratio: Nonewarmup_steps: 73log_level: passivelog_level_replica: warninglog_on_each_node: Truelogging_nan_inf_filter: Trueenable_jit_checkpoint: Falsesave_on_each_node: Falsesave_only_model: Falserestore_callback_states_from_checkpoint: Falseuse_cpu: Falseseed: 42data_seed: Nonebf16: Falsefp16: Falsebf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonelocal_rank: -1ddp_backend: Nonedebug: []dataloader_drop_last: Falsedataloader_num_workers: 0dataloader_prefetch_factor: Nonedisable_tqdm: Falseremove_unused_columns: Falselabel_names: Noneload_best_model_at_end: Trueignore_data_skip: Falsefsdp: []fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}accelerator_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: Nonegroup_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: Truepush_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_for_metrics: []eval_do_concat_batches: Trueauto_find_batch_size: Falsefull_determinism: Falseddp_timeout: 1800torch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Noneinclude_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: Trueuse_cache: Falseprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | Validation Loss | entity-matching-eval_average_precision |
|---|---|---|---|---|
| 0.1463 | 36 | 0.3950 | - | - |
| 0.2927 | 72 | 0.3475 | - | - |
| 0.2967 | 73 | - | 0.3461 | 0.9648 |
| 0.1463 | 36 | 0.0637 | - | - |
| 0.2927 | 72 | 0.1365 | - | - |
| 0.2967 | 73 | - | 0.4392 | 0.9630 |
| 0.4390 | 108 | 0.4193 | - | - |
| 0.5854 | 144 | 0.2634 | - | - |
| 0.5935 | 146 | - | 0.3738 | 0.9602 |
| 0.7317 | 180 | 0.3739 | - | - |
| 0.8780 | 216 | 0.1583 | - | - |
| 0.8902 | 219 | - | 0.1850 | 0.9893 |
| 1.0244 | 252 | 0.1806 | - | - |
| 1.1707 | 288 | 0.1287 | - | - |
| 1.1870 | 292 | - | 0.4037 | 0.9836 |
| 1.3171 | 324 | 0.1883 | - | - |
| 1.4634 | 360 | 0.1562 | - | - |
| 1.4837 | 365 | - | 0.3427 | 0.9868 |
| 1.6098 | 396 | 0.0619 | - | - |
| 1.7561 | 432 | 0.0854 | - | - |
| 1.7805 | 438 | - | 0.2923 | 0.9887 |
| 1.9024 | 468 | 0.1240 | - | - |
| 2.0488 | 504 | 0.1076 | - | - |
| 2.0772 | 511 | - | 0.2441 | 0.9915 |
| 2.1951 | 540 | 0.1289 | - | - |
| 2.3415 | 576 | 0.0311 | - | - |
| 2.3740 | 584 | - | 0.2151 | 0.9923 |
| 2.4878 | 612 | 0.0181 | - | - |
| 2.6341 | 648 | 0.0982 | - | - |
| 2.6707 | 657 | - | 0.2268 | 0.9915 |
| 2.7805 | 684 | 0.0010 | - | - |
| 2.9268 | 720 | 0.0321 | - | - |
| 2.9675 | 730 | - | 0.2393 | 0.9915 |
@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