ChemMRL
Collection
SMILES Matryoshka Representation Learning Embedding Transformer
•
5 items
•
Updated
•
1
This is a Chem-MRL (sentence-transformers) model finetuned from Derify/ChemBERTa-druglike on the pubchem_10m_genmol_similarity dataset. It maps SMILES to a 1024-dimensional dense vector space and can be used for molecular similarity, semantic search, database indexing, molecular classification, clustering, and more.
SentenceTransformer(
(0): Transformer({'max_seq_length': 128, 'do_lower_case': False, 'architecture': 'RobertaModel'})
(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})
(2): Normalize()
)
First install the Chem-MRL library:
pip install -U chem-mrl>=0.7.3
Then you can load this model and run inference.
from chem_mrl import ChemMRL
# Download from the 🤗 Hub
model = ChemMRL("Derify/ChemMRL-beta")
# Run inference
sentences = [
"Clc1nccc(C#CCCc2nc3ccccc3o2)n1",
"O=Cc1nc2ccccc2o1",
"O[C@H]1CN(C(Cc2ccccc2)c2ccccc2)C[C@@H]1Cc1cnc[nH]1",
]
embeddings = model.backbone.encode(sentences)
print(embeddings.shape)
# [3, 1024]
# Get the similarity scores for the embeddings
similarities = model.backbone.similarity(embeddings, embeddings)
print(similarities)
# tensor([[1.0000, 0.3200, 0.1209],
# [0.3200, 1.0000, 0.0950],
# [0.1209, 0.0950, 1.0000]])
# Load the model with half precision
model = ChemMRL("Derify/ChemMRL-beta", use_half_precision=True)
sentences = [
"Clc1nccc(C#CCCc2nc3ccccc3o2)n1",
"O=Cc1nc2ccccc2o1",
"O[C@H]1CN(C(Cc2ccccc2)c2ccccc2)C[C@@H]1Cc1cnc[nH]1",
]
embeddings = model.embed(sentences) # Use the embed method for half precision
print(embeddings.shape)
# [3, 1024]
pubchem_10m_genmol_similaritychem_mrl.evaluation.EmbeddingSimilarityEvaluator.EmbeddingSimilarityEvaluator with these parameters:{
"precision": "float32"
}
| Split | Metric | Value |
|---|---|---|
| validation | spearman | 0.993212 |
| test | spearman | 0.993243 |
smiles_a, smiles_b, and label| smiles_a | smiles_b | label | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
Matryoshka2dLoss with these parameters:{
"loss": "TanimotoSentLoss",
"n_layers_per_step": -1,
"last_layer_weight": 2.0,
"prior_layers_weight": 1.0,
"kl_div_weight": 0.5,
"kl_temperature": 0.3,
"matryoshka_dims": [
1024,
512,
256,
128,
64,
32,
16,
8
],
"matryoshka_weights": [
1,
1,
1,
1,
1,
1,
1,
1
],
"n_dims_per_step": -1
}
eval_strategy: stepsper_device_train_batch_size: 64per_device_eval_batch_size: 128learning_rate: 8e-06weight_decay: 6.505130550397454e-06warmup_ratio: 0.2data_seed: 42fp16: Truetf32: Trueload_best_model_at_end: Trueoptim: adamw_apex_fuseddataloader_pin_memory: Falseoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 64per_device_eval_batch_size: 128per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 1eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 8e-06weight_decay: 6.505130550397454e-06adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 3max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: {}warmup_ratio: 0.2warmup_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: 42jit_mode_eval: Falseuse_ipex: Falsebf16: Falsefp16: Truefp16_opt_level: O1half_precision_backend: autobf16_full_eval: Falsefp16_full_eval: Falsetf32: Truelocal_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}deepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_apex_fusedoptim_args: Noneadafactor: Falsegroup_by_length: Falselength_column_name: lengthddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falsedataloader_pin_memory: Falsedataloader_persistent_workers: Falseskip_memory_metrics: Trueuse_legacy_prediction_loop: Falsepush_to_hub: Falsehub_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: Falseneftune_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: Falseprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | pubchem_10m_genmol_similarity_spearman |
|---|---|---|---|
| 0.0796 | 24500 | 121.4633 | - |
| 0.08 | 24616 | - | 0.9739 |
| 0.1592 | 49000 | 118.6111 | - |
| 0.16 | 49232 | - | 0.9817 |
| 0.2389 | 73500 | 117.491 | - |
| 0.24 | 73848 | - | 0.9848 |
| 0.3185 | 98000 | 116.3786 | - |
| 0.32 | 98464 | - | 0.9865 |
| 0.3997 | 123000 | 115.9773 | - |
| 0.4 | 123080 | - | 0.9873 |
| 0.4794 | 147500 | 115.2441 | - |
| 0.48 | 147696 | - | 0.9885 |
| 0.5590 | 172000 | 114.8674 | - |
| 0.56 | 172312 | - | 0.9887 |
| 0.6386 | 196500 | 114.6483 | - |
| 0.64 | 196928 | - | 0.9892 |
| 0.7199 | 221500 | 114.0507 | - |
| 0.72 | 221544 | - | 0.9898 |
| 0.7995 | 246000 | 113.5606 | - |
| 0.8 | 246160 | - | 0.9902 |
| 0.8791 | 270500 | 113.2762 | - |
| 0.88 | 270776 | - | 0.9907 |
| 0.9587 | 295000 | 113.3295 | - |
| 0.96 | 295392 | - | 0.9908 |
| 1.0400 | 320000 | 112.9253 | - |
| 1.04 | 320008 | - | 0.9909 |
| 1.1196 | 344500 | 112.584 | - |
| 1.12 | 344624 | - | 0.9910 |
| 1.1992 | 369000 | 112.616 | - |
| 1.2 | 369240 | - | 0.9916 |
| 1.2788 | 393500 | 112.4692 | - |
| 1.28 | 393856 | - | 0.9914 |
| 1.3585 | 418000 | 112.2679 | - |
| 1.3600 | 418472 | - | 0.9917 |
| 1.4397 | 443000 | 112.1639 | - |
| 1.44 | 443088 | - | 0.9919 |
| 1.5193 | 467500 | 112.1139 | - |
| 1.52 | 467704 | - | 0.9921 |
| 1.5990 | 492000 | 111.8096 | - |
| 1.6 | 492320 | - | 0.9923 |
| 1.6786 | 516500 | 111.8252 | - |
| 1.6800 | 516936 | - | 0.9922 |
| 1.7598 | 541500 | 111.836 | - |
| 1.76 | 541552 | - | 0.9924 |
| 1.8395 | 566000 | 111.8471 | - |
| 1.8400 | 566168 | - | 0.9924 |
| 1.9191 | 590500 | 111.7778 | - |
| 1.92 | 590784 | - | 0.9925 |
| 1.9987 | 615000 | 111.4892 | - |
| 2.0 | 615400 | - | 0.9927 |
| 2.0799 | 640000 | 111.2659 | - |
| 2.08 | 640016 | - | 0.9928 |
| 2.1596 | 664500 | 111.3635 | - |
| 2.16 | 664632 | - | 0.9927 |
| 2.2392 | 689000 | 111.0114 | - |
| 2.24 | 689248 | - | 0.9928 |
| 2.3188 | 713500 | 111.0559 | - |
| 2.32 | 713864 | - | 0.9929 |
| 2.3984 | 738000 | 110.5276 | - |
| 2.4 | 738480 | - | 0.9929 |
| 2.4797 | 763000 | 110.9828 | - |
| 2.48 | 763096 | - | 0.9930 |
| 2.5593 | 787500 | 110.8404 | - |
| 2.56 | 787712 | - | 0.9930 |
| 2.6389 | 812000 | 111.1937 | - |
| 2.64 | 812328 | - | 0.9931 |
| 2.7186 | 836500 | 110.6662 | - |
| 2.7200 | 836944 | - | 0.9931 |
| 2.7998 | 861500 | 110.7714 | - |
| 2.8 | 861560 | - | 0.9932 |
| 2.8794 | 886000 | 110.7638 | - |
| 2.88 | 886176 | - | 0.9932 |
| 2.9591 | 910500 | 110.7021 | - |
| 2.96 | 910792 | - | 0.9932 |
| 2.9997 | 923000 | 110.6097 | - |
@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{li20242d,
title={2D Matryoshka Sentence Embeddings},
author={Xianming Li and Zongxi Li and Jing Li and Haoran Xie and Qing Li},
year={2024},
eprint={2402.14776},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
@misc{kusupati2024matryoshka,
title={Matryoshka Representation Learning},
author={Aditya Kusupati and Gantavya Bhatt and Aniket Rege and Matthew Wallingford and Aditya Sinha and Vivek Ramanujan and William Howard-Snyder and Kaifeng Chen and Sham Kakade and Prateek Jain and Ali Farhadi},
year={2024},
eprint={2205.13147},
archivePrefix={arXiv},
primaryClass={cs.LG}
}
@online{kexuefm-8847,
title={CoSENT: A more efficient sentence vector scheme than Sentence-BERT},
author={Su Jianlin},
year={2022},
month={Jan},
url={https://kexue.fm/archives/8847},
}
@online{cortes-2025-tanimotosentloss,
title={TanimotoSentLoss: Tanimoto Loss for SMILES Embeddings},
author={Emmanuel Cortes},
year={2025},
month={Jan},
url={https://github.com/emapco/chem-mrl},
}
Manny Cortes ([email protected])
Base model
Derify/ChemBERTa-druglike