Package: t5chem
A Unified Deep Learning Model for Multi-task Reaction Predictions.It is built onhuggingface transformers– T5 model with some modifications.InstallationT5Chem can be either installed via pip or from source. We recommend to install t5chem from source.To install from source (with latest version):$gitclonehttps://github.com/HelloJocelynLu/t5chem.git$cdt5chem/$pythonsetup.pyinstall$pythonsetup.pytest# optional, only works when you have pytest installedIt should automatically handle dependencies for you.To install via pip$pipinstallt5chemUsageCall from command line:$t5chem-h# show the general help information$t5chemtrain-h# show help information for model training$t5chempredict-h# show help information for model predictionWe have some sample data (a small subset from datasets used in paper) available indata/folder, to have a quick start:$tar-xjvfdata/sample_data.tar.bz2$t5chemtrain--data_dirdata/sample/product/--output_dirmodel/--task_typeproduct--pretrainmodels/pretrain/simple/--num_epoch30$t5chempredict--data_dirdata/sample/product/--model_dirmodel/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 containtrain.source,train.targetfor training, andtest.source,test.targetfor testingoutput_dir: The directory to save trained model. Will generate four files:vocab.ptfor vocabulary,config.jsonfor model configuration,pytorch_model.binfor trained model weights andtraining_args.binfor training arguments.task_type: task type. Currently we are supportingproduct(for forward reaction prediction),reactants(for single-step retrosynthesis),reagents(for reagents prediction),regression(to predict numeric values) andclassification(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:fromtransformersimportT5ForConditionalGenerationfromt5chemimportT5ForProperty,SimpleTokenizerpretrain_path="path/to/your/pretrained/model/"model=T5ForConditionalGeneration.from_pretrained(pretrain_path)# for seq2seq taskstokenizer=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 taskinputs=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 3We have Google Colab examples available! Feel free to try it out:Call T5Chem via CLI (command line)ColabUse a pretrained model in python scriptColabDesign your own project: predict molecular weightsColabCompatibilityNow we have found some installation issues on rdkit version later than 2020.09.2 (See discussionhere)torchtext version 0.10.0 published some backward incompatible changes. T5Chem now only tested on torchtext<=0.8.1LicenceMIT Licence.Authorst5chemwas written byJocelyn Lu.