Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 17
How to use cafierom/smiles_embedding_gemma_FT_full with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("cafierom/smiles_embedding_gemma_FT_full")
sentences = [
"O[C@H](C[C@H](O)\\C=C\\c1c2CCCC(Cc3ccc(Cl)cc3)c2nn1-c1ccc(F)cc1)CC([O-])=O",
"CC(C)c1sc(c(c1\\C=C\\[C@@H](O)C[C@@H](O)CC([O-])=O)-c1ccccc1)-c1ccccc1",
"C[C@H](CC\\C=C(/C)C(O)=O)[C@H]1CC[C@@]2(C)C3=CC[C@H]4C(C)(C)[C@@H](O)CC[C@]4(C)C3=CC[C@]12C",
"CCOC(=O)COc1ccc(CC=C)cc1OC"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from google/embeddinggemma-300m. It maps sentences & paragraphs to a 768-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': 'Gemma3TextModel'})
(1): Pooling({'embedding_dimension': 768, 'pooling_mode': 'mean', 'include_prompt': True})
(2): Dense({'in_features': 768, 'out_features': 3072, 'bias': False, 'activation_function': 'torch.nn.modules.linear.Identity', 'module_input_name': 'sentence_embedding', 'module_output_name': 'sentence_embedding'})
(3): Dense({'in_features': 3072, 'out_features': 768, 'bias': False, 'activation_function': 'torch.nn.modules.linear.Identity', 'module_input_name': 'sentence_embedding', 'module_output_name': 'sentence_embedding'})
(4): 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("sentence_transformers_model_id")
# Run inference
queries = [
'CC(C)c1c(C)c(C)c(-c2ccc(F)cc2)n1CC[C@@H]1C[C@@H](O)CC(=O)O1',
]
documents = [
'O[C@@H]1C[C@H](OC(=O)C1)\\C=C\\c1c(Cl)cc(Cl)cc1OC\\C=C\\c1ccccc1',
'COc1cccc(Sc2cc3nc(C4CC4)c(\\C=C\\[C@@H]4C[C@@H](O)CC(=O)O4)c(Sc4cccc(OC)c4)c3cc2F)c1',
'C[C@H](CC\\C=C(/C)C(O)=O)[C@H]1CC[C@@]2(C)C3=CC[C@H]4C(C)(C)[C@@H](O)CC[C@]4(C)C3=CC[C@]12C',
]
query_embeddings = model.encode_query(queries)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings.shape)
# [1, 768] [3, 768]
# Get the similarity scores for the embeddings
similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities)
# tensor([[0.3374, 0.3095, 0.3194]])
premise, hypothesis, and label| premise | hypothesis | label | |
|---|---|---|---|
| type | string | string | int |
| modality | text | text | |
| details |
|
|
|
| premise | hypothesis | label |
|---|---|---|
Cc1cc(nc(-c2ccc(F)cc2)c1\C=C[C@@H](O)CC@@HCC([O-])=O)-c1ccccc1 |
Cc1cc(C)c(CCC2CC@@HCC(=O)O2)c(c1)-c1ccc(F)c(C)c1 |
0 |
COC(=O)CC@HCC@H\C=C\n1c(cc(c1-c1ccc(F)cc1)-c1cccc(Br)c1)C(C)C |
COc1cccc(Sc2c(\C=C[C@@H]3CC@@HCC(=O)O3)c(nc3ccc(F)cc23)C2CC2)c1 |
2 |
CC(C)c1c(Br)c(Br)c(-c2ccc(F)cc2)n1CCC@@HCC@@HCC([O-])=O |
CC(c1ccc(F)cc1)c1cc(C)cc(C)c1OCC(O)CC@@HCC([O-])=O |
0 |
SoftmaxLoss with these parameters:{
"num_labels": 3,
"concatenation_sent_rep": true,
"concatenation_sent_difference": true,
"concatenation_sent_multiplication": false
}
premise, hypothesis, and label| premise | hypothesis | label | |
|---|---|---|---|
| type | string | string | int |
| modality | text | text | |
| details |
|
|
|
| premise | hypothesis | label |
|---|---|---|
CC(C)c1nc(nc(-c2ccc(F)cc2)c1\C=C[C@@H]1CC@HOCc1ccccc1)N(C)S(C)(=O)=O |
O[C@@H]1CC@@HOC(=O)C1 |
2 |
CC(C)(C)c1ccc(CC2CCCc3c2nn(c3\C=C[C@@H](O)CC@@HCC([O-])=O)-c2ccc(F)cc2)cc1 |
CC(C)=CCC\C(C)=C\CCC1=CC@@Hc1cc(F)ccc1F |
2 |
CC(C)n1c(CCC@@HCC@@HCC([O-])=O)c(c(c1C(N)=O)-c1ccccn1)-c1ccc(F)cc1 |
CC(C)c1nc(nc(-c2ccc(F)cc2)c1\C=C[C@@H]1CC@@HCC(=O)O1)-c1ccc(F)cc1 |
0 |
SoftmaxLoss with these parameters:{
"num_labels": 3,
"concatenation_sent_rep": true,
"concatenation_sent_difference": true,
"concatenation_sent_multiplication": false
}
per_device_train_batch_size: 32warmup_steps: 10optim: adafactorweight_decay: 0.01bf16: Trueper_device_eval_batch_size: 32load_best_model_at_end: Truedataloader_pin_memory: Falseper_device_train_batch_size: 32num_train_epochs: 3max_steps: -1learning_rate: 5e-05lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 10optim: adafactoroptim_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: 32prediction_loss_only: Trueeval_on_start: Falseeval_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: Falsedataloader_num_workers: 0dataloader_pin_memory: Falsedataloader_persistent_workers: Falsedataloader_prefetch_factor: Noneremove_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: Nonewarmup_ratio: Nonelocal_rank: -1prompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | Validation Loss |
|---|---|---|---|
| 0.0075 | 20 | 0.9718 | - |
| 0.0151 | 40 | 0.9007 | - |
| 0.0188 | 50 | - | 0.8585 |
| 0.0226 | 60 | 0.8638 | - |
| 0.0301 | 80 | 0.8383 | - |
| 0.0376 | 100 | 0.8177 | 0.8061 |
| 0.0452 | 120 | 0.7900 | - |
| 0.0527 | 140 | 0.7714 | - |
| 0.0565 | 150 | - | 0.7483 |
| 0.0602 | 160 | 0.7685 | - |
| 0.0677 | 180 | 0.7646 | - |
| 0.0753 | 200 | 0.7267 | 0.7716 |
| 0.0828 | 220 | 0.7011 | - |
| 0.0903 | 240 | 0.7125 | - |
| 0.0941 | 250 | - | 0.6630 |
| 0.0979 | 260 | 0.6717 | - |
| 0.1054 | 280 | 0.6909 | - |
| 0.1129 | 300 | 0.6571 | 0.6595 |
| 0.1204 | 320 | 0.6452 | - |
| 0.1280 | 340 | 0.6249 | - |
| 0.1317 | 350 | - | 0.6331 |
| 0.1355 | 360 | 0.6354 | - |
| 0.1430 | 380 | 0.6096 | - |
| 0.1505 | 400 | 0.6140 | 0.5933 |
| 0.1581 | 420 | 0.5773 | - |
| 0.1656 | 440 | 0.5829 | - |
| 0.1694 | 450 | - | 0.5645 |
| 0.1731 | 460 | 0.5626 | - |
| 0.1807 | 480 | 0.5426 | - |
| 0.1882 | 500 | 0.5622 | 0.5493 |
| 0.1957 | 520 | 0.5388 | - |
| 0.2032 | 540 | 0.5175 | - |
| 0.2070 | 550 | - | 0.5402 |
| 0.2108 | 560 | 0.5439 | - |
| 0.2183 | 580 | 0.5280 | - |
| 0.2258 | 600 | 0.4912 | 0.5181 |
| 0.2333 | 620 | 0.5223 | - |
| 0.2409 | 640 | 0.5352 | - |
| 0.2446 | 650 | - | 0.4903 |
| 0.2484 | 660 | 0.4860 | - |
| 0.2559 | 680 | 0.4960 | - |
| 0.2635 | 700 | 0.4727 | 0.5087 |
| 0.2710 | 720 | 0.4897 | - |
| 0.2785 | 740 | 0.4987 | - |
| 0.2823 | 750 | - | 0.4752 |
| 0.2860 | 760 | 0.5292 | - |
| 0.2936 | 780 | 0.5049 | - |
| 0.3011 | 800 | 0.4351 | 0.4706 |
| 0.3086 | 820 | 0.4715 | - |
| 0.3161 | 840 | 0.4900 | - |
| 0.3199 | 850 | - | 0.4554 |
| 0.3237 | 860 | 0.4658 | - |
| 0.3312 | 880 | 0.4579 | - |
| 0.3387 | 900 | 0.4525 | 0.4458 |
| 0.3463 | 920 | 0.4361 | - |
| 0.3538 | 940 | 0.4663 | - |
| 0.3575 | 950 | - | 0.4305 |
| 0.3613 | 960 | 0.4590 | - |
| 0.3688 | 980 | 0.4451 | - |
| 0.3764 | 1000 | 0.4457 | 0.4188 |
| 0.3839 | 1020 | 0.4250 | - |
| 0.3914 | 1040 | 0.4195 | - |
| 0.3952 | 1050 | - | 0.3994 |
| 0.3989 | 1060 | 0.4180 | - |
| 0.4065 | 1080 | 0.3685 | - |
| 0.4140 | 1100 | 0.4286 | 0.5046 |
| 0.4215 | 1120 | 0.4912 | - |
| 0.4291 | 1140 | 0.4331 | - |
| 0.4328 | 1150 | - | 0.4072 |
| 0.4366 | 1160 | 0.3891 | - |
| 0.4441 | 1180 | 0.3991 | - |
| 0.4516 | 1200 | 0.3882 | 0.3993 |
| 0.4592 | 1220 | 0.3859 | - |
| 0.4667 | 1240 | 0.3829 | - |
| 0.4705 | 1250 | - | 0.3743 |
| 0.4742 | 1260 | 0.3745 | - |
| 0.4817 | 1280 | 0.3900 | - |
| 0.4893 | 1300 | 0.3509 | 0.3541 |
| 0.4968 | 1320 | 0.3596 | - |
| 0.5043 | 1340 | 0.3689 | - |
| 0.5081 | 1350 | - | 0.3400 |
| 0.5119 | 1360 | 0.3522 | - |
| 0.5194 | 1380 | 0.3200 | - |
| 0.5269 | 1400 | 0.3314 | 0.3305 |
| 0.5344 | 1420 | 0.3104 | - |
| 0.5420 | 1440 | 0.3830 | - |
| 0.5457 | 1450 | - | 0.3313 |
| 0.5495 | 1460 | 0.3156 | - |
| 0.5570 | 1480 | 0.3209 | - |
| 0.5645 | 1500 | 0.3023 | 0.3167 |
| 0.5721 | 1520 | 0.3266 | - |
| 0.5796 | 1540 | 0.3051 | - |
| 0.5834 | 1550 | - | 0.3093 |
| 0.5871 | 1560 | 0.2805 | - |
| 0.5947 | 1580 | 0.3092 | - |
| 0.6022 | 1600 | 0.2911 | 0.2979 |
| 0.6097 | 1620 | 0.3340 | - |
| 0.6172 | 1640 | 0.2923 | - |
| 0.6210 | 1650 | - | 0.3117 |
| 0.6248 | 1660 | 0.3332 | - |
| 0.6323 | 1680 | 0.2779 | - |
| 0.6398 | 1700 | 0.2879 | 0.2756 |
| 0.6473 | 1720 | 0.2857 | - |
| 0.6549 | 1740 | 0.2709 | - |
| 0.6586 | 1750 | - | 0.2355 |
| 0.6624 | 1760 | 0.2708 | - |
| 0.6699 | 1780 | 0.2623 | - |
| 0.6775 | 1800 | 0.2505 | 0.2744 |
| 0.6850 | 1820 | 0.2711 | - |
| 0.6925 | 1840 | 0.2410 | - |
| 0.6963 | 1850 | - | 0.2683 |
| 0.7000 | 1860 | 0.2745 | - |
| 0.7076 | 1880 | 0.2557 | - |
| 0.7151 | 1900 | 0.2798 | 0.2675 |
@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
google/embeddinggemma-300m