Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 19
How to use cross-encoder-testing/ultrabert-150m-reranker-test with sentence-transformers:
from sentence_transformers import CrossEncoder
model = CrossEncoder("cross-encoder-testing/ultrabert-150m-reranker-test", trust_remote_code=True)
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 dmis-lab/UltraBERT-150M on the parquet dataset using the sentence-transformers library. It computes scores for pairs of texts, which can be used for text reranking and semantic search.
CrossEncoder(
(0): Transformer({'transformer_task': 'sequence-classification', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'logits'}}, 'module_output_name': 'scores', 'architecture': 'UltrabertForSequenceClassification'})
)
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("tomaarsen/ultrabert-150m-reranker-msmarco524k-3e-5-20261014")
# Get scores for pairs of inputs
pairs = [
['how much does david cameron earn', "OK-So definitively David Cameron who is the current British Prime Minister earns £142,500 per year. Recently the Civil Service disclosed the salary's of all of the Cabinet members who earn over £150,000. David Cameron's £142,500 was used as a bench mark for this."],
['how much does david cameron earn', 'Celebrities wealth, income, and salary in 2016, 2017. Cameron Dallas. Handsome Vine star Cameron Dallas earned his first million before he was 20 years old. His current net worth is approximately $1.2 million as of 2017 and although he never admitted having any official girlfriend, we know the names of last two girls he was dating.'],
['distance from the island of palms to downtown charleston, sc', 'Distance, Gas Consumption and Emission Notes. Distance from Isle of Palms, SC to Charleston, SC is 18Miles or 29 Km. You can get this distance about 39 mins. If you want to planning travel with plane for 13 Miles or 20 Km, You can get this distance about 31 mins . A car with an average MPG will needs 0.83 gallons of gas to get the route between these points. The estimated cost of gas to get between Isle of Palms, SC and Charleston, SC is $1.88. During the route, an average car will release 16.26 pounds of CO 2 to the atmosphere. Your carbon footprint is 0.9 pounds of CO 2 per mile.'],
['distance from the island of palms to downtown charleston, sc', 'Once youâ\x80\x99ve done your obligatory sunbathing and beachcombing at the Isle of Palms County Park Beach, head to nearby Charleston, a 30-minute drive away, which has historic sites, landmarks, shopping districts, golf courses and family attractions like The South Carolina Aquarium and Fountain Walk, a new dining, entertainment and shopping complex nearby.'],
['how much does nicu cost per day', 'According to a 2010 article in Managed Care Magazine, the average cost for infants in NICU is around $3,000 per day. This average does not include surgeries or helicopter transports.'],
]
scores = model.predict(pairs)
print(scores)
# [ 6.9062 -3.8906 5.9688 -2.3438 4.4375]
# Or rank different texts based on similarity to a single text
ranks = model.rank(
'how much does david cameron earn',
[
"OK-So definitively David Cameron who is the current British Prime Minister earns £142,500 per year. Recently the Civil Service disclosed the salary's of all of the Cabinet members who earn over £150,000. David Cameron's £142,500 was used as a bench mark for this.",
'Celebrities wealth, income, and salary in 2016, 2017. Cameron Dallas. Handsome Vine star Cameron Dallas earned his first million before he was 20 years old. His current net worth is approximately $1.2 million as of 2017 and although he never admitted having any official girlfriend, we know the names of last two girls he was dating.',
'Distance, Gas Consumption and Emission Notes. Distance from Isle of Palms, SC to Charleston, SC is 18Miles or 29 Km. You can get this distance about 39 mins. If you want to planning travel with plane for 13 Miles or 20 Km, You can get this distance about 31 mins . A car with an average MPG will needs 0.83 gallons of gas to get the route between these points. The estimated cost of gas to get between Isle of Palms, SC and Charleston, SC is $1.88. During the route, an average car will release 16.26 pounds of CO 2 to the atmosphere. Your carbon footprint is 0.9 pounds of CO 2 per mile.',
'Once youâ\x80\x99ve done your obligatory sunbathing and beachcombing at the Isle of Palms County Park Beach, head to nearby Charleston, a 30-minute drive away, which has historic sites, landmarks, shopping districts, golf courses and family attractions like The South Carolina Aquarium and Fountain Walk, a new dining, entertainment and shopping complex nearby.',
'According to a 2010 article in Managed Care Magazine, the average cost for infants in NICU is around $3,000 per day. This average does not include surgeries or helicopter transports.',
]
)
# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]
query, passage, and label| query | passage | label | |
|---|---|---|---|
| type | string | string | float |
| modality | text | text | |
| details |
|
|
|
| query | passage | label |
|---|---|---|
how much does david cameron earn |
OK-So definitively David Cameron who is the current British Prime Minister earns £142,500 per year. Recently the Civil Service disclosed the salary's of all of the Cabinet members who earn over £150,000. David Cameron's £142,500 was used as a bench mark for this. |
1.0 |
how much does david cameron earn |
Celebrities wealth, income, and salary in 2016, 2017. Cameron Dallas. Handsome Vine star Cameron Dallas earned his first million before he was 20 years old. His current net worth is approximately $1.2 million as of 2017 and although he never admitted having any official girlfriend, we know the names of last two girls he was dating. |
0.0 |
distance from the island of palms to downtown charleston, sc |
Distance, Gas Consumption and Emission Notes. Distance from Isle of Palms, SC to Charleston, SC is 18Miles or 29 Km. You can get this distance about 39 mins. If you want to planning travel with plane for 13 Miles or 20 Km, You can get this distance about 31 mins . A car with an average MPG will needs 0.83 gallons of gas to get the route between these points. The estimated cost of gas to get between Isle of Palms, SC and Charleston, SC is $1.88. During the route, an average car will release 16.26 pounds of CO 2 to the atmosphere. Your carbon footprint is 0.9 pounds of CO 2 per mile. |
1.0 |
BinaryCrossEntropyLoss with these parameters:{
"activation_fn": "torch.nn.modules.linear.Identity",
"pos_weight": 1.0
}
per_device_train_batch_size: 32num_train_epochs: 1learning_rate: 3e-05warmup_steps: 0.05optim: adamw_torchweight_decay: 0.01gradient_accumulation_steps: 4bf16: Truetf32: Truelogging_nan_inf_filter: Falsedisable_tqdm: Trueper_device_eval_batch_size: 32push_to_hub: Truehub_private_repo: Falsehub_model_id: tomaarsen/ultrabert-150m-reranker-msmarco524k-3e-5-20261014load_best_model_at_end: Trueseed: 12data_seed: 12dataloader_num_workers: 2per_device_train_batch_size: 32num_train_epochs: 1max_steps: -1learning_rate: 3e-05lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 0.05optim: adamw_torchoptim_args: Noneweight_decay: 0.01adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08optim_target_modules: Nonegradient_accumulation_steps: 4average_tokens_across_devices: Truemax_grad_norm: 1.0label_smoothing_factor: 0.0bf16: Truefp16: Falsebf16_full_eval: Falsefp16_full_eval: Falsetf32: Truegradient_checkpointing: Falsegradient_checkpointing_kwargs: Nonetorch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Noneuse_liger_kernel: Falseliger_kernel_config: Noneuse_cache: Falseneftune_noise_alpha: Nonetorch_empty_cache_steps: Noneauto_find_batch_size: Falselog_on_each_node: Truelogging_nan_inf_filter: Falseinclude_num_input_tokens_seen: nolog_level: passivelog_level_replica: warningdisable_tqdm: Trueproject: huggingfacetrackio_space_id: Nonetrackio_bucket_id: Nonetrackio_static_space_id: Noneper_device_eval_batch_size: 32prediction_loss_only: Trueeval_on_start: Falseeval_do_concat_batches: Trueeval_use_gather_object: Falseeval_accumulation_steps: Noneinclude_for_metrics: []batch_eval_metrics: Falsesave_only_model: Falsesave_on_each_node: Falseenable_jit_checkpoint: Falsepush_to_hub: Truehub_private_repo: Falsehub_model_id: tomaarsen/ultrabert-150m-reranker-msmarco524k-3e-5-20261014hub_strategy: every_savehub_always_push: Falsehub_revision: Noneload_best_model_at_end: Trueignore_data_skip: Falserestore_callback_states_from_checkpoint: Falsefull_determinism: Falseseed: 12data_seed: 12use_cpu: Falseaccelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}parallelism_config: Nonedataloader_drop_last: Falsedataloader_num_workers: 2dataloader_pin_memory: Truedataloader_persistent_workers: Falsedataloader_prefetch_factor: Nonedataloader_multiprocessing_context: Nonedataloader_in_order: Trueremove_unused_columns: Truelabel_names: Nonetrain_sampling_strategy: randomlength_column_name: lengthddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falseddp_static_graph: Noneddp_backend: Noneddp_timeout: 1800fsdp: Nonefsdp_config: Nonedeepspeed: Nonedebug: []skip_memory_metrics: Truedo_predict: Falseresume_from_checkpoint: Nonelocal_rank: -1prompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}warmup_ratio: None| Epoch | Step | Training Loss |
|---|---|---|
| 0.0001 | 1 | 1.1699 |
| 0.0122 | 100 | 0.7252 |
| 0.0244 | 200 | 0.3373 |
| 0.0366 | 300 | 0.3011 |
| 0.0488 | 400 | 0.3020 |
| 0.0610 | 500 | 0.2891 |
| 0.0625 | 512 | - |
| 0.0732 | 600 | 0.2700 |
| 0.0854 | 700 | 0.2660 |
| 0.0977 | 800 | 0.2738 |
| 0.1099 | 900 | 0.2579 |
| 0.1221 | 1000 | 0.2588 |
| 0.125 | 1024 | - |
| 0.1343 | 1100 | 0.2357 |
| 0.1465 | 1200 | 0.2382 |
| 0.1587 | 1300 | 0.2344 |
| 0.1709 | 1400 | 0.2334 |
| 0.1831 | 1500 | 0.2306 |
| 0.1875 | 1536 | - |
| 0.1953 | 1600 | 0.2278 |
| 0.2075 | 1700 | 0.2283 |
| 0.2197 | 1800 | 0.2183 |
| 0.2319 | 1900 | 0.2187 |
| 0.2441 | 2000 | 0.2115 |
| 0.25 | 2048 | - |
| 0.2563 | 2100 | 0.2069 |
| 0.2686 | 2200 | 0.2073 |
| 0.2808 | 2300 | 0.2072 |
| 0.2930 | 2400 | 0.2138 |
| 0.3052 | 2500 | 0.2062 |
| 0.3125 | 2560 | - |
| 0.3174 | 2600 | 0.2042 |
| 0.3296 | 2700 | 0.2034 |
| 0.3418 | 2800 | 0.1919 |
| 0.3540 | 2900 | 0.1980 |
| 0.3662 | 3000 | 0.1999 |
| 0.375 | 3072 | - |
| 0.3784 | 3100 | 0.1951 |
| 0.3906 | 3200 | 0.1949 |
| 0.4028 | 3300 | 0.2005 |
| 0.4150 | 3400 | 0.1909 |
| 0.4272 | 3500 | 0.1816 |
| 0.4375 | 3584 | - |
| 0.4395 | 3600 | 0.1890 |
| 0.4517 | 3700 | 0.1866 |
| 0.4639 | 3800 | 0.1868 |
| 0.4761 | 3900 | 0.1792 |
| 0.4883 | 4000 | 0.1803 |
| 0.5 | 4096 | - |
| 0.5005 | 4100 | 0.1794 |
| 0.5127 | 4200 | 0.1795 |
| 0.5249 | 4300 | 0.1751 |
| 0.5371 | 4400 | 0.1829 |
| 0.5493 | 4500 | 0.1716 |
| 0.5615 | 4600 | 0.1632 |
| 0.5625 | 4608 | - |
| 0.5737 | 4700 | 0.1773 |
| 0.5859 | 4800 | 0.1659 |
| 0.5981 | 4900 | 0.1636 |
| 0.6104 | 5000 | 0.1716 |
| 0.6226 | 5100 | 0.1654 |
| 0.625 | 5120 | - |
| 0.6348 | 5200 | 0.1679 |
| 0.6470 | 5300 | 0.1654 |
| 0.6592 | 5400 | 0.1671 |
| 0.6714 | 5500 | 0.1579 |
| 0.6836 | 5600 | 0.1579 |
| 0.6875 | 5632 | - |
| 0.6958 | 5700 | 0.1577 |
| 0.7080 | 5800 | 0.1509 |
| 0.7202 | 5900 | 0.1551 |
| 0.7324 | 6000 | 0.1528 |
| 0.7446 | 6100 | 0.1553 |
| 0.75 | 6144 | - |
| 0.7568 | 6200 | 0.1512 |
| 0.7690 | 6300 | 0.1464 |
| 0.7812 | 6400 | 0.1461 |
| 0.7935 | 6500 | 0.1431 |
| 0.8057 | 6600 | 0.1456 |
| 0.8125 | 6656 | - |
| 0.8179 | 6700 | 0.1520 |
| 0.8301 | 6800 | 0.1416 |
| 0.8423 | 6900 | 0.1418 |
| 0.8545 | 7000 | 0.1443 |
| 0.8667 | 7100 | 0.1418 |
| 0.875 | 7168 | - |
| 0.8789 | 7200 | 0.1423 |
| 0.8911 | 7300 | 0.1359 |
| 0.9033 | 7400 | 0.1385 |
| 0.9155 | 7500 | 0.1387 |
| 0.9277 | 7600 | 0.1340 |
| 0.9375 | 7680 | - |
| 0.9399 | 7700 | 0.1313 |
| 0.9521 | 7800 | 0.1297 |
| 0.9644 | 7900 | 0.1354 |
| 0.9766 | 8000 | 0.1340 |
| 0.9888 | 8100 | 0.1354 |
| 1.0 | 8192 | - |
@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",
}
One epoch on 524,288 shared MS MARCO triplets, seed 12, LR 3e-05. Query content is clipped to 32 tokens, passage content to 256, combined cap 291. Checkpoint selected by the original 1,024-query validation set. Test scores do not select checkpoints. Experiment artifacts.
Base model
dmis-lab/UltraBERT-150M