Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 16
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 = [
"CCc1nc(cc(-c2ccc(F)cc2)c1CCC1C[C@@H](O)CC(=O)O1)-c1ccccc1",
"CC[C@H](C)C(=O)O[C@H]1C[C@@H](C)[C@H](O)C2=C[C@@H](O)[C@H](C)[C@H](CC[C@@H]3CC=CC(=O)O3)[C@@H]12",
"CCCCCCCCCCCCCCCC(O)(CC(O)=O)CC(O)=O",
"COc1cccc(CNC(=O)c2nn(c(OC[C@@H](O)C[C@@H](O)CC(O)=O)c2C(C)C)-c2ccc(F)cc2)c1"
]
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)c1cc(c(-c2ccc(F)cc2)n1\\C=C\\[C@@H](O)C[C@@H](O)CC([O-])=O)-c1ccccn1',
]
documents = [
'CC(C)=CCC\\C(C)=C\\CCC1=C[C@@H](OC1=O)c1ccccc1O',
'CCCCc1cc(OC)c(OC)cc1OC',
'CO[C@@H]1C[C@H](OC(=O)C1)\\C=C\\c1c(C)cc(C)cc1-c1ccc(F)c(C)c1',
]
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.0571, -0.0621, 0.5212]])
premise, hypothesis, and label| premise | hypothesis | label | |
|---|---|---|---|
| type | string | string | int |
| modality | text | text | |
| details |
|
|
|
| premise | hypothesis | label |
|---|---|---|
CCC(C)(C)C(=O)O[C@H]1CC@(CSc2ccccc2)O[C@@H]2CCC@HC@HC12 |
Cc1nnnn1C(\C=C[C@@H](O)CC@@HCC([O-])=O)=C(c1ccc(F)cc1)c1ccc(F)cc1 |
2 |
CCn1c(CCC@@HCC@@HCC([O-])=O)c(c(C)c1C(=O)Nc1ccccc1)-c1ccc(F)cc1 |
O[C@@H]1CC@H\C=C\c1c(Cl)cc(Cl)cc1OCc1cccnc1 |
2 |
CC(C)c1c(c(c(-c2ccc(F)cc2)n1CCC@@HCC@@HCC([O-])=O)-c1ccc(F)cc1)S(=O)(=O)Nc1cccc(CC(N)=O)c1 |
COc1ccc(OC)c(c1)[C@@H]1OC(=O)C(CC\C=C(/C)CCC=C(C)C)=C1 |
2 |
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 |
|---|---|---|
O[C@@H]1CC(CCc2ccccc2-c2ccccc2)OC(=O)C1 |
O[C@@H]1CC@H\C=C\c1ccc(Cl)cc1Cl |
0 |
CC(C)n1c(CCC@@HCC@@HCC([O-])=O)c(c2CCCN(c3ccccc3)C(=O)c12)-c1ccc(F)cc1 |
CC(C)c1ccc(Sc2cc3c(Sc4ccc(cc4)C(C)C)c(\C=C[C@@H]4CC@@HCC(=O)O4)cnc3c(Sc3ccc(cc3)C(C)C)c2Sc2ccc(cc2)C(C)C)cc1 |
2 |
CC(C)c1c(cc(-c2ccc(F)cc2)n1CC[C@@H]1CC@@HCC(=O)O1)-c1ccccc1 |
CC(CCc1ccc2c(c1)-c1ccccc1S2(=O)=O)CC(O)=O |
2 |
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.0150 | 20 | 0.9755 | - |
| 0.0301 | 40 | 0.9023 | - |
| 0.0376 | 50 | - | 0.8855 |
| 0.0451 | 60 | 0.8828 | - |
| 0.0602 | 80 | 0.8538 | - |
| 0.0752 | 100 | 0.8304 | 0.8613 |
| 0.0903 | 120 | 0.8119 | - |
| 0.1053 | 140 | 0.7917 | - |
| 0.1129 | 150 | - | 0.7640 |
| 0.1204 | 160 | 0.7857 | - |
| 0.1354 | 180 | 0.7664 | - |
| 0.1505 | 200 | 0.7574 | 0.7473 |
| 0.1655 | 220 | 0.7350 | - |
| 0.1806 | 240 | 0.7296 | - |
| 0.1881 | 250 | - | 0.7173 |
| 0.1956 | 260 | 0.7332 | - |
| 0.2107 | 280 | 0.7386 | - |
| 0.2257 | 300 | 0.7079 | 0.7244 |
| 0.2408 | 320 | 0.6684 | - |
| 0.2558 | 340 | 0.6670 | - |
| 0.2634 | 350 | - | 0.6760 |
| 0.2709 | 360 | 0.6600 | - |
| 0.2859 | 380 | 0.6630 | - |
| 0.3010 | 400 | 0.6050 | 0.6227 |
| 0.3160 | 420 | 0.6080 | - |
| 0.3311 | 440 | 0.6267 | - |
| 0.3386 | 450 | - | 0.6153 |
| 0.3461 | 460 | 0.6197 | - |
| 0.3612 | 480 | 0.6111 | - |
| 0.3762 | 500 | 0.5984 | 0.5897 |
| 0.3913 | 520 | 0.6073 | - |
| 0.4063 | 540 | 0.5479 | - |
| 0.4138 | 550 | - | 0.5703 |
| 0.4214 | 560 | 0.5916 | - |
| 0.4364 | 580 | 0.5567 | - |
| 0.4515 | 600 | 0.6482 | 0.7078 |
| 0.4665 | 620 | 0.5991 | - |
| 0.4816 | 640 | 0.5820 | - |
| 0.4891 | 650 | - | 0.5583 |
| 0.4966 | 660 | 0.5783 | - |
| 0.5117 | 680 | 0.5352 | - |
| 0.5267 | 700 | 0.5344 | 0.5442 |
| 0.5418 | 720 | 0.5527 | - |
| 0.5568 | 740 | 0.5349 | - |
| 0.5643 | 750 | - | 0.5376 |
| 0.5719 | 760 | 0.5310 | - |
| 0.5869 | 780 | 0.5384 | - |
| 0.6020 | 800 | 0.4973 | 0.5414 |
| 0.6170 | 820 | 0.5212 | - |
| 0.6321 | 840 | 0.4855 | - |
| 0.6396 | 850 | - | 0.5125 |
| 0.6471 | 860 | 0.5038 | - |
| 0.6622 | 880 | 0.5001 | - |
| 0.6772 | 900 | 0.4910 | 0.5051 |
| 0.6922 | 920 | 0.5000 | - |
| 0.7073 | 940 | 0.4682 | - |
| 0.7148 | 950 | - | 0.4980 |
| 0.7223 | 960 | 0.4830 | - |
| 0.7374 | 980 | 0.5125 | - |
| 0.7524 | 1000 | 0.5118 | 0.4886 |
| 0.7675 | 1020 | 0.4507 | - |
| 0.7825 | 1040 | 0.4715 | - |
| 0.7901 | 1050 | - | 0.4867 |
| 0.7976 | 1060 | 0.5020 | - |
| 0.8126 | 1080 | 0.4806 | - |
| 0.8277 | 1100 | 0.4737 | 0.4858 |
| 0.8427 | 1120 | 0.4677 | - |
| 0.8578 | 1140 | 0.4579 | - |
| 0.8653 | 1150 | - | 0.4536 |
| 0.8728 | 1160 | 0.4481 | - |
| 0.8879 | 1180 | 0.4897 | - |
| 0.9029 | 1200 | 0.4500 | 0.4570 |
| 0.9180 | 1220 | 0.4647 | - |
| 0.9330 | 1240 | 0.4498 | - |
| 0.9406 | 1250 | - | 0.4436 |
| 0.9481 | 1260 | 0.4429 | - |
| 0.9631 | 1280 | 0.4748 | - |
| 0.9782 | 1300 | 0.4139 | 0.4568 |
| 0.9932 | 1320 | 0.4340 | - |
| 1.0083 | 1340 | 0.4404 | - |
| 1.0158 | 1350 | - | 0.4689 |
| 1.0233 | 1360 | 0.4709 | - |
| 1.0384 | 1380 | 0.4103 | - |
| 1.0534 | 1400 | 0.3984 | 0.4238 |
| 1.0685 | 1420 | 0.4082 | - |
| 1.0835 | 1440 | 0.4505 | - |
| 1.091 | 1450 | - | 0.3957 |
| 1.0986 | 1460 | 0.4392 | - |
| 1.1136 | 1480 | 0.3966 | - |
| 1.1287 | 1500 | 0.3717 | 0.4049 |
| 1.1437 | 1520 | 0.3994 | - |
| 1.1588 | 1540 | 0.4006 | - |
| 1.1663 | 1550 | - | 0.4244 |
| 1.1738 | 1560 | 0.4005 | - |
| 1.1889 | 1580 | 0.3951 | - |
| 1.2039 | 1600 | 0.4065 | 0.4066 |
@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