Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 16
How to use Fallovski/CrossencoderPharma with sentence-transformers:
from sentence_transformers import CrossEncoder
model = CrossEncoder("Fallovski/CrossencoderPharma")
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 doctolib-lab/doctobert-fr-base 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': 'RobertaForSequenceClassification'})
)
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("Fallovski/CrossencoderPharma")
# Get scores for pairs of inputs
pairs = [
['KLIPAL CODEINE 300/25 MG CP /16', 'ANTHELIOS 30+ ULT YX SENS 50ML'],
['BIOTIC PLUS 100MG ENF 60ML', 'BIOTIC PLUS 500MG SACH B/14'],
['FALCIART 80/480 MG COMP B/6', 'FALCIART CPR 80/480MG BT6'],
['KLACIN CPR 625MG BT15', 'Klacin Cpr 625Mg Bt15'],
['INDOCOLLYRE 0.1% ETO F/5ML B/1', 'Indocollyre 0.1% Eto F/5Ml B/1'],
]
scores = model.predict(pairs)
print(scores)
# [9.7995e-04 1.1121e-03 9.9875e-01 9.9884e-01 9.9885e-01]
# Or rank different texts based on similarity to a single text
ranks = model.rank(
'KLIPAL CODEINE 300/25 MG CP /16',
[
'ANTHELIOS 30+ ULT YX SENS 50ML',
'BIOTIC PLUS 500MG SACH B/14',
'FALCIART CPR 80/480MG BT6',
'Klacin Cpr 625Mg Bt15',
'Indocollyre 0.1% Eto F/5Ml B/1',
]
)
# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]
validationCrossEncoderClassificationEvaluator| Metric | Value |
|---|---|
| accuracy | 0.9871 |
| accuracy_threshold | 0.5495 |
| f1 | 0.9869 |
| f1_threshold | 0.5495 |
| precision | 0.9849 |
| recall | 0.9889 |
| average_precision | 0.9981 |
sentence1, sentence2, and label| sentence1 | sentence2 | label | |
|---|---|---|---|
| type | string | string | float |
| modality | text | text | |
| details |
|
|
|
| sentence1 | sentence2 | label |
|---|---|---|
SÉROLOGIE ARBOVIRUS |
SÉROLOGIE WRIGHT |
0.0 |
SOND FOL H 15ML AA14 16CH /1 |
SOND FOL H 15ML AA14 16CH 1 |
1.0 |
FARLINE CAPRI D +1.5 MARON BLANC HOM |
FARLINE MONZA CAREY +3.0 MARON/NOIR |
0.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 | float |
| modality | text | text | |
| details |
|
|
|
| sentence1 | sentence2 | label |
|---|---|---|
KLIPAL CODEINE 300/25 MG CP /16 |
ANTHELIOS 30+ ULT YX SENS 50ML |
0.0 |
BIOTIC PLUS 100MG ENF 60ML |
BIOTIC PLUS 500MG SACH B/14 |
0.0 |
FALCIART 80/480 MG COMP B/6 |
FALCIART CPR 80/480MG BT6 |
1.0 |
BinaryCrossEntropyLoss with these parameters:{
"activation_fn": "torch.nn.modules.linear.Identity",
"pos_weight": null
}
per_device_train_batch_size: 32per_device_eval_batch_size: 32learning_rate: 2e-05num_train_epochs: 6warmup_ratio: 0.1load_best_model_at_end: Trueoverwrite_output_dir: Falsedo_predict: Falseprediction_loss_only: Trueper_device_train_batch_size: 32per_device_eval_batch_size: 32per_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: 6max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_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: Falsebf16: Falsefp16: 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: 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 | Validation Loss | validation_average_precision |
|---|---|---|---|---|
| 0.1397 | 50 | 0.6869 | - | - |
| 0.2793 | 100 | 0.3572 | - | - |
| 0.4190 | 150 | 0.1483 | - | - |
| 0.5587 | 200 | 0.13 | - | - |
| 0.6983 | 250 | 0.1394 | - | - |
| 0.8380 | 300 | 0.106 | - | - |
| 0.9777 | 350 | 0.0999 | - | - |
| 1.0 | 358 | - | 0.1673 | 0.9963 |
| 1.1173 | 400 | 0.084 | - | - |
| 1.2570 | 450 | 0.0731 | - | - |
| 1.3966 | 500 | 0.0716 | - | - |
| 1.5363 | 550 | 0.0699 | - | - |
| 1.6760 | 600 | 0.0647 | - | - |
| 1.8156 | 650 | 0.0691 | - | - |
| 1.9553 | 700 | 0.0942 | - | - |
| 2.0 | 716 | - | 0.0571 | 0.9981 |
| 2.0950 | 750 | 0.0399 | - | - |
| 2.2346 | 800 | 0.0503 | - | - |
| 2.3743 | 850 | 0.0219 | - | - |
| 2.5140 | 900 | 0.0456 | - | - |
| 2.6536 | 950 | 0.0536 | - | - |
| 2.7933 | 1000 | 0.0349 | - | - |
| 2.9330 | 1050 | 0.052 | - | - |
| 3.0 | 1074 | - | 0.0602 | 0.9983 |
| 3.0726 | 1100 | 0.0398 | - | - |
| 3.2123 | 1150 | 0.0128 | - | - |
| 3.3520 | 1200 | 0.022 | - | - |
| 3.4916 | 1250 | 0.0122 | - | - |
| 3.6313 | 1300 | 0.0265 | - | - |
| 3.7709 | 1350 | 0.04 | - | - |
| 3.9106 | 1400 | 0.0242 | - | - |
| 4.0 | 1432 | - | 0.0684 | 0.9987 |
| 4.0503 | 1450 | 0.0186 | - | - |
| 4.1899 | 1500 | 0.0185 | - | - |
| 4.3296 | 1550 | 0.0129 | - | - |
| 4.4693 | 1600 | 0.0113 | - | - |
| 4.6089 | 1650 | 0.0103 | - | - |
| 4.7486 | 1700 | 0.003 | - | - |
| 4.8883 | 1750 | 0.0207 | - | - |
| 5.0 | 1790 | - | 0.0744 | 0.9987 |
| 5.0279 | 1800 | 0.0181 | - | - |
| 5.1676 | 1850 | 0.0158 | - | - |
| 5.3073 | 1900 | 0.0156 | - | - |
| 5.4469 | 1950 | 0.0123 | - | - |
| 5.5866 | 2000 | 0.0094 | - | - |
| 5.7263 | 2050 | 0.0159 | - | - |
| 5.8659 | 2100 | 0.0033 | - | - |
| 6.0 | 2148 | - | 0.0649 | 0.9988 |
| -1 | -1 | - | - | 0.9981 |
@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
doctolib-lab/doctobert-fr-base