Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 19
How to use seanfarrell/icd11_ner_model_small with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("seanfarrell/icd11_ner_model_small")
sentences = [
"vascular disorders of the stomach",
"vascular disorders of the stomach, unspecified",
"ringworm of the hand",
"anogenital herpes"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from BAAI/bge-small-en-v1.5. It maps sentences & paragraphs to a 384-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, classification, clustering, and more.
SentenceTransformer(
(0): Transformer({'transformer_task': 'feature-extraction', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'last_hidden_state'}}, 'module_output_name': 'token_embeddings', 'architecture': 'BertModel'})
(1): Pooling({'embedding_dimension': 384, 'pooling_mode': 'cls', 'include_prompt': True})
(2): Normalize({})
)
First install the Sentence Transformers library:
pip install -U sentence-transformers
Then you can load this model and run inference.
from sentence_transformers import SentenceTransformer
# Download from the 🤗 Hub
model = SentenceTransformer("seanfarrell/icd11_ner_model_small")
# Run inference
queries = [
'metabolic or transporter liver disease, unspecified',
]
documents = [
'metabolic or transporter liver disease',
'spontaneous rupture of synovium or tendon, unspecified',
'staphyloma of cornea',
]
query_embeddings = model.encode_query(queries)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings.shape)
# [1, 384] [3, 384]
# Get the similarity scores for the embeddings
similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities)
# tensor([[ 0.9840, -0.1296, -0.1292]])
icd11-valInformationRetrievalEvaluator| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.7478 |
| cosine_accuracy@5 | 0.8718 |
| cosine_accuracy@10 | 0.8966 |
| cosine_precision@1 | 0.7478 |
| cosine_precision@3 | 0.6254 |
| cosine_precision@5 | 0.5259 |
| cosine_precision@10 | 0.3787 |
| cosine_recall@1 | 0.1589 |
| cosine_recall@3 | 0.3773 |
| cosine_recall@5 | 0.4796 |
| cosine_recall@10 | 0.6031 |
| cosine_ndcg@10 | 0.6649 |
| cosine_mrr@10 | 0.8007 |
| cosine_map@10 | 0.5745 |
anchor and positive| anchor | positive | |
|---|---|---|
| type | string | string |
| modality | text | text |
| details |
|
|
| anchor | positive |
|---|---|
duodenal adenoma in familial polyposis |
benign duodenal neoplasm |
congenital unilateral hip dislocation |
developmental dysplasia of hip, unilateral |
postprocedural pulmonary arterial tree disorder |
postprocedural pulmonary arterial tree complication |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim",
"gather_across_devices": false,
"directions": [
"query_to_doc"
],
"partition_mode": "joint",
"hardness_mode": null,
"hardness_strength": 0.0
}
per_device_train_batch_size: 512num_train_epochs: 1learning_rate: 2e-05lr_scheduler_type: cosinewarmup_steps: 800weight_decay: 0.01bf16: Trueper_device_eval_batch_size: 256eval_on_start: Trueload_best_model_at_end: Truedataloader_drop_last: Trueper_device_train_batch_size: 512num_train_epochs: 1max_steps: -1learning_rate: 2e-05lr_scheduler_type: cosinelr_scheduler_kwargs: Nonewarmup_steps: 800optim: adamw_torch_fusedoptim_args: Noneweight_decay: 0.01adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08optim_target_modules: Nonegradient_accumulation_steps: 1average_tokens_across_devices: Truemax_grad_norm: 1.0label_smoothing_factor: 0.0bf16: Truefp16: Falsebf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonegradient_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: Trueinclude_num_input_tokens_seen: nolog_level: passivelog_level_replica: warningdisable_tqdm: Falseproject: huggingfacetrackio_space_id: Nonetrackio_bucket_id: Nonetrackio_static_space_id: Noneper_device_eval_batch_size: 256prediction_loss_only: Trueeval_on_start: Trueeval_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: Falsehub_private_repo: Nonehub_model_id: Nonehub_strategy: every_savehub_always_push: Falsehub_revision: Noneload_best_model_at_end: Trueignore_data_skip: Falserestore_callback_states_from_checkpoint: Falsefull_determinism: Falseseed: 42data_seed: Noneuse_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: Truedataloader_num_workers: 0dataloader_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 | icd11-val_cosine_ndcg@10 |
|---|---|---|---|
| 0 | 0 | - | 0.4871 |
| 0.0063 | 50 | 2.5057 | - |
| 0.0125 | 100 | 2.1921 | - |
| 0.0187 | 150 | 1.6707 | - |
| 0.025 | 200 | 1.4270 | - |
| 0.0312 | 250 | 1.3379 | - |
| 0.0375 | 300 | 1.2811 | - |
| 0.0437 | 350 | 1.2222 | - |
| 0.05 | 400 | 1.1848 | - |
| 0.0563 | 450 | 1.1484 | - |
| 0.0625 | 500 | 1.1260 | 0.5411 |
| 0.0688 | 550 | 1.0856 | - |
| 0.075 | 600 | 1.0654 | - |
| 0.0813 | 650 | 1.0247 | - |
| 0.0875 | 700 | 1.0050 | - |
| 0.0938 | 750 | 0.9669 | - |
| 0.1 | 800 | 0.9515 | - |
| 0.1062 | 850 | 0.9404 | - |
| 0.1125 | 900 | 0.8906 | - |
| 0.1187 | 950 | 0.8692 | - |
| 0.125 | 1000 | 0.8413 | 0.5746 |
| 0.1313 | 1050 | 0.8439 | - |
| 0.1375 | 1100 | 0.8270 | - |
| 0.1437 | 1150 | 0.8128 | - |
| 0.15 | 1200 | 0.7762 | - |
| 0.1562 | 1250 | 0.7666 | - |
| 0.1625 | 1300 | 0.7555 | - |
| 0.1688 | 1350 | 0.7562 | - |
| 0.175 | 1400 | 0.7180 | - |
| 0.1812 | 1450 | 0.6945 | - |
| 0.1875 | 1500 | 0.7032 | 0.6002 |
| 0.1938 | 1550 | 0.6747 | - |
| 0.2 | 1600 | 0.6729 | - |
| 0.2062 | 1650 | 0.6604 | - |
| 0.2125 | 1700 | 0.6644 | - |
| 0.2188 | 1750 | 0.6556 | - |
| 0.225 | 1800 | 0.6440 | - |
| 0.2313 | 1850 | 0.6284 | - |
| 0.2375 | 1900 | 0.6105 | - |
| 0.2437 | 1950 | 0.5935 | - |
| 0.25 | 2000 | 0.5923 | 0.6120 |
| 0.2562 | 2050 | 0.5850 | - |
| 0.2625 | 2100 | 0.5787 | - |
| 0.2687 | 2150 | 0.5764 | - |
| 0.275 | 2200 | 0.5643 | - |
| 0.2812 | 2250 | 0.5655 | - |
| 0.2875 | 2300 | 0.5463 | - |
| 0.2938 | 2350 | 0.5414 | - |
| 0.3 | 2400 | 0.5368 | - |
| 0.3063 | 2450 | 0.5236 | - |
| 0.3125 | 2500 | 0.5109 | 0.6230 |
| 0.3187 | 2550 | 0.5308 | - |
| 0.325 | 2600 | 0.5000 | - |
| 0.3312 | 2650 | 0.5069 | - |
| 0.3375 | 2700 | 0.5120 | - |
| 0.3438 | 2750 | 0.4853 | - |
| 0.35 | 2800 | 0.4877 | - |
| 0.3563 | 2850 | 0.4786 | - |
| 0.3625 | 2900 | 0.4869 | - |
| 0.3688 | 2950 | 0.4865 | - |
| 0.375 | 3000 | 0.4561 | 0.6332 |
| 0.3812 | 3050 | 0.4640 | - |
| 0.3875 | 3100 | 0.4629 | - |
| 0.3937 | 3150 | 0.4575 | - |
| 0.4 | 3200 | 0.4493 | - |
| 0.4062 | 3250 | 0.4503 | - |
| 0.4125 | 3300 | 0.4301 | - |
| 0.4188 | 3350 | 0.4410 | - |
| 0.425 | 3400 | 0.4415 | - |
| 0.4313 | 3450 | 0.4316 | - |
| 0.4375 | 3500 | 0.4359 | 0.6441 |
| 0.4437 | 3550 | 0.4147 | - |
| 0.45 | 3600 | 0.4028 | - |
| 0.4562 | 3650 | 0.4002 | - |
| 0.4625 | 3700 | 0.4132 | - |
| 0.4688 | 3750 | 0.4021 | - |
| 0.475 | 3800 | 0.4058 | - |
| 0.4813 | 3850 | 0.4023 | - |
| 0.4875 | 3900 | 0.4038 | - |
| 0.4938 | 3950 | 0.4007 | - |
| 0.5 | 4000 | 0.3894 | 0.6501 |
| 0.5062 | 4050 | 0.3856 | - |
| 0.5125 | 4100 | 0.3879 | - |
| 0.5188 | 4150 | 0.3758 | - |
| 0.525 | 4200 | 0.3796 | - |
| 0.5312 | 4250 | 0.3890 | - |
| 0.5375 | 4300 | 0.3831 | - |
| 0.5437 | 4350 | 0.3806 | - |
| 0.55 | 4400 | 0.3781 | - |
| 0.5563 | 4450 | 0.3761 | - |
| 0.5625 | 4500 | 0.3723 | 0.6551 |
| 0.5687 | 4550 | 0.3603 | - |
| 0.575 | 4600 | 0.3595 | - |
| 0.5813 | 4650 | 0.3524 | - |
| 0.5875 | 4700 | 0.3695 | - |
| 0.5938 | 4750 | 0.3552 | - |
| 0.6 | 4800 | 0.3521 | - |
| 0.6062 | 4850 | 0.3459 | - |
| 0.6125 | 4900 | 0.3472 | - |
| 0.6188 | 4950 | 0.3511 | - |
| 0.625 | 5000 | 0.3537 | 0.6589 |
| 0.6312 | 5050 | 0.3490 | - |
| 0.6375 | 5100 | 0.3428 | - |
| 0.6438 | 5150 | 0.3492 | - |
| 0.65 | 5200 | 0.3471 | - |
| 0.6562 | 5250 | 0.3348 | - |
| 0.6625 | 5300 | 0.3404 | - |
| 0.6687 | 5350 | 0.3442 | - |
| 0.675 | 5400 | 0.3494 | - |
| 0.6813 | 5450 | 0.3306 | - |
| 0.6875 | 5500 | 0.3349 | 0.6598 |
| 0.6937 | 5550 | 0.3401 | - |
| 0.7 | 5600 | 0.3374 | - |
| 0.7063 | 5650 | 0.3306 | - |
| 0.7125 | 5700 | 0.3277 | - |
| 0.7188 | 5750 | 0.3274 | - |
| 0.725 | 5800 | 0.3318 | - |
| 0.7312 | 5850 | 0.3316 | - |
| 0.7375 | 5900 | 0.3273 | - |
| 0.7438 | 5950 | 0.3252 | - |
| 0.75 | 6000 | 0.3306 | 0.6636 |
| 0.7562 | 6050 | 0.3347 | - |
| 0.7625 | 6100 | 0.3186 | - |
| 0.7688 | 6150 | 0.3301 | - |
| 0.775 | 6200 | 0.3203 | - |
| 0.7812 | 6250 | 0.3234 | - |
| 0.7875 | 6300 | 0.3134 | - |
| 0.7937 | 6350 | 0.3175 | - |
| 0.8 | 6400 | 0.3312 | - |
| 0.8063 | 6450 | 0.3302 | - |
| 0.8125 | 6500 | 0.3189 | 0.6644 |
| 0.8187 | 6550 | 0.3191 | - |
| 0.825 | 6600 | 0.3265 | - |
| 0.8313 | 6650 | 0.3192 | - |
| 0.8375 | 6700 | 0.3111 | - |
| 0.8438 | 6750 | 0.3124 | - |
| 0.85 | 6800 | 0.3101 | - |
| 0.8562 | 6850 | 0.3188 | - |
| 0.8625 | 6900 | 0.3180 | - |
| 0.8688 | 6950 | 0.3153 | - |
| 0.875 | 7000 | 0.3159 | 0.6646 |
| 0.8812 | 7050 | 0.3132 | - |
| 0.8875 | 7100 | 0.3168 | - |
| 0.8938 | 7150 | 0.3227 | - |
| 0.9 | 7200 | 0.3121 | - |
| 0.9062 | 7250 | 0.3212 | - |
| 0.9125 | 7300 | 0.3195 | - |
| 0.9187 | 7350 | 0.3177 | - |
| 0.925 | 7400 | 0.3228 | - |
| 0.9313 | 7450 | 0.3172 | - |
| 0.9375 | 7500 | 0.3045 | 0.6652 |
| 0.9437 | 7550 | 0.3052 | - |
| 0.95 | 7600 | 0.3273 | - |
| 0.9563 | 7650 | 0.3163 | - |
| 0.9625 | 7700 | 0.3138 | - |
| 0.9688 | 7750 | 0.3280 | - |
| 0.975 | 7800 | 0.3074 | - |
| 0.9812 | 7850 | 0.3266 | - |
| 0.9875 | 7900 | 0.3214 | - |
| 0.9938 | 7950 | 0.3240 | - |
| 1.0 | 8000 | 0.3141 | 0.6649 |
@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",
}
@misc{oord2019representationlearningcontrastivepredictive,
title={Representation Learning with Contrastive Predictive Coding},
author={Aaron van den Oord and Yazhe Li and Oriol Vinyals},
year={2019},
eprint={1807.03748},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/1807.03748},
}
Base model
BAAI/bge-small-en-v1.5