Git Product home page Git Product logo

t5chem's Introduction

T5Chem

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

Installation

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

  1. To install from source (with latest version):
$ git clone https://github.com/HelloJocelynLu/t5chem.git
$ cd t5chem/
$ python setup.py install
$ python setup.py test # optional, only works when you have pytest installed

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 --pretrain models/pretrain/simple/ --num_epoch 30
$ t5chem predict --data_dir data/sample/product/ --model_dir model/

Note that we may not get a very good result (~70% top-1 accuracy) as we are only trained on a small dataset.

Required auguments:

  • data_dir: The path to data directory, should contain train.source, train.target for training, and test.source, test.target for testing
  • output_dir: The directory to save trained model. Will generate four files: vocab.pt for vocabulary, config.json for model configuration, pytorch_model.bin for trained model weights and training_args.bin for training arguments.
  • task_type: task type. Currently we are supporting product (for forward reaction prediction), reactants (for single-step retrosynthesis), reagents (for reagents prediction), regression (to predict numeric values) and classification (to predict categorical values).
  • model_dir: The path to a trained model. (task type, tokenization method...etc can be inferred from saved model.

Call as an API:

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.pt'))
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

Compatibility

  • Now we have found some installation issues on rdkit version later than 2020.09.2 (See discussion here)
  • torchtext version 0.10.0 published some backward incompatible changes. T5Chem now only tested on torchtext<=0.8.1

Licence

MIT Licence.

Authors

t5chem was written by Jocelyn Lu.

t5chem's People

Contributors

hellojocelynlu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.