Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 16
How to use mghuibregtse/biolinkbert-large-simcse-rat with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("mghuibregtse/biolinkbert-large-simcse-rat")
sentences = [
"Phgdh",
"Ps10",
"ENSRNOG00000054310",
"phosphoglycerate dehydrogenase"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from michiyasunaga/BioLinkBERT-large. It maps sentences & paragraphs to a 1024-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.
SentenceTransformer(
(0): Transformer({'max_seq_length': 128, 'do_lower_case': False}) with Transformer model: BertModel
(1): Pooling({'word_embedding_dimension': 1024, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': True})
)
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("sentence_transformers_model_id")
# Run inference
sentences = [
'coactivator-associated arginine methyltransferase 1',
'tRNA methyltransferase 13 homolog',
'small nucleolar RNA SNORA17',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 1024]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [3, 3]
val-evalEmbeddingSimilarityEvaluator| Metric | Value |
|---|---|
| pearson_cosine | 0.7654 |
| spearman_cosine | 0.7408 |
text1, text2, and label| text1 | text2 | label | |
|---|---|---|---|
| type | string | string | int |
| details |
|
|
|
| text1 | text2 | label |
|---|---|---|
ENSRNOG00000007053 |
mediator complex subunit 7 |
1 |
ENSRNOG00000060932 |
small nucleolar RNA SNORA55 |
1 |
ENSRNOG00000015213 |
ENSRNOG00000024039 |
0 |
ContrastiveLoss with these parameters:{
"distance_metric": "SiameseDistanceMetric.COSINE_DISTANCE",
"margin": 1.0,
"size_average": true
}
text1, text2, and label| text1 | text2 | label | |
|---|---|---|---|
| type | string | string | int |
| details |
|
|
|
| text1 | text2 | label |
|---|---|---|
ENSRNOG00000001350 |
Naa25 |
1 |
ENSRNOG00000019570 |
Gng3 |
1 |
AABR07040892.1 |
ENSRNOG00000039203 |
1 |
ContrastiveLoss with these parameters:{
"distance_metric": "SiameseDistanceMetric.COSINE_DISTANCE",
"margin": 1.0,
"size_average": true
}
eval_strategy: stepsper_device_train_batch_size: 256per_device_eval_batch_size: 256learning_rate: 3e-05num_train_epochs: 100warmup_ratio: 0.1fp16: Trueload_best_model_at_end: Trueddp_find_unused_parameters: Falseoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 256per_device_eval_batch_size: 256per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 1eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 3e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 100max_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: 42data_seed: Nonejit_mode_eval: Falseuse_ipex: Falsebf16: Falsefp16: Truefp16_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}tp_size: 0fsdp_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}deepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torchoptim_args: Noneadafactor: Falsegroup_by_length: Falselength_column_name: lengthddp_find_unused_parameters: Falseddp_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: Falsegradient_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: Falseeval_use_gather_object: Falseaverage_tokens_across_devices: Falseprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportional| Epoch | Step | Training Loss | Validation Loss | val-eval_spearman_cosine |
|---|---|---|---|---|
| 0.7072 | 500 | 0.1291 | - | - |
| 0.9986 | 706 | - | 0.1366 | -0.0396 |
| 1.4144 | 1000 | 0.1134 | - | - |
| 1.9972 | 1412 | - | 0.1040 | 0.3382 |
| 2.1216 | 1500 | 0.1066 | - | - |
| 2.8289 | 2000 | 0.0943 | - | - |
| 2.9958 | 2118 | - | 0.0867 | 0.5349 |
| 3.5361 | 2500 | 0.0863 | - | - |
| 3.9943 | 2824 | - | 0.0825 | 0.5669 |
| 4.2433 | 3000 | 0.0827 | - | - |
| 4.9505 | 3500 | 0.0806 | - | - |
| 4.9929 | 3530 | - | 0.0810 | 0.5764 |
| 5.6577 | 4000 | 0.0782 | - | - |
| 5.9915 | 4236 | - | 0.0785 | 0.5923 |
| 6.3649 | 4500 | 0.0774 | - | - |
| 6.9901 | 4942 | - | 0.0774 | 0.6017 |
| 7.0721 | 5000 | 0.0758 | - | - |
| 7.7793 | 5500 | 0.0735 | - | - |
| 7.9887 | 5648 | - | 0.0773 | 0.6034 |
| 8.4866 | 6000 | 0.0719 | - | - |
| 8.9873 | 6354 | - | 0.0765 | 0.6052 |
| 9.1938 | 6500 | 0.0701 | - | - |
| 9.9010 | 7000 | 0.0685 | - | - |
| 9.9859 | 7060 | - | 0.0753 | 0.6165 |
| 10.6082 | 7500 | 0.0651 | - | - |
| 10.9844 | 7766 | - | 0.0742 | 0.6215 |
| 11.3154 | 8000 | 0.0634 | - | - |
| 11.9830 | 8472 | - | 0.0730 | 0.6345 |
| 12.0226 | 8500 | 0.0612 | - | - |
| 12.7298 | 9000 | 0.0567 | - | - |
| 12.9816 | 9178 | - | 0.0720 | 0.6401 |
| 13.4371 | 9500 | 0.0538 | - | - |
| 13.9802 | 9884 | - | 0.0708 | 0.6514 |
| 14.1443 | 10000 | 0.0517 | - | - |
| 14.8515 | 10500 | 0.048 | - | - |
| 14.9788 | 10590 | - | 0.0691 | 0.6616 |
| 15.5587 | 11000 | 0.0436 | - | - |
| 15.9774 | 11296 | - | 0.0681 | 0.6692 |
| 16.2659 | 11500 | 0.0417 | - | - |
| 16.9731 | 12000 | 0.0394 | - | - |
| 16.9760 | 12002 | - | 0.0659 | 0.6819 |
| 17.6803 | 12500 | 0.0345 | - | - |
| 17.9745 | 12708 | - | 0.0636 | 0.6954 |
| 18.3876 | 13000 | 0.033 | - | - |
| 18.9731 | 13414 | - | 0.0621 | 0.7027 |
| 19.0948 | 13500 | 0.0313 | - | - |
| 19.8020 | 14000 | 0.028 | - | - |
| 19.9717 | 14120 | - | 0.0615 | 0.7066 |
| 20.5092 | 14500 | 0.0258 | - | - |
| 20.9703 | 14826 | - | 0.0598 | 0.7144 |
| 21.2164 | 15000 | 0.0249 | - | - |
| 21.9236 | 15500 | 0.0231 | - | - |
| 21.9689 | 15532 | - | 0.0587 | 0.7191 |
| 22.6308 | 16000 | 0.0207 | - | - |
| 22.9675 | 16238 | - | 0.0582 | 0.7215 |
| 23.3380 | 16500 | 0.0199 | - | - |
| 23.9661 | 16944 | - | 0.0575 | 0.7245 |
| 24.0453 | 17000 | 0.0194 | - | - |
| 24.7525 | 17500 | 0.0169 | - | - |
| 24.9646 | 17650 | - | 0.0562 | 0.7293 |
| 25.4597 | 18000 | 0.0161 | - | - |
| 25.9632 | 18356 | - | 0.0557 | 0.7327 |
| 26.1669 | 18500 | 0.0159 | - | - |
| 26.8741 | 19000 | 0.0146 | - | - |
| 26.9618 | 19062 | - | 0.0550 | 0.7342 |
| 27.5813 | 19500 | 0.0134 | - | - |
| 27.9604 | 19768 | - | 0.0551 | 0.7340 |
| 28.2885 | 20000 | 0.0132 | - | - |
| 28.9590 | 20474 | - | 0.0544 | 0.7373 |
| 28.9958 | 20500 | 0.0127 | - | - |
| 29.7030 | 21000 | 0.0112 | - | - |
| 29.9576 | 21180 | - | 0.0538 | 0.7387 |
| 30.4102 | 21500 | 0.011 | - | - |
| 30.9562 | 21886 | - | 0.0534 | 0.7403 |
| 31.1174 | 22000 | 0.0109 | - | - |
| 31.8246 | 22500 | 0.0099 | - | - |
| 31.9547 | 22592 | - | 0.0536 | 0.7402 |
| 32.5318 | 23000 | 0.0094 | - | - |
| 32.9533 | 23298 | - | 0.0530 | 0.7421 |
| 33.2390 | 23500 | 0.0093 | - | - |
| 33.9463 | 24000 | 0.0091 | - | - |
| 33.9519 | 24004 | - | 0.0528 | 0.7425 |
| 34.6535 | 24500 | 0.0081 | - | - |
| 34.9505 | 24710 | - | 0.0524 | 0.7435 |
| 35.3607 | 25000 | 0.0081 | - | - |
| 35.9491 | 25416 | - | 0.0529 | 0.7421 |
| 36.0679 | 25500 | 0.008 | - | - |
| 36.7751 | 26000 | 0.0072 | - | - |
| 36.9477 | 26122 | - | 0.0526 | 0.7426 |
| 37.4823 | 26500 | 0.007 | - | - |
| 37.9463 | 26828 | - | 0.0522 | 0.7439 |
| 38.1895 | 27000 | 0.007 | - | - |
| 38.8967 | 27500 | 0.0067 | - | - |
| 38.9448 | 27534 | - | 0.0529 | 0.7416 |
| 39.6040 | 28000 | 0.0062 | - | - |
| 39.9434 | 28240 | - | 0.0523 | 0.7425 |
| 40.3112 | 28500 | 0.0062 | - | - |
| 40.9420 | 28946 | - | 0.0529 | 0.7408 |
@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",
}
@inproceedings{hadsell2006dimensionality,
author={Hadsell, R. and Chopra, S. and LeCun, Y.},
booktitle={2006 IEEE Computer Society Conference on Computer Vision and Pattern Recognition (CVPR'06)},
title={Dimensionality Reduction by Learning an Invariant Mapping},
year={2006},
volume={2},
number={},
pages={1735-1742},
doi={10.1109/CVPR.2006.100}
}
Base model
michiyasunaga/BioLinkBERT-large