Skip to main content

A Unified Deep Learning Model for Multi-task Reaction Predictions

Project description

Latest PyPI version

A Unified Deep Learning Model for Multi-task Reaction Predictions.

It is built on huggingface transformers – T5 model with some modifications.

cover.png

Docker

We have a docker image available here, feel free to try it out!

Installation

T5Chem can be either installed via pip or from source. We recommend to install t5chem from source.

  1. To install from source

$ git clone https://github.com/HelloJocelynLu/t5chem.git
$ cd t5chem/
$ pip install .

It should automatically handle dependencies for you.

  1. To install via pip

$ pip install t5chem

Usage

Call from command line:

$ t5chem -h # show the general help information
$ t5chem train -h # show help information for model training
$ t5chem predict -h # show help information for model prediction

We have some sample data (a small subset from datasets used in paper) available in data/ folder, to have a quick start:

$ tar -xjvf data/sample_data.tar.bz2
$ t5chem train --data_dir data/sample/product/ --output_dir model/ --task_type product --num_epoch 30        # Train a model
$ t5chem predict --data_dir data/sample/product/ --model_dir model/      # test a trained model

However, finetune based on a pre-trained model is strongly recommended. (You will get ~70% top-1 accuracy if training from a pretrained model by using –pretrain. But only 0.1% top-1 accuracy by training from scratch). You can download some pre-trained models and more datasets here.

Download and extract the pretrained model weights:

$ wget https://yzhang.hpc.nyu.edu/T5Chem/models/simple_pretrain.tar.bz2
$ tar -xjvf simple_pretrain.tar.bz2

Train using a pretrained model and test it:

$ t5chem train --data_dir data/sample/product/ --output_dir model/ --task_type product --num_epoch 30 --pretrain models/pretrain/simple/
$ t5chem predict --data_dir data/sample/product/ --model_dir model/

A more detailed example training from pretrained weights and explanations for commonly used arguments can be find here.

Call as an API (Test a trained model):

from transformers import T5ForConditionalGeneration
from t5chem import T5ForProperty, SimpleTokenizer
pretrain_path = "path/to/your/pretrained/model/"
model = T5ForConditionalGeneration.from_pretrained(pretrain_path)    # for seq2seq tasks
tokenizer = SimpleTokenizer(vocab_file=os.path.join(pretrain_path, 'vocab.txt'))
inputs = tokenizer.encode("Product:COC(=O)c1cc(COc2ccc(-c3ccccc3OC)cc2)c(C)o1.C1CCOC1>>", return_tensors='pt')
output = model.generate(input_ids=inputs, max_length=300, early_stopping=True)
tokenizer.decode(output[0], skip_special_tokens=True) # "COc1ccccc1-c1ccc(OCc2cc(C(=O)O)oc2C)cc1"

model = T5ForProperty.from_pretrained(pretrain_path)  # for non-seq2seq task
inputs = tokenizer.encode("Classification:COC(=O)c1cccc(C(=O)OC)c1>CN(C)N.Cl.O>COC(=O)c1cccc(C(=O)O)c1", return_tensors='pt')
outputs = model(inputs)
print(outputs.logits.argmax())   # Class 3

We have Google Colab examples available! Feel free to try it out:

  • Call T5Chem via CLI (command line) Colab

  • Use a pretrained model in python script Colab

  • Design your own project: predict molecular weights Colab

Licence

MIT Licence.

Authors

t5chem was written by Jocelyn Lu.

Reference

Jieyu Lu and Yingkai Zhang., Unified Deep Learning Model for Multitask Reaction Predictions with Explanation. J. Chem. Inf. Model., 62. 1376–1387 (2022) https://pubs.acs.org/doi/abs/10.1021/acs.jcim.1c01467

@article{lu2022unified,
title={Unified Deep Learning Model for Multitask Reaction Predictions with Explanation},
author={Lu, Jieyu and Zhang, Yingkai},
journal={Journal of Chemical Information and Modeling},
year={2022},
publisher={ACS Publications}
}

Other projects in Zhang’s Lab: https://www.nyu.edu/projects/yzhang/IMA/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

t5chem-1.2.0.tar.gz (2.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

t5chem-1.2.0-py3-none-any.whl (35.0 kB view details)

Uploaded Python 3

File details

Details for the file t5chem-1.2.0.tar.gz.

File metadata

  • Download URL: t5chem-1.2.0.tar.gz
  • Upload date:
  • Size: 2.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for t5chem-1.2.0.tar.gz
Algorithm Hash digest
SHA256 dad456230ab9e9af23df02bcf5efe9f5a6d389d8138a6dd79611c2d8d304fec1
MD5 64f0d69ea3cdf0a4cfe6c602dbc98eaa
BLAKE2b-256 8384dfa0815a67a1b586f31f10022fc7a45ae4e035f18b48ebab107e6f290c8d

See more details on using hashes here.

File details

Details for the file t5chem-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: t5chem-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 35.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for t5chem-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0b90dd52285b96b29822e23a9eedd2968d62815ea12a55d36a9b2f412df9d6a8
MD5 c42a01efced00785245f5f175b854e29
BLAKE2b-256 f77cdaaa4353c57ac36bf01d41beb46c2a6cc1acc8ed4dafca62fc8c3445bce8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page