Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper
•
1908.10084
•
Published
•
12
This is a Cross Encoder model finetuned from answerdotai/ModernBERT-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("bnkc123/modernbert-base-gooaq-bce")
# Get scores for pairs of texts
pairs = [
['how many blocks can a bag of cement mould in nigeria?', '1 bag of cement produces 50 blocks so let us do the calculation,15 bags will produce 15 x 50 = 750 pieces of 6 inches blocks. So with a double tipper of sand and 15 bags of cement you will get 750 blocks.'],
['how many blocks can a bag of cement mould in nigeria?', 'Wood, cement, aggregates, metals, bricks, concrete, clay are the most common type of building material used in construction. The choice of these are based on their cost effectiveness for building projects.'],
['how many blocks can a bag of cement mould in nigeria?', 'x 16 in. Concrete Blocks are a great choice for the construction of your next masonry project. Concrete Block construction provides durability,fire resistance and thermal mass which adds to energy efficiency. Concrete block also provide high resistance to sound penetration.'],
['how many blocks can a bag of cement mould in nigeria?', "['Cement or lime concrete.', 'Bricks.', 'Flagstones.', 'Marble.', 'Glass.', 'Ceramic.', 'Plastic.', 'Mud and murram.']"],
['how many blocks can a bag of cement mould in nigeria?', "Here's the thing: Even though reusable bags are multi-use, and often made of recycled fabric, they are usually not recyclable."],
]
scores = model.predict(pairs)
print(scores.shape)
# (5,)
# Or rank different texts based on similarity to a single text
ranks = model.rank(
'how many blocks can a bag of cement mould in nigeria?',
[
'1 bag of cement produces 50 blocks so let us do the calculation,15 bags will produce 15 x 50 = 750 pieces of 6 inches blocks. So with a double tipper of sand and 15 bags of cement you will get 750 blocks.',
'Wood, cement, aggregates, metals, bricks, concrete, clay are the most common type of building material used in construction. The choice of these are based on their cost effectiveness for building projects.',
'x 16 in. Concrete Blocks are a great choice for the construction of your next masonry project. Concrete Block construction provides durability,fire resistance and thermal mass which adds to energy efficiency. Concrete block also provide high resistance to sound penetration.',
"['Cement or lime concrete.', 'Bricks.', 'Flagstones.', 'Marble.', 'Glass.', 'Ceramic.', 'Plastic.', 'Mud and murram.']",
"Here's the thing: Even though reusable bags are multi-use, and often made of recycled fabric, they are usually not recyclable.",
]
)
# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]
gooaq-devCrossEncoderRerankingEvaluator with these parameters:{
"at_k": 10,
"always_rerank_positives": false
}
| Metric | Value |
|---|---|
| map | 0.8711 (+0.0572) |
| mrr@10 | 0.8702 (+0.0576) |
| ndcg@10 | 0.8945 (+0.0451) |
question, answer, and label| question | answer | label | |
|---|---|---|---|
| type | string | string | int |
| details |
|
|
|
| question | answer | label |
|---|---|---|
how many blocks can a bag of cement mould in nigeria? |
1 bag of cement produces 50 blocks so let us do the calculation,15 bags will produce 15 x 50 = 750 pieces of 6 inches blocks. So with a double tipper of sand and 15 bags of cement you will get 750 blocks. |
1 |
how many blocks can a bag of cement mould in nigeria? |
Wood, cement, aggregates, metals, bricks, concrete, clay are the most common type of building material used in construction. The choice of these are based on their cost effectiveness for building projects. |
0 |
how many blocks can a bag of cement mould in nigeria? |
x 16 in. Concrete Blocks are a great choice for the construction of your next masonry project. Concrete Block construction provides durability,fire resistance and thermal mass which adds to energy efficiency. Concrete block also provide high resistance to sound penetration. |
0 |
BinaryCrossEntropyLoss with these parameters:{
"activation_fn": "torch.nn.modules.linear.Identity",
"pos_weight": 3
}
eval_strategy: stepsper_device_eval_batch_size: 16gradient_accumulation_steps: 8learning_rate: 2e-05num_train_epochs: 1warmup_ratio: 0.1seed: 12bf16: Truedataloader_num_workers: 4load_best_model_at_end: Trueoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 8per_device_eval_batch_size: 16per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 8eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 2e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 1max_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: 12data_seed: Nonejit_mode_eval: 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: 4dataloader_prefetch_factor: Nonepast_index: -1disable_tqdm: Falseremove_unused_columns: Truelabel_names: Noneload_best_model_at_end: Trueignore_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: lengthproject: huggingfacetrackio_space_id: trackioddp_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: 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: Trueprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | gooaq-dev_ndcg@10 |
|---|---|---|---|
| -1 | -1 | - | 0.1346 (-0.7148) |
| 0.0012 | 1 | 0.7435 | - |
| 0.0119 | 10 | 0.8952 | - |
| 0.0237 | 20 | 0.8604 | - |
| 0.0356 | 30 | 0.8869 | - |
| 0.0474 | 40 | 0.924 | - |
| 0.0593 | 50 | 0.8146 | - |
| 0.0711 | 60 | 0.9116 | - |
| 0.0830 | 70 | 0.8595 | - |
| 0.0948 | 80 | 0.8881 | - |
| 0.1067 | 90 | 0.8793 | - |
| 0.1185 | 100 | 0.8568 | - |
| 0.1304 | 110 | 0.8389 | - |
| 0.1422 | 120 | 0.8486 | - |
| 0.1541 | 130 | 0.8219 | - |
| 0.1659 | 140 | 0.8428 | - |
| 0.1778 | 150 | 0.8187 | - |
| 0.1896 | 160 | 0.7387 | - |
| 0.2015 | 170 | 0.658 | - |
| 0.2133 | 180 | 0.6728 | - |
| 0.2252 | 190 | 0.6725 | - |
| 0.2370 | 200 | 0.5657 | 0.8263 (-0.0231) |
| 0.2489 | 210 | 0.517 | - |
| 0.2607 | 220 | 0.4983 | - |
| 0.2726 | 230 | 0.5309 | - |
| 0.2844 | 240 | 0.4927 | - |
| 0.2963 | 250 | 0.5733 | - |
| 0.3081 | 260 | 0.5188 | - |
| 0.32 | 270 | 0.5496 | - |
| 0.3319 | 280 | 0.4925 | - |
| 0.3437 | 290 | 0.5078 | - |
| 0.3556 | 300 | 0.5287 | - |
| 0.3674 | 310 | 0.4579 | - |
| 0.3793 | 320 | 0.4382 | - |
| 0.3911 | 330 | 0.4201 | - |
| 0.4030 | 340 | 0.4193 | - |
| 0.4148 | 350 | 0.4398 | - |
| 0.4267 | 360 | 0.3959 | - |
| 0.4385 | 370 | 0.4356 | - |
| 0.4504 | 380 | 0.4551 | - |
| 0.4622 | 390 | 0.4156 | - |
| 0.4741 | 400 | 0.3969 | 0.8758 (+0.0264) |
| 0.4859 | 410 | 0.3614 | - |
| 0.4978 | 420 | 0.4567 | - |
| 0.5096 | 430 | 0.3743 | - |
| 0.5215 | 440 | 0.45 | - |
| 0.5333 | 450 | 0.4246 | - |
| 0.5452 | 460 | 0.39 | - |
| 0.5570 | 470 | 0.4236 | - |
| 0.5689 | 480 | 0.3827 | - |
| 0.5807 | 490 | 0.3516 | - |
| 0.5926 | 500 | 0.462 | - |
| 0.6044 | 510 | 0.4161 | - |
| 0.6163 | 520 | 0.388 | - |
| 0.6281 | 530 | 0.3719 | - |
| 0.64 | 540 | 0.4343 | - |
| 0.6519 | 550 | 0.3842 | - |
| 0.6637 | 560 | 0.422 | - |
| 0.6756 | 570 | 0.3523 | - |
| 0.6874 | 580 | 0.3907 | - |
| 0.6993 | 590 | 0.294 | - |
| 0.7111 | 600 | 0.4234 | 0.8875 (+0.0381) |
| 0.7230 | 610 | 0.4502 | - |
| 0.7348 | 620 | 0.3912 | - |
| 0.7467 | 630 | 0.3575 | - |
| 0.7585 | 640 | 0.3319 | - |
| 0.7704 | 650 | 0.3795 | - |
| 0.7822 | 660 | 0.3854 | - |
| 0.7941 | 670 | 0.3285 | - |
| 0.8059 | 680 | 0.3836 | - |
| 0.8178 | 690 | 0.3775 | - |
| 0.8296 | 700 | 0.3503 | - |
| 0.8415 | 710 | 0.3741 | - |
| 0.8533 | 720 | 0.3502 | - |
| 0.8652 | 730 | 0.3793 | - |
| 0.8770 | 740 | 0.3352 | - |
| 0.8889 | 750 | 0.3062 | - |
| 0.9007 | 760 | 0.3634 | - |
| 0.9126 | 770 | 0.3542 | - |
| 0.9244 | 780 | 0.353 | - |
| 0.9363 | 790 | 0.3565 | - |
| 0.9481 | 800 | 0.4184 | 0.8945 (+0.0451) |
@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
answerdotai/ModernBERT-base