Downloads · 30 days
680
4% of all-time downloads
jonghyunlee1993/MolGPT_pretrained-by-ZINC15
MolGPT_pretrained-by-ZINC15 is a machine learning model from jonghyunlee1993. 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 mit.
This repository hosts a GPT-2-based model for generating SMILES strings, trained on the ZINC 15 dataset. The model follows the architecture and hyperparameter setup of MolGPT (Bagal et al., 2021), and has been fine-tu…
Downloads · 30 days
680
4% of all-time downloads
All-time downloads
16.4K
Public
Parameters
6.9M
27.6 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors27.6 MB · 99%
From the Hugging Face model README
This repository hosts a GPT-2-based model for generating SMILES strings, trained on the ZINC 15 dataset. The model follows the architecture and hyperparameter setup of MolGPT (Bagal et al., 2021), and has been fine-tuned to generate valid molecular representations with high accuracy.
The model is built using the GPT-2 base architecture, with the following configuration:
GPT2Config(
vocab_size=tokenizer.vocab_size, # 10,000 tokens
n_positions=128,
n_ctx=128,
n_embd=256,
n_layer=8,
n_head=8,
resid_pdrop=0.1,
embd_pdrop=0.1,
attn_pdrop=0.1
)
The tokenizer was custom-trained using Byte Pair Encoding (BPE) with a vocabulary size of 10,000 tokens. Below is the tokenizer configuration:
def configure_tokenizer(tokenizer_path):
tokenizer = PreTrainedTokenizerFast(tokenizer_file=tokenizer_path)
tokenizer.model_max_length = 128
tokenizer.pad_token = "<pad>"
tokenizer.bos_token = "<bos>"
tokenizer.eos_token = "<eos>"
return tokenizer
TrainingArguments(
output_dir=output_dir,
evaluation_strategy="steps",
learning_rate=5e-4,
max_steps=100_000,
per_device_train_batch_size=128,
save_steps=10_000,
save_total_limit=3,
logging_dir=f"{output_dir}/logs",
logging_steps=10_000,
warmup_steps=10_000,
dataloader_num_workers=4,
gradient_accumulation_steps=1,
fp16=True
)
The validity of generated SMILES was evaluated by generating 10,000 sequences with a fixed temperature of 1. The results were compared to the original MolGPT model:
| Dataset/Metric | GPT-2 (This Model) | MolGPT |
|---|---|---|
| ZINC 15 Validity | 99.68% | N/A |
| MOSES Validity | N/A | 99.4% |
| GuacaMol Validity | N/A | 98.1% |
Install Dependencies Install the required libraries via pip:
pip install transformers
pip install tokenizers
Load the Model and Tokenizer To use the model for SMILES generation, follow these steps:
from transformers import GPT2LMHeadModel, PreTrainedTokenizerFast
tokenizer_path = "path_to_tokenizer/tokenizer.json"
tokenizer = PreTrainedTokenizerFast(tokenizer_file=tokenizer_path)
tokenizer.pad_token = "<pad>"
tokenizer.bos_token = "<bos>"
tokenizer.eos_token = "<eos>"
from transformers import GPT2LMHeadModel
model = GPT2LMHeadModel.from_pretrained("jonghyunlee/MolGPT_pretrained-by-ZINC15")
def generate_smiles(model, tokenizer, num_sequences=1000, temperature=1.0):
return model.generate(
max_length=128,
num_return_sequences=num_sequences,
pad_token_id=tokenizer.pad_token_id,
bos_token_id=tokenizer.bos_token_id,
eos_token_id=tokenizer.eos_token_id,
do_sample=True,
temperature=temperature,
return_dict_in_generate=True,
)
generated_smiles = [tokenizer.decode(output, skip_special_tokens=True) for output in outputs]
print(generated_smiles)
If you use this model in your research, please cite:
Bagal, V., Aggarwal, R., Vinod, P. K., & Priyakumar, U. D. (2021). MolGPT: molecular generation using a transformer-decoder model. Journal of Chemical Information and Modeling, 62(9), 2064-2076.