Implementations of transformer models from scratch for chemists — building toward a small MolFormer-style, encoder-only, MLM-pretrained model that fits on a free Google Colab.
This repository is a sister course to GNNs-For-Chemists. Where the GNN course teaches molecules as graphs, this one teaches molecules as sequences — SMILES strings tokenized and fed through a transformer encoder. Each notebook builds the next layer of the stack from scratch, with chemistry-first intuition and rich visualizations, so that by the end you can pre-train and fine-tune your own tiny chemical foundation model.
The course focuses on encoder-only / bidirectional transformers (BERT-style, MolFormer-style), since these are the workhorses of property prediction and representation learning in chemistry. Causal/decoder transformers (GPT-style) are mentioned for context but not the focus.
To get the most out of this tutorial series, you should have:
- Python: Basic to intermediate Python programming skills
- Chemistry: Fundamental understanding of molecular structures and SMILES notation
- Machine Learning: Basic familiarity with neural networks and gradient descent
- Mathematics: Basic linear algebra (matrix multiplication, dot products)
- Packages: Familiarity with PyTorch, NumPy, and RDKit (installation instructions provided in notebooks)
No prior experience with transformers or attention is required — we build the concepts from the ground up!
The following notebooks (01, 02, 03, ...) form the main learning path and are essential for understanding transformer fundamentals applied to chemistry:
These notebooks (02.1, 04.1, ...) provide additional details and advanced topics that complement the main series:
Contributions are welcome! Please see CONTRIBUTORS.md for guidelines on how to contribute.
This project is licensed under the MIT License — see the LICENSE file for details.
If you use this repository in your research or teaching, please cite it as:
@misc{transformers_for_chemists,
author = {Fooladi, Hosein},
title = {Transformers For Chemists: Building a Tiny MolFormer from Scratch},
year = {2026},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/HFooladi/Transformers-For-Chemists}},
note = {Educational resource for chemists, pharmacists, and researchers building encoder-only transformer models for chemical applications}
}