{'fraction_non_alphanumeric': 0.03114019979331726, 'fraction_numerical': 0.006751636238374096, 'mean_word_length': 5.068561872909699, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
DGL-LifeSci: An Open-Source Toolkit for Deep Learning on Graphs in Life Science

Graph neural networks (GNNs) constitute a class of deep learning methods for graph data. They have wide applications in chemistry and biology, such as molecular property prediction, reaction prediction, and drug–target interaction prediction. Despite the interest, GNN-based modeling is challenging as it requires graph data preprocessing and modeling in addition to programming and deep learning. Here, we present Deep Graph Library (DGL)-LifeSci, an open-source package for deep learning on graphs in life science. Deep Graph Library (DGL)-LifeSci is a python toolkit based on RDKit, PyTorch, and Deep Graph Library (DGL). DGL-LifeSci allows GNN-based modeling on custom datasets for molecular property prediction, reaction prediction, and molecule generation. With its command-line interfaces, users can perform modeling without any background in programming and deep learning. We test the command-line interfaces using standard benchmarks MoleculeNet, USPTO, and ZINC. Compared with previous implementations, DGL-LifeSci achieves a speed up by up to 6×. For modeling flexibility, DGL-LifeSci provides well-optimized modules for various stages of the modeling pipeline. In addition, DGL-LifeSci provides pretrained models for reproducing the test experiment results and applying models without training. The code is distributed under an Apache-2.0 License and is freely accessible at https://github.com/awslabs/dgl-lifesci.


INTRODUCTION
A large amount of the chemical and biological data corresponds to attributed graphs, e.g., molecular graphs, interaction networks and biological pathways. Many of the machine learning (ML) tasks that arise in this domain can be formulated as learning tasks on graphs. For example, molecular property prediction can be formulated as learning a mapping from molecular graphs to real numbers (regression) or discrete values (classification) [8]; molecule generation can be formulated as learning a distribution over molecular graphs [13]; reaction prediction can be formulated as learning a mapping from one set of graphs (reactants) to another set of graphs (products) [6]. A representation is a vector of a user-defined dimensionality. Graph neural networks (GNNs) combine graph structures and features in representation learning and they have been one of the most popular approaches for learning on graphs [31,33]. GNNs have also attracted considerable attention in life science and researchers have applied them to many different tasks [26,34,13,6,25,8,10,22,9,12].
Despite significant research, it is often challenging for experts in life science to use GNN-based approaches. To unlock the power of GNNs requires clean interfaces for custom datasets and robust and efficient pipelines. This is because developing GNN pipelines by oneself requires a combined skill set of programming, machine learning, and GNN modeling, which is time-consuming to obtain. This calls for a set of ready-to-run programs, which should make little assumption about users' background.
Prior efforts have greatly lowered the bar for GNN-based modeling in life science, but none of them fully addresses the problem. DeepChem [18] is a package for deep learning in drug discovery, materials science, quantum chemistry, and biology. While it implements several GNN models, it still requires users to program. Chainer Chemistry [1] is a package for deep learning in biology and chemistry, based on Chainer [27]. It only provides a command-line interface for GNN-based regression on molecules and requires users to write code for other tasks. PiNN [21] implements a GNN variant for predicting potential energy surfaces and physicochemical properties of molecules and materials. It also requires users to program themselves.
Here we present a python toolkit named DGL-LifeSci. It provides high-quality and robust implementations of seven models for molecular property prediction, one model for molecule generation, and one model for chemical reaction prediction. For all these models and tasks, there is an associated command-line script for predictions on custom datasets without writing a single line of code. DGL-LifeSci also provides pre-trained models for all experiments. Compared with previous implementations, it achieves a speedup by up to 6x.
In the following, we first provide a high-level overview of how graph neural networks over molecules work. Then, we discuss the implementation and package features of DGL-LifeSci. After that, we present the results of evaluating DGL-LifeSci interms of robustness and efficiency. Finally, we conclude with a discussion on future work.

GRAPH NEURAL NETWORKS OVER MOLECULES
GNNs perform graph-based representation learning by combining information from the topology of a graph and the features associated with its nodes and edges. They iteratively update the representation of a node by aggregating representations of its neighbors. As the number of iterations increases, the nodes gain information from an increasingly larger local subgraph.
When applying GNNs to molecules as in molecular property prediction, there are two phases -a message passing phase and a readout phase. Figure 1 is an illustration of them.
Message Passing Phase. The message passing phase updates node representations simultaneously across the entire graph and consists of multiple rounds of message passing. In a round of message passing, the representation of a node is updated by applying learnable functions to its original representation, the representations of its adjacent nodes and the representations of its incident edges. The operation is similar to gathering messages from adjacent nodes. By performing k rounds of message passing, we can aggregate information from all the nodes/edges that are within k hops from each node.
Readout Phase. The readout phase computes a representation for the entire graph. This representation is computed by applying a potentially learnable function to the representations of all the nodes in the graph, e.g., summation over them. Once we obtain graph representations, we can pass them to a multilayer perceptron (MLP) for final prediction.

PACKAGE FEATURES
DGL-LifeSci contains four components: (i) a set of ready-to-run scripts for training and inference; (ii) programming APIs for allowing researchers to develop their own custom pipelines and models; (iii) a set of pre-trained models that can either be fine-tuned or directly used to perform inference; (iv) a set of built-in datasets for quick experimentation. It provides models that can be used to solve three tasks. The first task is molecular property prediction or quantitative structure activity relationship (QSAR) prediction. This can be formulated as a regression or classification task for single molecules. The second task is molecule generation. The third task is chemical reaction prediction.
Usage. DGL-LifeSci provides command-line scripts for each task. They are responsible for invoking the modeling pipeline, which handles model training and model evaluation. Users need to prepare their data in a standard format. They can then use the command-line interface by specifying the path to the data file along with some additional arguments. For example, below is the command-line interface for regression and classification problems in molecular property prediction. Users need to prepare molecules in the form of SMILES strings with their properties to predict in a CSV file.

IMPLEMENTATION
Dependencies. DGL-LifeSci is developed using PyTorch [16] and Deep Graph Library (DGL) [29]. PyTorch is a general-purpose deep learning framework and DGL is a high-performant GNN library. In addition, it uses RDKit [19] for utilities related to cheminformatics.
Modeling Pipeline and Modules. A general GNN-based modeling pipeline consists of three stages: dataset preparation, model initialization and model training. The dataset preparation stage involves data loading, graph construction, representation initialization for nodes and edges (graph featurization) and dataset interface construction. The model training stage involves model update, metric computation and early stopping. As presented in figure 2, DGL-LifeSci is modularized for these various stages and stage components so as to cater to the need of different uses. While DGL-LifeSci allows users to perform GNN-based modeling without programming, advanced users can also adapt these modules for their own development.
Dataset Preparation. DGL-LifeSci provides dataset interfaces for supporting both built-in datasets and custom datasets. The interfaces are responsible for loading raw data files and invoking graph construction and featurization.
Graph construction and featurization are two important steps for GNN-specific data preparation. DGL-LifeSci provides built-in support for constructing three kinds of graphs for molecules -molecular graphs, distance-based graphs, and complete graphs. In all these graphs, each node corresponds to an atom in a molecule. In a molecular graph, the edges correspond to chemical bonds in the molecule. The construction of a distance-based graph requires a molecule conformation and there is an edge between a pair of atoms if the distance between them is within a cutoff distance. In a complete graph, every pair of atoms is connected. For graph featurization, DGL-LifeSci allows initializing various node and edge features from atom and bond descriptors. Table 1 gives an overview of them.
Users can split the dataset into training/validation/test subsets or do so for k-fold cross validation. DGL-LifeSci provides built-in support for random split, scaffold split, weight split and stratified split [30]. The random split performs a pure random split of a dataset. The scaffold split separates structurally different molecules into different subsets based on their Bemis-Murcko scaffolds [3]. The weight split sorts molecules based on their weight and then splits them in order. The stratified split sorts molecules based on their label and ensures that each subset contains nearly the full range of provided labels.
Models Included. Table 2 lists the models implemented. GCN and GAT are two popular GNNs initially developed for node classification. We extend them for graph regression/classification with a readout function and an MLP. NF and Weave are among the earliest models that extend rule-based molecular fingerprints with graph neural networks. MPNN unifies multiple GNNs for quantum chemistry. AttentiveFP extends GAT with gated recurrent units [5].
One difficulty in developing learning-based approaches for molecular property prediction is the gap between an extremely large chemical space and extremely limited labels for molecular properties. It is estimated that the number of drug-like molecules is between 10 23 and 10 60 while most datasets have less than tens of thousands of molecules in MoleculeNet [17,24,20,7,30]. Hu et al. [11] propose to approach this problem by utilizing millions of unlabeled molecules in pre-training the weights of a GIN model for general molecule representations. One can then fine-tune the model weights for predicting particular properties. We include four pre-trained models from their work in DGL-LifeSci. The models were pre-trained with a same strategy for supervised learning and a different strategy for self-supervised learning. We distinguish the models by the associated strategy for self-supervised learning, which are context prediction, deep graph infomax, edge prediction and attribute masking.   JTVAE is an autoencoder that utilizes both a junction tree and a molecular graph for the intermediate representation of a molecule. WLN is a two-stage model for chemical reaction prediction. It first identifies potential bond changes and then enumerates and ranks candidate products.

MODELING PERFORMANCE
Molecular Property Prediction. We test against six binary classification datasets in MoleculeNet and evaluate the model performance by ROC-AUC averaged over all tasks [30]. To evaluate the model performance on unseen structures, we employ the scaffold split and use respectively 80%, 10% and 10% of the dataset for training, validation, and test. We train six models (NF, GCN, GAT, Weave, MPNN, AttentiveFP) from scratch using the featurization proposed in DeepChem, which is described in table 3. GCN and GAT take initial node features only and they do not take initial edge features. We also fine-tuned the four pre-trained GIN models. For a non-GNN baseline model, we train an MLP taking Extended-Connectivity Fingerprints (ECFPs).
For all the settings, we perform a hyperparameter search for 32 trials. Within each trial, we train a randomly initialized model and perform an early stopping if the validation performance no longer improves for 30 epochs. Finally, we evaluate the model achieving the best validation performance across all epochs and trials on the test set. Table 4 presents the summary of the test performance. For a reference, we also include the fine-tuning performance reported previously [11].
Reaction Prediction. We test WLN against USPTO [2] dataset following the setting in the original work [6]. WLN is a two-stage model for reaction prediction. The first stage identifies candidate reaction centers, i.e. pairs of atoms that lose or form a bond in the reaction. The second stage enumerates candidate products from the candidate reaction centers and ranks them. We achieve comparable performance for both stages as in table 5.
Molecule Generation. We test JTVAE against a ZINC [23] subset for reconstructing input molecules [13]. We achieve an accuracy of 76.4% while the authors' released code achieve an accuracy of 74.4%.

CONCLUSIONS
Here, we present DGL-LifeSci, an open-source Python toolkit for deep learning on graphs in life science. In the current version of DGL-LifeSci, we support GNN-based modeling for molecular property prediction, reaction prediction and molecule generation.
With command-line interfaces, users can perform efficient modeling on custom datasets without programming a single line of code. Advanced users can also adapt highly modularized building blocks for their own development.
In the current implementations of DGL-LifeSci, the primary focus is on small molecules. In the future, we aim to extend the support to other graphs in life science like proteins and biological networks. This will open up a much richer set of tasks in life science.