Rxn-SMARTS-Embeddings
Self-supervised transformer embeddings for reaction SMARTS, pretrained via span-masked language modelling directly on RetroRules v3.0.
- Paper: citation to follow upon publication
- Companion repo (experiment pipeline, SLURM scripts, paper stats): Rxn-SMARTS-Embeddings-paper
- Pretrained weights: Hugging Face Hub
- Training corpus, tokenizer, embeddings: Zenodo
- Full experiment results/logs: Zenodo
Installation
Requires Python 3.10–3.12 and uv.
git clone https://github.com/jcorreia11/Rxn-SMARTS-Embeddings.git
cd Rxn-SMARTS-Embeddings
uv sync --no-dev # embedding SMARTS only — just torch + numpy
uv sync --extra all # + preprocessing/training/evaluation/visualisation, for the full pipeline
Getting started
No setup beyond installation is required — the first call downloads and caches the medium model and vocabulary from the Hugging Face Hub automatically.
smarts-embed "[C:1]-[O:2]>>[C:1]=[O:2]" # → JSON to stdout
smarts-embed --file smarts.txt --output embeddings.npy # batch → numpy array
smarts-embed "[C:1]-[O:2]>>[C:1]=[O:2]" --size large # small | medium | large
from rxn_smarts_embeddings.predict import predict, load_embedder
emb = predict("[C:1]-[O:2]>>[C:1]=[O:2]") # (d_model,)
embs = predict(["[C:1]-[O:2]>>[C:1]=[O:2]", "c1ccccc1>>c1cccnc1"]) # (N, d_model)
embedder = load_embedder() # reuse across calls
embs = embedder.embed(smarts_list, batch_size=128)
Both auto-discover the latest local checkpoint in models/, falling back to a
Hugging Face Hub download when none is found. Pass weights=/config=/vocab=
(or --weights/--config/--vocab) to use a specific run instead.
Run smarts-embed --help for the full option list (pooling, batch size, output
format, device, etc.).
Project structure
src/rxn_smarts_embeddings/
├── predict.py # predict() API + smarts-embed CLI entry point
├── preprocessing/ # load & deduplicate RetroRules CSVs, RDKit validation
├── tokenization/ # rule-based tokenizer (Daylight SMARTS grammar) + vocab
├── datasets/ # SMARTSDataset (tokenize, pad, batch)
├── models/ # TransformerConfig, encoder, MLM head, SmartsEmbedder
└── training/ # MLMCollator, Trainer
Reproducing the data pipeline
Download the raw RetroRules v3.0 CSVs from retrorules.org
into data/raw/, then:
python src/rxn_smarts_embeddings/preprocessing/load_data.py
python src/rxn_smarts_embeddings/preprocessing/validate_smarts.py
python src/rxn_smarts_embeddings/tokenization/build_vocab.py
python src/rxn_smarts_embeddings/tokenization/sentencepiece_tokenizer.py
| Stage | Input | Output |
|---|---|---|
load_data.py |
data/raw/retrorules-v3.0-*.csv |
data/processed/clean_smarts.txt, reaction_groups.csv |
validate_smarts.py |
clean_smarts.txt, reaction_groups.csv |
data/processed/validated_smarts.csv |
build_vocab.py |
validated_smarts.csv |
data/processed/vocab.json |
sentencepiece_tokenizer.py |
validated_smarts.csv |
data/processed/sp_tokenizer.{model,vocab} |
Training uses Trainer (rxn_smarts_embeddings.training.mlm_trainer); output
checkpoints are stamped models/smarts_transformer_<YYYYMMDD_HHMMSS>.{pt,json}.
For the CLI wrapper, SLURM .sbatch scripts, and full HPC reproduction guide, see
the companion repo.
Development
uv run pytest
ruff check src tests && ruff format src tests
Docs (built with MkDocs + Material):
uv sync --group docs
uv run mkdocs serve # http://127.0.0.1:8000, live-reloads on edit
License
MIT — see LICENSE.
Citation
Citation details will be added once the paper is published.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rxn_smarts_embeddings-1.0.0.tar.gz.
File metadata
- Download URL: rxn_smarts_embeddings-1.0.0.tar.gz
- Upload date:
- Size: 166.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
548e09ab35233657853063bf1c9a13ab460596c8b544f99c680155b2aaea8a6e
|
|
| MD5 |
8abfea90164838da91b4d033f950bbcf
|
|
| BLAKE2b-256 |
bfc202d2f7214b9fb0ad79bdd0679876b5612d5f044f5bc3bb854c2878ef2f2b
|
Provenance
The following attestation bundles were made for rxn_smarts_embeddings-1.0.0.tar.gz:
Publisher:
release.yml on jcorreia11/Rxn-SMARTS-Embeddings
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rxn_smarts_embeddings-1.0.0.tar.gz -
Subject digest:
548e09ab35233657853063bf1c9a13ab460596c8b544f99c680155b2aaea8a6e - Sigstore transparency entry: 2752933989
- Sigstore integration time:
-
Permalink:
jcorreia11/Rxn-SMARTS-Embeddings@c11c1f84bd6aa5753c0f7217402ac03e83e71d0a -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/jcorreia11
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c11c1f84bd6aa5753c0f7217402ac03e83e71d0a -
Trigger Event:
push
-
Statement type:
File details
Details for the file rxn_smarts_embeddings-1.0.0-py3-none-any.whl.
File metadata
- Download URL: rxn_smarts_embeddings-1.0.0-py3-none-any.whl
- Upload date:
- Size: 35.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d16bee41616e1a58ae40163f7d6f6450bde044c7250a9c0a721dcf3ef7810c89
|
|
| MD5 |
e8ee9669ef7e7e2475b8092046dfe540
|
|
| BLAKE2b-256 |
b6341a01b3a299177593b24f9a448d915ddaf01f6edbfbf6f66e2900f8edcc19
|
Provenance
The following attestation bundles were made for rxn_smarts_embeddings-1.0.0-py3-none-any.whl:
Publisher:
release.yml on jcorreia11/Rxn-SMARTS-Embeddings
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rxn_smarts_embeddings-1.0.0-py3-none-any.whl -
Subject digest:
d16bee41616e1a58ae40163f7d6f6450bde044c7250a9c0a721dcf3ef7810c89 - Sigstore transparency entry: 2752933997
- Sigstore integration time:
-
Permalink:
jcorreia11/Rxn-SMARTS-Embeddings@c11c1f84bd6aa5753c0f7217402ac03e83e71d0a -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/jcorreia11
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c11c1f84bd6aa5753c0f7217402ac03e83e71d0a -
Trigger Event:
push
-
Statement type: