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.
Metadata
Release files for rxn-smarts-embeddings 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rxn_smarts_embeddings-1.0.0.tar.gz | 166.8 kB | With provenance | Details for rxn_smarts_embeddings-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rxn_smarts_embeddings-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for rxn_smarts_embeddings-1.0.0-py3-none-any.whl |
Total release size: 202.4 kB
Release files / rxn_smarts_embeddings-1.0.0.tar.gz
| Download URL | rxn_smarts_embeddings-1.0.0.tar.gz |
|---|---|
| Size | 166.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
548e09ab35233657853063bf1c9a13ab460596c8b544f99c680155b2aaea8a6e
|
|
BLAKE2b-256 checksum How to use checksums |
bfc202d2f7214b9fb0ad79bdd0679876b5612d5f044f5bc3bb854c2878ef2f2b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.
Transparency logRelease files / rxn_smarts_embeddings-1.0.0-py3-none-any.whl
| Download URL | rxn_smarts_embeddings-1.0.0-py3-none-any.whl |
|---|---|
| Size | 35.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d16bee41616e1a58ae40163f7d6f6450bde044c7250a9c0a721dcf3ef7810c89
|
|
BLAKE2b-256 checksum How to use checksums |
b6341a01b3a299177593b24f9a448d915ddaf01f6edbfbf6f66e2900f8edcc19
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.
Transparency logSecurity for rxn-smarts-embeddings 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for rxn_smarts_embeddings-1.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.