Package: rxn-onmt-models
RXN package for OpenNMT-based modelsThis repository contains a Python package and associated scripts for training reaction models based on the OpenNMT library.
The repository is built on top of other RXN packages; see our other repositoriesrxn-utilities,rxn-chemutils, andrxn-onmt-utils.For the evaluation of trained models, see therxn-metricsrepository.Links:GitHub repositoryDocumentationPyPI packageThis repository was produced through a collaborative project involving IBM Research Europe and Syngenta.System RequirementsThis package is supported on all operating systems.
It has been tested on the following systems:macOS: Big Sur (11.1)Linux: Ubuntu 18.04.4A Python version of 3.6, 3.7, or 3.8 is recommended.
Python versions 3.9 and above are not expected to work due to compatibility with the selected version of OpenNMT.Installation guideThe package can be installed from Pypi:pipinstallrxn-onmt-models[rdkit]You can leave out[rdkit]if RDKit is already available in your environment.For local development, the package can be installed with:pipinstall-e".[dev,rdkit]"Training models.Example of usage for training RXN modelsThe easy waySimply execute the interactive programrxn-plan-trainingin your terminal and follow the instructions.The complicated wayOptional: set shell variables, to be used in the commands later on.MODEL_TASK="forward"# Existing TXT filesDATA_1="/path/to/data_1.txt"DATA_2="/path/to/data_2.txt"DATA_3="/path/to/data_3.txt"# Where to put the processed dataDATA_DIR_1="/path/to/processed_data_1"DATA_DIR_2="/path/to/processed_data_2"DATA_DIR_3="/path/to/processed_data_3"# Where to save the ONMT-preprocessed dataPREPROCESSED="/path/to/onmt-preprocessed"# Where to save the modelsMODELS="/path/to/models"MODELS_FINETUNED="/path/to/models_finetuned"Prepare the data (standardization, filtering, etc.)rxn-prepare-data--input_data$DATA_1--output_dir$DATA_DIR_1Preprocess the data with OpenNMTrxn-onmt-preprocess--input_dir$DATA_DIR_1--output_dir$PREPROCESSED--model_task$MODEL_TASKTrain the model (here with small parameter values, to make it fast on CPU for testing).rxn-onmt-train--model_output_dir$MODELS--preprocess_dir$PREPROCESSED_SINGLE--train_num_steps10--batch_size4--heads2--layers2--transformer_ff512--no_gpuMulti-task trainingFor multi-task training, the process is similar.
We need to prepare also the second data set; in addition, the OpenNMT preprocessing and training take additional arguments.
To sum up:rxn-prepare-data--input_data$DATA_1--output_dir$DATA_DIR_1rxn-prepare-data--input_data$DATA_2--output_dir$DATA_DIR_2rxn-prepare-data--input_data$DATA_2--output_dir$DATA_DIR_3rxn-onmt-preprocess--input_dir$DATA_DIR_1--output_dir$PREPROCESSED--model_task$MODEL_TASK\--additional_data$DATA_DIR_2--additional_data$DATA_DIR_3rxn-onmt-train--model_output_dir$MODELS--preprocess_dir$PREPROCESSED--train_num_steps30--batch_size4--heads2--layers2--transformer_ff256--no_gpu\--data_weights1--data_weights3--data_weights4Continuing the trainingContinuing training is possible (for both single-task and multi-task); it needs fewer parameters:rxn-onmt-continue-training--model_output_dir$MODELS--preprocess_dir$PREPROCESSED--train_num_steps30--batch_size4--no_gpu\--data_weights1--data_weights3--data_weights4Fine-tuningFine-tuning is in principle similar to continuing the training.
The main differences are the potential occurrence of new tokens, as well as the optimizer being reset.
There is a dedicated command for fine-tuning. For example:rxn-onmt-finetune--model_output_dir$MODELS_FINETUNED--preprocess_dir$PREPROCESSED--train_num_steps20--batch_size4--no_gpu\--train_from$MODELS/model_step_30.ptThe syntax is very similar torxn-onmt-trainandrxn-onmt-continue-training.
This is compatible both with single-task and multi-task.