Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 12
This is a Cross Encoder model finetuned from Alibaba-NLP/gte-multilingual-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("lohith-chanchu/reranker-gte-multilingual-reranker-base-custom-bce")
# Get scores for pairs of texts
pairs = [
['Gaskugelhahn, Gewinde, DN 32 Gaskugelhahn, zum manuellen Absperren, geeignet für Erdgas, PN 6, nach DIN EN 331, Gehäuse aus Pressmessing, in Durchgangsform, beid seits Gewindeanschluss, DIN-DVGW-zugelassen, DN 32, einschließlich Übergangsstücke sowie Verbindungs-, Dichtungs- und Befestigungsma terial', 'DITECH Gas-KH m gelbem Hebelgriff und vollem Durchgang 11/4"'],
['Gaskugelhahn, Gewinde, DN 40 jedoch DN 40', 'DITECH Gas-KH m gelbem Hebelgriff und vollem Durchgang 11/2"'],
['Gaskugelhahn, Gewinde, DN 50 jedoch DN 50', 'DITECH Gas-KH m gelbem Hebelgriff und vollem Durchgang 2"'],
['Doppelnippel, Stahl, DN 15, Montagehöhe bis 6,0 m Doppelnippel, aus Kohlenstoffstahl, für Rohrleitung aus mittelschwerem Stahlrohr DIN EN 10255, mit Außengewinde 1/2 , Montagehöhe üb er Gelände / Fußboden bis 6,0 m', 'HS Rohrdoppelnippel Nr. 23 schwarz 1/2" 100mm'],
['Doppelnippel, Stahl, DN 20, Montagehöhe bis 6,0 m jedoch Außengewinde 3/4', 'HS Rohrdoppelnippel Nr. 23 schwarz 3/4" 100mm'],
]
scores = model.predict(pairs)
print(scores.shape)
# (5,)
# Or rank different texts based on similarity to a single text
ranks = model.rank(
'Gaskugelhahn, Gewinde, DN 32 Gaskugelhahn, zum manuellen Absperren, geeignet für Erdgas, PN 6, nach DIN EN 331, Gehäuse aus Pressmessing, in Durchgangsform, beid seits Gewindeanschluss, DIN-DVGW-zugelassen, DN 32, einschließlich Übergangsstücke sowie Verbindungs-, Dichtungs- und Befestigungsma terial',
[
'DITECH Gas-KH m gelbem Hebelgriff und vollem Durchgang 11/4"',
'DITECH Gas-KH m gelbem Hebelgriff und vollem Durchgang 11/2"',
'DITECH Gas-KH m gelbem Hebelgriff und vollem Durchgang 2"',
'HS Rohrdoppelnippel Nr. 23 schwarz 1/2" 100mm',
'HS Rohrdoppelnippel Nr. 23 schwarz 3/4" 100mm',
]
)
# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]
custom-devCrossEncoderRerankingEvaluator with these parameters:{
"at_k": 10,
"always_rerank_positives": false
}
| Metric | Value |
|---|---|
| map | 0.3148 (+0.1281) |
| mrr@10 | 0.3228 (+0.1424) |
| ndcg@10 | 0.3455 (+0.1352) |
query, answer, and label| query | answer | label | |
|---|---|---|---|
| type | string | string | int |
| details |
|
|
|
| query | answer | label |
|---|---|---|
Gaskugelhahn, Gewinde, DN 32 Gaskugelhahn, zum manuellen Absperren, geeignet für Erdgas, PN 6, nach DIN EN 331, Gehäuse aus Pressmessing, in Durchgangsform, beid seits Gewindeanschluss, DIN-DVGW-zugelassen, DN 32, einschließlich Übergangsstücke sowie Verbindungs-, Dichtungs- und Befestigungsma terial |
DITECH Gas-KH m gelbem Hebelgriff und vollem Durchgang 11/4" |
1 |
Gaskugelhahn, Gewinde, DN 40 jedoch DN 40 |
DITECH Gas-KH m gelbem Hebelgriff und vollem Durchgang 11/2" |
1 |
Gaskugelhahn, Gewinde, DN 50 jedoch DN 50 |
DITECH Gas-KH m gelbem Hebelgriff und vollem Durchgang 2" |
1 |
BinaryCrossEntropyLoss with these parameters:{
"activation_fn": "torch.nn.modules.linear.Identity",
"pos_weight": 5
}
eval_strategy: epochper_device_train_batch_size: 100per_device_eval_batch_size: 100learning_rate: 2e-05num_train_epochs: 2warmup_ratio: 0.1seed: 12bf16: Truedataloader_num_workers: 4load_best_model_at_end: Trueoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: epochprediction_loss_only: Trueper_device_train_batch_size: 100per_device_eval_batch_size: 100per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 1eval_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: 2max_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: 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: 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: 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 | custom-dev_ndcg@10 |
|---|---|---|---|
| 0.0002 | 1 | 1.5605 | - |
| 0.0224 | 100 | 0.9229 | - |
| 0.0447 | 200 | 0.4384 | - |
| 0.0671 | 300 | 0.3577 | - |
| 0.0894 | 400 | 0.3024 | - |
| 0.1118 | 500 | 0.267 | - |
| 0.1342 | 600 | 0.2393 | - |
| 0.1565 | 700 | 0.2228 | - |
| 0.1789 | 800 | 0.2196 | - |
| 0.2013 | 900 | 0.1812 | - |
| 0.2236 | 1000 | 0.2003 | - |
| 0.2460 | 1100 | 0.1756 | - |
| 0.2683 | 1200 | 0.1652 | - |
| 0.2907 | 1300 | 0.1529 | - |
| 0.3131 | 1400 | 0.1652 | - |
| 0.3354 | 1500 | 0.1327 | - |
| 0.3578 | 1600 | 0.1273 | - |
| 0.3801 | 1700 | 0.124 | - |
| 0.4025 | 1800 | 0.1371 | - |
| 0.4249 | 1900 | 0.1239 | - |
| 0.4472 | 2000 | 0.1252 | - |
| 0.4696 | 2100 | 0.115 | - |
| 0.4919 | 2200 | 0.116 | - |
| 0.5143 | 2300 | 0.1115 | - |
| 0.5367 | 2400 | 0.1157 | - |
| 0.5590 | 2500 | 0.1126 | - |
| 0.5814 | 2600 | 0.1071 | - |
| 0.6038 | 2700 | 0.1162 | - |
| 0.6261 | 2800 | 0.1088 | - |
| 0.6485 | 2900 | 0.1032 | - |
| 0.6708 | 3000 | 0.1086 | - |
| 0.6932 | 3100 | 0.0926 | - |
| 0.7156 | 3200 | 0.0846 | - |
| 0.7379 | 3300 | 0.0931 | - |
| 0.7603 | 3400 | 0.1053 | - |
| 0.7826 | 3500 | 0.0825 | - |
| 0.8050 | 3600 | 0.1116 | - |
| 0.8274 | 3700 | 0.0917 | - |
| 0.8497 | 3800 | 0.0907 | - |
| 0.8721 | 3900 | 0.0774 | - |
| 0.8945 | 4000 | 0.0789 | - |
| 0.9168 | 4100 | 0.0792 | - |
| 0.9392 | 4200 | 0.0933 | - |
| 0.9615 | 4300 | 0.0893 | - |
| 0.9839 | 4400 | 0.0993 | - |
| 1.0 | 4472 | - | 0.3409 (+0.1306) |
| 1.0063 | 4500 | 0.0755 | - |
| 1.0286 | 4600 | 0.0551 | - |
| 1.0510 | 4700 | 0.0626 | - |
| 1.0733 | 4800 | 0.0694 | - |
| 1.0957 | 4900 | 0.0537 | - |
| 1.1181 | 5000 | 0.0557 | - |
| 1.1404 | 5100 | 0.0694 | - |
| 1.1628 | 5200 | 0.0621 | - |
| 1.1852 | 5300 | 0.0661 | - |
| 1.2075 | 5400 | 0.0494 | - |
| 1.2299 | 5500 | 0.0607 | - |
| 1.2522 | 5600 | 0.0561 | - |
| 1.2746 | 5700 | 0.0513 | - |
| 1.2970 | 5800 | 0.0617 | - |
| 1.3193 | 5900 | 0.0435 | - |
| 1.3417 | 6000 | 0.0659 | - |
| 1.3640 | 6100 | 0.0597 | - |
| 1.3864 | 6200 | 0.0668 | - |
| 1.4088 | 6300 | 0.0557 | - |
| 1.4311 | 6400 | 0.0566 | - |
| 1.4535 | 6500 | 0.0632 | - |
| 1.4758 | 6600 | 0.0573 | - |
| 1.4982 | 6700 | 0.0634 | - |
| 1.5206 | 6800 | 0.054 | - |
| 1.5429 | 6900 | 0.0392 | - |
| 1.5653 | 7000 | 0.046 | - |
| 1.5877 | 7100 | 0.0562 | - |
| 1.6100 | 7200 | 0.0443 | - |
| 1.6324 | 7300 | 0.0757 | - |
| 1.6547 | 7400 | 0.0555 | - |
| 1.6771 | 7500 | 0.0345 | - |
| 1.6995 | 7600 | 0.0525 | - |
| 1.7218 | 7700 | 0.0595 | - |
| 1.7442 | 7800 | 0.0561 | - |
| 1.7665 | 7900 | 0.0484 | - |
| 1.7889 | 8000 | 0.0465 | - |
| 1.8113 | 8100 | 0.0501 | - |
| 1.8336 | 8200 | 0.0411 | - |
| 1.8560 | 8300 | 0.0386 | - |
| 1.8784 | 8400 | 0.0477 | - |
| 1.9007 | 8500 | 0.0517 | - |
| 1.9231 | 8600 | 0.0338 | - |
| 1.9454 | 8700 | 0.0466 | - |
| 1.9678 | 8800 | 0.062 | - |
| 1.9902 | 8900 | 0.0647 | - |
| 2.0 | 8944 | - | 0.3455 (+0.1352) |
| -1 | -1 | - | 0.3455 (+0.1352) |
@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
Alibaba-NLP/gte-multilingual-reranker-base