A Variational Autoencoder (VAE) that learns a continuous latent representation of molecular structures and generates novel candidates. Trained on the QM9 benchmark dataset using SMILES notation, with validity and novelty assessment of generated molecules.
| Category | Details |
|---|---|
| Generative Modelling | Variational Autoencoder with KL-divergence regularisation |
| Molecular Representation | SMILES encoding/decoding, character-level tokenisation |
| Deep Learning | PyTorch GRU-based encoder/decoder, teacher forcing, KL annealing, mixed-precision training, latent-space sampling and interpolation |
| Cheminformatics | RDKit molecule parsing, canonicalisation, property calculation, structure visualisation |
| Evaluation | Train/validation/test split, held-out reconstruction accuracy, raw (unrepaired) validity, canonical novelty against the training set, property distributions |
| Reproducibility | Fixed random seeds, version-pinned dependencies, deterministic data splits |
| Dataset | QM9 — standard benchmark for small organic molecules |
- Open the notebook in Google Colab using the badge above (GPU recommended for faster training).
- Run cells in order (Runtime → Run all) — the QM9 dataset is downloaded automatically and split into train/validation/test sets.
- The notebook walks through environment setup, data preprocessing, model training (with a validation loop), and molecule generation.
- Generated molecules are visualised with RDKit and assessed for reconstruction accuracy, raw validity, and canonical novelty; a latent-space interpolation shows the smoothness of the learned representation.
The committed notebook has its outputs cleared — run all cells in Colab to regenerate them.
Key parameters you can adjust:
hidden_dim— GRU hidden state dimensionlatent_dim— latent space dimensionalitybatch_size— training batch sizenum_epochs— number of training epochsSEED— global random seed for reproducible splits, training, and sampling
Generating valid SMILES strings is a hard problem — the syntax is strict, and most random character sequences are chemically meaningless. The VAE learns to navigate this by encoding known molecules into a smooth latent space where nearby points tend to decode into similar, valid structures. This is the core insight behind latent-space drug discovery: instead of searching a discrete combinatorial space, you optimise over a continuous manifold. The gap between "valid molecule" and "viable drug candidate" remains vast, but the approach demonstrates why generative models have become central to computational chemistry.
This project is open-source and available under the MIT License.
- CNN X-ray Image Classifier — deep learning for medical imaging
- Generalized Analysis of Text Data — NLP reference notebook with 13 techniques
- kenreid.co.uk/data_science — all projects, publications, and CV
Ken Reid — Data Scientist, photographer, and avid reader.
- kenreid.co.uk — Portfolio & blog
- @kenreid.co.uk — Bluesky
- @DrKenReid — GitHub