ChemQ3MTP-base is a lightweight generative model for chemistry, trained on 2.33 million valid bioactive and natural product molecules dataset curated from ChemBL34, COCONUTDB, and SuperNatural3. It is built on a compact Qwen2-like transformer backbone and employs a multi-horizon predictive (MTP) loss objective to model molecular structures in SELFIES representation.
Train Loss: 1.1720 → Perplexity: ~3.23
Validation Loss: 1.0448 → Perplexity: ~2.84
Current version (0.2) (Lic for Code: MIT; Weights: Apache 2.0)
A custom Qwen2-style language model, adapted for molecular generation:
✅ Qwen2-like Mini Backbone – Efficient causal LM architecture
✅ Multi-Token Prediction (MTP Head) – Parallel prediction of 1–3 future tokens, implemented as a plug-and-play head compatible with AutoModel
✅ Horizon Loss – Weighted multi-horizon objectives for long-term coherence
✅ Adaptive Generation-Length Cap – Dynamically limits max_new_tokens to 25% of prompt length when no budget is given, reducing inference cost and preventing runaway molecule chains during RL (no retraining needed; works with generate and generate_with_logprobs)
RL-Ready Features:
✅ Durrant's Lab Filter – Integrated substructure filtering based on gypsum_dl (Ropp et al. 2019) methodology to remove improbable molecular variants in validity check
✅ Pareto Reward Controller – Ready for RL fine-tuning with dynamic multi-objective optimization balancing validity, synthesizability, and molecular complexity with adaptive weight adjustment
💡 Target domain: molecular generation (SELFIES).
🔬 Goal: general base model knowledgable and capable in generating SELFIES representation of new molecules
🚀 Core innovation: fast, modular MTP + RL fine-tuning pipelines using standard HuggingFace components.
Disclaimer and Responsible Use Policy
Model Purpose: This generative model is designed exclusively for research and development applications in drug discovery and materials science. The model is intended to assist researchers in hypothesis generation, molecular design, and materials exploration.
Limitations and Accuracy:
The model's outputs are predictions and should be validated through experimental verification.
The author makes no warranties regarding the accuracy, completeness, reliability, or suitability of generated results.
Users assume all risks associated with model outputs and their applications.
Prohibited Uses:
The model must not be used for:
Legal, medical, or regulatory decision-making without proper validation
Generating dangerous, toxic, or harmful compounds
Any illegal activities or purposes
Military, defense, or weapons development applications
Circumventing safety regulations or ethical guidelines
Compliance: Users are responsible for ensuring compliance with applicable laws, regulations, and institutional policies in their jurisdiction.
Liability: The author disclaims all liability for damages arising from the use or misuse of this model.
1# ==============================2# Generate SELFIES from ChemQ3MTP checkpoint3# LOADING THE MODEL & TOKENIZER4# ================================56import sys
7import os
8import torch
910# --- Replicate local module loading exactly as in training ---11notebook_dir = os.getcwd()12chemq3mtp_path = os.path.join(notebook_dir,"ChemQ3MTP")1314if chemq3mtp_path notin sys.path:15 sys.path.insert(0, chemq3mtp_path)1617# Optional: clean up duplicate paths 18existing_paths =[p for p in sys.path if p.endswith("ChemQ3MTP")]19for path in existing_paths[:-1]:# keep only the most recently added20 sys.path.remove(path)2122# Now import from local ChemQ3MTP folder23from FastChemTokenizerHF import FastChemTokenizerSelfies
24from ChemQ3MTP import ChemQ3MTPForCausalLM
2526# --- Load from checkpoint (same as saved in training) ---27checkpoint_dir ="./"# or your actual checkpoint path2829print(f"Loading tokenizer...")30tokenizer = FastChemTokenizerSelfies.from_pretrained('./selftok_core/')3132print(f"Loading ChemQ3MTP model from {checkpoint_dir}...")33model = ChemQ3MTPForCausalLM.from_pretrained(checkpoint_dir)3435# --- Prepare for generation ---36device = torch.device("cuda"if torch.cuda.is_available()else"cpu")37model.to(device)38model.eval()3940# Disable MTP mode for standard autoregressive generation41ifhasattr(model,'set_mtp_training'):42 model.set_mtp_training(False)4344try:45# Tokenize start token46 input_ids = tokenizer("<s>", return_tensors="pt").input_ids.to(device)4748with torch.no_grad():49 gen = model.generate(50 input_ids=input_ids,51 max_length=256,52 top_k=50,53 temperature=1.0,54 do_sample=True,55 pad_token_id=tokenizer.pad_token_id,56 eos_token_id=tokenizer.eos_token_id,57 early_stopping=True58)5960 result = tokenizer.decode(gen[0], skip_special_tokens=True)61print("Generated SELFIES:")62print(result)6364except Exception as e:65print(f"Generation failed: {e}")66import traceback
67 traceback.print_exc()6869# Loading tokenizer...70# ✅ Special tokens bound: 0 1 2 3 471# Loading ChemQ3MTP model from ./...72# Generated SELFIES:73# .[N] [C] [C] [N] [C] [C] [=C] [C] [=C] [Branch1] ...
Training and scaling require significant computational resources.
If you’d like to support this research (e.g., helping us rent compute servers for rapid RL prototyping and MTP validation), you can contribute here:
Every bit of support helps us push ChemQ3MTP further! 🚀🧬
Citation
If you find this project useful in your research and wish to cite it, please use the following BibTex entry:
bibtex
1@software{chemq3mtp_base,
2 author = {GP Bayu},
3 title = {{ChemQ3MTP}: Pretraining a Lightweight Transformer for Molecular Generation with Multi-Token Prediction and Horizon Loss},
4 url = {https://huggingface.co/gbyuvd/ChemQ3MTP-base},
5 version = {0.2},
6 year = {2025},
7}
References
BibTeX
Qwen2
bibtex
1@misc{yang2024qwen2technicalreport,
2 title={Qwen2 Technical Report},
3 author={An Yang and Baosong Yang and Binyuan Hui and Bo Zheng and Bowen Yu and Chang Zhou and Chengpeng Li and Chengyuan Li and Dayiheng Liu and Fei Huang and Guanting Dong and Haoran Wei and Huan Lin and Jialong Tang and Jialin Wang and Jian Yang and Jianhong Tu and Jianwei Zhang and Jianxin Ma and Jianxin Yang and Jin Xu and Jingren Zhou and Jinze Bai and Jinzheng He and Junyang Lin and Kai Dang and Keming Lu and Keqin Chen and Kexin Yang and Mei Li and Mingfeng Xue and Na Ni and Pei Zhang and Peng Wang and Ru Peng and Rui Men and Ruize Gao and Runji Lin and Shijie Wang and Shuai Bai and Sinan Tan and Tianhang Zhu and Tianhao Li and Tianyu Liu and Wenbin Ge and Xiaodong Deng and Xiaohuan Zhou and Xingzhang Ren and Xinyu Zhang and Xipin Wei and Xuancheng Ren and Xuejing Liu and Yang Fan and Yang Yao and Yichang Zhang and Yu Wan and Yunfei Chu and Yuqiong Liu and Zeyu Cui and Zhenru Zhang and Zhifang Guo and Zhihao Fan},
4 year={2024},
5 eprint={2407.10671},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8 url={https://arxiv.org/abs/2407.10671},
9}
COCONUTDB
bibtex
1@article{sorokina2021coconut,
2 title={COCONUT online: Collection of Open Natural Products database},
3 author={Sorokina, Maria and Merseburger, Peter and Rajan, Kohulan and Yirik, Mehmet Aziz and Steinbeck, Christoph},
4 journal={Journal of Cheminformatics},
5 volume={13},
6 number={1},
7 pages={2},
8 year={2021},
9 doi={10.1186/s13321-020-00478-9}
10}
ChemBL34
bibtex
1@article{zdrazil2023chembl,
2 title={The ChEMBL Database in 2023: a drug discovery platform spanning multiple bioactivity data types and time periods},
3 author={Zdrazil, Barbara and Felix, Eloy and Hunter, Fiona and Manners, Emma J and Blackshaw, James and Corbett, Sybilla and de Veij, Marleen and Ioannidis, Harris and Lopez, David Mendez and Mosquera, Juan F and Magarinos, Maria Paula and Bosc, Nicolas and Arcila, Ricardo and Kizil{\"o}ren, Tevfik and Gaulton, Anna and Bento, A Patr{\'i}cia and Adasme, Melissa F and Monecke, Peter and Landrum, Gregory A and Leach, Andrew R},
4 journal={Nucleic Acids Research},
5 year={2023},
6 volume={gkad1004},
7 doi={10.1093/nar/gkad1004}
8}
910@misc{chembl34,
11 title={ChemBL34},
12 year={2023},
13 doi={10.6019/CHEMBL.database.34}
14}
SuperNatural3
bibtex
1@article{Gallo2023,
2 author = {Gallo, K and Kemmler, E and Goede, A and Becker, F and Dunkel, M and Preissner, R and Banerjee, P},
3 title = {{SuperNatural 3.0-a database of natural products and natural product-based derivatives}},
4 journal = {Nucleic Acids Research},
5 year = {2023},
6 month = jan,
7 day = {6},
8 volume = {51},
9 number = {D1},
10 pages = {D654-D659},
11 doi = {10.1093/nar/gkac1008}
12}
Ranger21 Optimizer
bibtex
1@article{wright2021ranger21,
2 title={Ranger21: a synergistic deep learning optimizer},
3 author={Wright, Less and Demeure, Nestor},
4 year={2021},
5 journal={arXiv preprint arXiv:2106.13731},
6}
Durrant's Lab Filtering
@article{ropp2019gypsum,
title={Gypsum-DL: An Open-source Program for Preparing Small-molecule Libraries for Structure-based Virtual Screening},
author={Ropp, Patrick J. and Spiegel, Jacob O. and Walker, Jennifer L. and Green, Harrison and Morales, Guillermo A. and Milliken, Katherine A. and Ringe, John J. and Durrant, Jacob D.},
journal={Journal of Cheminformatics},
volume={11},
number={1},
year={2019},
doi={10.1186/s13321-019-0358-3}
}