Downloads · 30 days
5
2% of all-time downloads
kssrikar4/RetroGPT
RetroGPT is a machine learning model from kssrikar4. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mpl-2.0.
RetroGPT is a transformer-based model for single-step retrosynthetic prediction. Given a target product molecule in SMILES format, the model predicts the required reactant molecules through sequence-to-sequence genera…
Downloads · 30 days
5
2% of all-time downloads
All-time downloads
214
Public
Repo size
308 MB
Likes
0
Public
Click a slice to open those files.
.pt231 MB · 75%
From the Hugging Face model README
RetroGPT is a transformer-based model for single-step retrosynthetic prediction. Given a target product molecule in SMILES format, the model predicts the required reactant molecules through sequence-to-sequence generation.
RetroGPT is a lightweight transformer architecture specifically designed for chemical reaction prediction. The model learns to "reverse" chemical reactions by predicting precursor reactants from product molecules.
The model is intended for retrosynthetic analysis in drug discovery and organic chemistry:
import torch, sys
from transformers import AutoModelForCausalLM
from rdkit.Chem import AllChem, Draw
from IPython.display import display
def get_reaction(product, model_id="kssrikar4/RetroGPT"):
model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True).eval()
tok = getattr(sys.modules[model.__class__.__module__], "RetroGPTTokenizer").from_pretrained(model_id)
ids = torch.tensor([tok.convert_tokens_to_ids(tok.tokenize(f"<s>{product}<sep>"))])
out = model.generate(
input_ids=ids,
attention_mask=torch.ones_like(ids),
max_length=256,
num_beams=5,
num_return_sequences=1
)
reac = tok.decode(out[0].tolist(), skip_special_tokens=True).split("<sep>")[-1].replace(" ", "")
rxn = AllChem.ReactionFromSmarts(f"{reac}>>{product}", useSmiles=True)
if rxn:
AllChem.Compute2DCoordsForReaction(rxn)
display(Draw.ReactionToImage(rxn, subImgSize=(350, 350)))
get_reaction("your smiles")
The model was trained on the USPTO dataset (uspto.csv), which contains patent-derived chemical reactions extracted from US patents. The dataset includes:
Dataset Statistics:
Architecture:
Hyperparameters:
Optimization:
| Hyperparameter | Value |
|---|---|
| Transformer Layers | 6 |
| Hidden Size | 512 |
| Attention Heads | 8 |
| Max Sequence Length | 256 |
| Batch Size | 64 |
| Learning Rate | 3e-4 |
| Weight Decay | 0.01 |
| Dropout | 0.1 |
| Epochs | 80 |
| Optimizer | AdamW |
The model is evaluated using Top-k Accuracy based on exact canonical SMILES matching:

Performance on Validation Set:

The model maintains consistent performance across different patent years, demonstrating robust generalization to reactions from different time periods.

The confusion matrix reveals:
c) and aliphatic (C) carbons
Disclaimer: This model is intended for research and educational purposes. Always verify predictions with chemical expertise and experimental validation before laboratory use.