Skip to main content

Rxn-SMARTS-Embeddings

CI Docs License: MIT

Self-supervised transformer embeddings for reaction SMARTS, pretrained via span-masked language modelling directly on RetroRules v3.0.

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

rxn_smarts_embeddings-1.0.0.tar.gz (166.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rxn_smarts_embeddings-1.0.0-py3-none-any.whl (35.6 kB view details)

Uploaded Python 3

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

Hashes for rxn_smarts_embeddings-1.0.0.tar.gz
Algorithm Hash digest
SHA256 548e09ab35233657853063bf1c9a13ab460596c8b544f99c680155b2aaea8a6e
MD5 8abfea90164838da91b4d033f950bbcf
BLAKE2b-256 bfc202d2f7214b9fb0ad79bdd0679876b5612d5f044f5bc3bb854c2878ef2f2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for rxn_smarts_embeddings-1.0.0.tar.gz:

Publisher: release.yml on jcorreia11/Rxn-SMARTS-Embeddings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rxn_smarts_embeddings-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for rxn_smarts_embeddings-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d16bee41616e1a58ae40163f7d6f6450bde044c7250a9c0a721dcf3ef7810c89
MD5 e8ee9669ef7e7e2475b8092046dfe540
BLAKE2b-256 b6341a01b3a299177593b24f9a448d915ddaf01f6edbfbf6f66e2900f8edcc19

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page