Views
No views yet
1import torch, sys
2from transformers import AutoModelForCausalLM
3from rdkit.Chem import AllChem, Draw
4from IPython.display import display
5
6def get_reaction(product, model_id="kssrikar4/RetroGPT"):
7 model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True).eval()
8 tok = getattr(sys.modules[model.__class__.__module__], "RetroGPTTokenizer").from_pretrained(model_id)
9 ids = torch.tensor([tok.convert_tokens_to_ids(tok.tokenize(f"<s>{product}<sep>"))])
10
11 out = model.generate(
12 input_ids=ids,
13 attention_mask=torch.ones_like(ids),
14 max_length=256,
15 num_beams=5,
16 num_return_sequences=1
17 )
18
19 reac = tok.decode(out[0].tolist(), skip_special_tokens=True).split("<sep>")[-1].replace(" ", "")
20 rxn = AllChem.ReactionFromSmarts(f"{reac}>>{product}", useSmiles=True)
21
22 if rxn:
23 AllChem.Compute2DCoordsForReaction(rxn)
24 display(Draw.ReactionToImage(rxn, subImgSize=(350, 350)))
25
26get_reaction("your smiles")uspto.csv), which contains patent-derived chemical reactions extracted from US patents. The dataset includes:| 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 |



c) and aliphatic (C) carbons