MolGAN: An implicit generative model for small molecular graphs
Nicola De Cao, Thomas Kipf
Introduction
Finding new chemical compounds with desired properties is a challenging task with important applications such as de novo drug design (Schneider & Fechner, 2005). The space of synthesizable molecules is vast and search in this space proves to be very difficult, mostly owing to its discrete nature.
Recent progress in the development of deep generative models has spawned a range of promising proposals to address this issue. Most works in this area (Gómez-Bombarelli et al., 2016; Kusner et al., 2017; Guimaraes et al., 2017; Dai et al., 2018) make use of a so-called SMILES representation (Weininger, 1988) of molecules: a string-based representation derived from molecular graphs. Recurrent neural networks (RNNs) are ideal candidates for these representations and consequently, most recent works follow the recipe of applying RNN-based generative models on this type of encoding. String-based representations of molecules, however, have certain disadvantages: RNNs have to spend capacity on learning both the syntactic rules and the order ambiguity of the representation. Besides, this is approach not applicable to generic (non-molecular) graphs.
SMILES strings are generated from a graph-based representation of molecules, thereby working in the original graph space has the benefit of removing additional overhead. With recent progress in the area of deep learning on graphs (Bronstein et al., 2017; Hamilton et al., 2017), training deep generative models directly on graph representations becomes a feasible alternative that has been explored in a range of recent works (Kipf & Welling, 2016; Johnson, 2017; Grover et al., 2019; Li et al., 2018b; Simonovsky & Komodakis, 2018; You et al., 2018).
Likelihood-based methods for molecular graph generation (Li et al., 2018b; Simonovsky & Komodakis, 2018) however, either require providing a fixed (or randomly chosen) ordered representation of the graph or an expensive graph matching procedure to evaluate the likelihood of a generated molecule, as the evaluation of all possible node orderings is prohibitive already for graphs of small size.
In this work, we sidestep this issue by utilizing implicit, likelihood-free methods, in particular, a generative adversarial network (GAN) (Goodfellow et al., 2014) that we adapt to work directly on graph representations. We further utilize a reinforcement learning (RL) objective similar to ORGAN (Guimaraes et al., 2017) to encourage the generation of molecules with particular properties.
Our molecular GAN (MolGAN) model (outlined in Figure 1) is the first to address the generation of graph-structured data in the context of molecular synthesis using GANs (Goodfellow et al., 2014). The generative model of MolGAN predicts discrete graph structure at once (i.e., non-sequentially) for computational efficiency, although sequential variants are possible in general. MolGAN further utilizes a permutation-invariant discriminator and reward network (for RL-based optimization towards desired chemical properties) based on graph convolution layers (Bruna et al., 2014; Duvenaud et al., 2015; Kipf & Welling, 2017; Schlichtkrull et al., 2017) that both operate directly on graph-structured representations.
Background
Most previous deep generative models for molecular data (Gómez-Bombarelli et al., 2016; Kusner et al., 2017; Guimaraes et al., 2017; Dai et al., 2018) resort to generating SMILES representations of molecules. The SMILES syntax, however, is not robust to small changes or mistakes, which can result in the generation of invalid or drastically different structures. Grammar VAEs (Kusner et al., 2017) alleviate this problem by constraining the generative process to follow a particular grammar.
Operating directly in the space of graphs has recently been shown to be a viable alternative for generative modeling of molecular data (Li et al., 2018b; Simonovsky & Komodakis, 2018) with the added benefit that all generated outputs are valid graphs (but not necessarily valid molecules).
2 Implicit vs. likelihood-based methods
Likelihood-based methods such as the variational auto-encoder (VAE) (Kingma & Welling, 2014; Rezende et al., 2014) typically allow for easier and more stable optimization than implicit generative models such as a GAN (Goodfellow et al., 2014). When generating graph-structured data, however, we wish to be invariant to reordering of nodes in the (ordered) matrix representation of the graph, which requires us to either perform a prohibitively expensive graph matching procedure (Simonovsky & Komodakis, 2018) or to evaluate the likelihood for all possible node permutations explicitly.
By resorting to implicit generative models, in particular to the GAN framework, we circumvent the need for an explicit likelihood. While the discriminator of the GAN can be made invariant to node ordering by utilizing graph convolutions (Bruna et al., 2014; Duvenaud et al., 2015; Kipf & Welling, 2017) and a node aggregation operator (Li et al., 2016), the generator still has to decide on a specific node ordering when generating a graph. Since we do not provide a likelihood, however, the generator is free to choose any suitable ordering for the task at hand. We provide a brief introduction to GANs in the following.
GANs (Goodfellow et al., 2014) are implicit generative models in the sense that they allow for inference of model parameters without requiring one to specify a likelihood.
A GAN consist of two main components: a generative model , that learns a map from a prior to the data distribution to sample new data-points, and a discriminative model , that learns to classify whether samples came from the data distribution rather than from . Those two models are implemented as neural networks and trained simultaneously with stochastic gradient descent (SGD). and have different objectives, and they can be seen as two players in a minimax game
where tries to generate samples to fool the discriminator and tries to differentiate samples correctly. To prevent undesired behaviour such as mode collapse (Salimans et al., 2016) and to stabilize learning, we use minibatch discrimination (Salimans et al., 2016) and improved WGAN (Gulrajani et al., 2017), an alternative and more stable GAN model that minimizes a better suited divergence.
Improved WGAN
WGANs (Arjovsky et al., 2017) minimize an approximation of the Earth Mover (EM) distance (also know as Wasserstein-1 distance) defined between two probability distributions. Formally, the Wasserstein distance between and , using the Kantorovich-Rubinstein duality is
where in the case of WGAN, is the empirical distribution and is the generator distribution. Note that the supremum is over all the K-Lipschitz functions for some .
Gulrajani et al. (2017) introduce a gradient penalty as an alternative soft constraint on the 1-Lipschitz continuity as an improvement upon the gradient clipping scheme from the original WGAN. The loss with respect to the generator remains the same as in WGAN, but the loss function with respect to the discriminator is modified to be
where is a hyperparameter (we use as in the original paper), is a sampled linear combination between and with , thus with .
3 Deterministic policy gradients
A GAN generator learns a transformation from a prior distribution to the data distribution. Thus, generated samples resemble data samples. However, in de novo drug design methods, we are not only interested in generating chemically valid compounds, but we want them to have some useful property (e.g., to be easily synthesizable). Therefore, we also optimize the generation process towards some non-differentiable metrics using reinforcement learning.
In reinforcement learning, a stochastic policy is represented by which is a parametric probability distribution in that selects a categorical action conditioned on an state . Conversely, a deterministic policy is represented by which deterministically outputs an action.
In initial experiments, we explored using REINFORCE (Williams, 1992) in combination with a stochastic policy that models graph generation as a set of categorical choices (actions). However, we found that it converged poorly due to the high dimensional action space when generating graphs at once. We instead base our method on a deterministic policy gradient algorithm which is known to perform well in high-dimensional action spaces (Silver et al., 2014). In particular, we employ a simplified version of deep deterministic policy gradient (DDPG) introduced by Lillicrap et al. (2016), an off-policy actor-critic algorithm that uses deterministic policy gradients to maximize an approximation of the expected future reward.
In our case, the policy is the GAN generator which takes a sample for the prior as input, instead of an environmental state , and it outputs a molecular graph as an action (). Moreover, we do not model episodes, so there is no need to assess the quality of a state-action combination since it does only depend on the graph . Therefore, we introduce a learnable and differentiable approximation of the reward function that predicts the immediate reward, and we train it via a mean squared error objective based on the real reward provided by an external system (e.g., the synthesizability score of a molecule). Then, we train the generator maximizing the predicted reward via which, being differentiable, provides a gradient to the policy towards the desired metric.
Model
The MolGAN architecture (Figure 2) consists of three main components: a generator , a discriminator and a reward network .
The generator takes a sample from a prior distribution and generates an annotated graph representing a molecule. Nodes and edges of are associated with annotations denoting atom type and bond type respectively. The discriminator takes both samples from the dataset and the generator and learns to distinguish them. Both and are trained using improved WGAN such that the generator learns to match the empirical distribution and eventually outputs valid molecules.
The reward network is used to approximate the reward function of a sample and optimize molecule generation towards non-differentiable metrics using reinforcement learning. Dataset and generated samples are inputs of , but, differently from the discriminator, it assigns scores to them (e.g., how likely the generated molecule is to be soluble in water). The reward network learns to assign a reward to each molecule to match a score provided by an external softwareWe used the RDKit Open-Source Cheminformatics Software: http://www.rdkit.org.. Notice that, when MolGAN outputs a non-valid molecule, it is not possible to assign a reward since the graph is not even a compound. Thus, for invalid molecular graphs, we assign zero rewards.
The discriminator is trained using the WGAN objective while the generator uses a linear combination of the WGAN loss and the RL loss:
where is a hyperparameter that regulates the trade-off between the two components.
2 Discriminator and reward network
After several layers of propagation via graph convolutions, following Li et al. (2016) we aggregate node embeddings into a graph level representation vector as
where is the logistic sigmoid function, and are MLPs with a linear output layer and denotes element-wise multiplication. Then, is a vector representation of the graph and it is further processed by an MLP to produce a graph level scalar output for the discriminator and for the reward network.
Related work
Objective-Reinforced Generative Adversarial Networks (ORGAN) by Guimaraes et al. (2017) is the closest related work to ours. Their model relies on SeqGAN (Yu et al., 2017) to adversarially learn to output sequences while optimizing towards chemical metrics with REINFORCE (Williams, 1992). The main differences from our approach is that they model sequences of SMILES as molecular representations instead of graphs, and their RL component uses REINFORCE while we use DDPG. Segler et al. (2018) also employs RL for drug discovery by searching retrosynthetic routes using Monte Carlo Tree Search (MCTS) in combination with an expansion policy network.
Several other works have explored training generative models on SMILES representations of molecules: CharacterVAE (Gómez-Bombarelli et al., 2016) is the first such model that is based on a VAE with recurrent encoder and decoder networks. GrammarVAE (Kusner et al., 2017) and SDVAE (Dai et al., 2018) constrain the decoding process to follow particular syntactic and semantic rules.
A related line of research considers training deep generative models to output graph-structured data directly. Several works explored auto-encoder architectures utilizing graph convolutions for link prediction within graphs (Kipf & Welling, 2016; Grover et al., 2019; Davidson et al., 2018). Johnson (2017); Li et al. (2018b); You et al. (2018); Li et al. (2018a) on the other hand developed likelihood-based methods to directly output graphs of arbitrary size in a sequential manner. Several related works have explored extending VAEs to generate graphs directly, examples include the GraphVAE (Simonovsky & Komodakis, 2018), Junction Tree VAE (Jin et al., 2018) and the NeVAE (Samanta et al., 2018) model.
For link prediction within graphs, a range of adversarial methods have been introduced in the literature (Minervini et al., 2017; Wang et al., 2018; Bojchevski et al., 2018). This class of models, however, is not suitable to generate molecular graphs from scratch, which makes direct comparison infeasible.
Experiments
We compare MolGAN against recent neural network-based drug generation models in a range of experiments on established benchmarks using the QM9 (Ramakrishnan et al., 2014) chemical database. We first focus on studying the effect of the parameter to find the best trade-off between the GAN and RL objective (see Section 5.1). We then compare MolGAN with ORGAN (Guimaraes et al., 2017) since it is the most related work to ours: ORGAN is a sequential generative model operating on SMILES representations, optimizing towards several chemical properties with an RL objective (see Section 5.2). We also compare our model against variational autoencoding methods (Section 5.3) such as CharacterVAE (Gómez-Bombarelli et al., 2016), GrammarVAE (Kusner et al., 2017), as well as a recent graph-based generative model: GraphVAE (Simonovsky & Komodakis, 2018).
In all experiments, we used QM9 (Ramakrishnan et al., 2014) a subset of the massive 166.4 billion molecules GDB-17 chemical database (Ruddigkeit et al., 2012). QM9 contains 133,885 organic compounds up to 9 heavy atoms: carbon (C), oxygen (O), nitrogen (N) and fluorine (F).
Generator architecture
Discriminator and reward network architecture
Both networks use a RelationalGCN encoder (see Eq. 3.2) with two layers and and with as hidden layer activation function. In the reward network, we further use a sigmoid activation function on the output.
Evaluation measures
We measure the following statistics as defined in Samanta et al. (2018): validity, novelty, and uniqueness. Validity is defined as the ratio between the number of valid and all generated molecules. Novelty measures the ratio between the set of valid samples that are not in the dataset and the total number of valid samples. Finally, uniqueness is defined as the ratio between the number of unique samples and valid samples and it measures the degree of variety during sampling.
Training
In all experiments, we use a batch size of 32 and train using the Adam (Kingma & Ba, 2015) optimizer with a learning rate of . For each setting, we employ a grid search over dropout rates (Srivastava et al., 2014) as well as over discretization variations (as described in Section 3.1). We always report the results of the best model depending on what we are optimizing for (e.g., when optimizing solubility we report the model with the highest solubility score – when no metric is optimized we report the model with the highest sum of individual scores). Although the use of WGAN should prevent, to some extent, undesired behaviors like mode collapse (Salimans et al., 2016), we notice that our models suffer from that problem. We leave addressing this issue for future work. As a simple countermeasure, we employ early stopping, evaluating every 10 epochs, to avoid completely collapsed modes. In particular, we use the unique score to measure the degree of collapse of our models since it intrinsically indicates how much variety there is in the generation process. We set an arbitrary threshold of 2% under which we consider a model to be collapsed and stop training.
During early stages of our work, we noticed that the reward network needs several epochs of pretraining before being used to propagate the gradient to the generator, otherwise the generator easily diverges. We think this happens because at the beginning of the training, does not predict the reward accurately and then it does not optimize the generator well. Therefore, in each experiment, we train the generator for the first half of the epochs without the RL component, but using the WGAN objective only. We train the reward network during these epochs, but no RL loss is used to train the generator. For the second half of the epochs we use the combined loss in Equation 4.
1 Effect of λ𝜆\lambda
As in Guimaraes et al. (2017), the hyperparameter controls the trade-off between maximizing the desired objective and regulating the generator to match the data distribution. We study the effects of on the solubility metric (see Section 5.2 for more details). We train for 300 epochs (150 of which for pretraining) on the 5k subset of QM9 used in Guimaraes et al. (2017). We use the best parameter – determined via the model with the maximum sum of valid, unique, novel, and solubility scores – on all other experiments (Section 5.2 and 5.3) without doing any further search.
We report results in Table 1. We observe a clear trend towards higher validity scores for lower values of . This is likely due to the implicit optimization of valid molecules since invalid ones receive zero reward during training. Therefore, if the RL loss component is strong, the generator is optimized to generate mostly valid molecular graphs. Conversely, it appears that does not mainly affect the unique and novel scores. Notice that these scores are not optimized, neither directly nor indirectly, and therefore they are a result of model architecture, hyperparameters, and training procedure. Indeed, the unique score is always close to 2% (which is our threshold) indicating that models appear to collapse (even in the RL only case) if we do not apply early stopping.
We also run without starting from a pretrained model. We observe that it succeeds in optimizing toward the desired metrics, but it collapses outputting very few samples (i.e., low unique score). This behavior may indicate that pretraining is fundamental for matching the data distribution before using RL since the GAN acts regularizing towards diversity.
Since controls the trade-off between the WGAN and RL losses, it is not surprising that (i.e., only RL in the second half of training) results in the highest valid and solubility scores compared to other values. The value with the highest sum of scores is . We use this value for subsequent experiments.
2 Objectives optimization
Similarly to the previous experiment, we train our model for 300 epochs on the 5k QM9 subset while optimizing the same objectives as Guimaraes et al. (2017) to compare against their work. Moreover, we also report results on the full dataset trained for 30 epochs (note that the full dataset is 20 times larger than the subset). All scores are normalized to lie within $$. We assign a score of zero to invalid compounds (i.e., implicitly we are also optimizing a validity score). We choose to optimize the following objectives which represent qualities typically desired for drug discovery:
how likely a compound is to be a drug. The Quantitative Estimate of Druglikeness (QED) score quantifies compound quality with a weighted geometric mean of desirability scores capturing the underlying data distribution of several drug properties (Bickerton et al., 2012).
Solubility:
the degree to which a molecule is hydrophilic. The log octanol-water partition coefficient (logP), is defined as the logarithm of the ratio of the concentrations between two solvents of a solute (Comer & Tam, 2001).
Synthetizability:
this measure quantifies how easy a molecule is to synthesize. The Synthetic Accessibility score (Ertl & Schuffenhauer, 2009) is a method to estimate the ease of synthesis in a probabilistic way.
We also measure, without optimizing for it, a diversity score which indicates how likely a molecule is to be diverse with respect to the dataset. This measure compares sub-structures between samples and a random subset from the dataset indicating how many repetitions there are.
For evaluation, we report average scores from 6400 sampled compounds as in (Guimaraes et al., 2017). Additionally, we re-run experiments from (Guimaraes et al., 2017) to compute unique scores and execution time since it is not reported. Differently from ORGAN, to optimize for all objectives, we do not alternate between optimizing them individually during training which in our case is not possible since the reward network is specific to a single type of reward. Thus, we instead optimize a joint reward which we define as the product (to lie within ) of all objectives.
Results
Results are reported in Table 2. Qualitative samples are provided in the Appendix (Figure 3). We observe that MolGAN models always converge to very high validity outputs at the end of the training. This is coherent as observed in the previous experiment, since also here there is an implicit optimization of validity. Moreover, in all single metrics settings, our models beat ORGAN models in terms of valid scores as well as all the three objective scores we optimize for.
We argue that this should be mainly due to two factors: i) intuitively, it should be easier to optimize a molecular graph predicted as a single sample than to optimize an RNN model that outputs a sequence of characters, and ii) using the deterministic policy gradient instead of REINFORCE effectively provides a better gradient and it improves the sampling procedure towards metrics while penalizing invalid graphs.
Training on the full QM9 dataset for 10 times fewer epochs further improves results in almost all scores. During training, our algorithm observes more different samples, and therefore it can learn well with much fewer iterations. Moreover, it can observe molecules with more diverse structures and properties.
As previously observed in Section 5.1, also in this experiment the unique score is always close to 2% confirming our hypothesis that our models are susceptible to mode collapse. This is not the case for the ORGAN baseline. During sampling, ORGAN generates sequences of maximum 51 characters which allows it to generate larger molecules whereas our model is (by choice) constrained to generate up to 9 atoms. This explain the difference in unique score since the chance of generating different molecules in a smaller space is much lower. Notice that in ORGAN, the RL component relies on REINFORCE, and the unique score is optimized penalizing non-unique outputs which we do not.
In terms of training time, our model outperforms ORGAN by a large margin when training on the 5k dataset (at least 5 times faster in each setting), as we do not rely on sequential generation or discrimination. Both ORGAN and MolGAN have a comparable number of parameters, with the latter being approximately larger.
3 VAE Baselines
In this experiment, we compare MolGAN against recent likelihood-based methods that utilize VAEs. We report a comparison with CharacterVAE (Gómez-Bombarelli et al., 2016), GrammarVAE (Kusner et al., 2017), and GraphVAE (Simonovsky & Komodakis, 2018). Here we train using the complete QM9 dataset. Naturally, we compare only with metrics that measure the quality of the generative process since the likelihood is not computed directly in MolGAN. Moreover, we do not optimize any particular chemical property except validity (i.e., we do not optimize any metric described above, but we optimize towards chemically valid compounds). The final evaluation scores are an average from random samples. The number of samples differs from the previous experiment to be in line with the setting in Simonovsky & Komodakis (2018).
Results are reported in Table 3. Training on the full QM9 dataset (without optimizing any metric except validity) results in a model with a higher unique score compared to the ones in Section 5.2.
Though the unique score of MolGAN is slightly higher compared to GrammarVAE, the other baselines are superior in terms of this score. Even though here we do not consider our model to be collapsed, such a low score confirms our hypothesis that our model is prone to mode collapse. On the other hand, we observe significantly higher validity scores compared to the VAE-based baselines.To verify that sampled unique molecules are (mostly) novel and not simply memorized from the dataset, we additionally measure how many of the unique molecules are also novel for our model. This score is 97% indicating that almost all unique molecules are indeed novel and MolGAN does not suffer from such problems.
Differently from our approach, VAEs optimize the evidence lower bound (ELBO) and there is no explicit nor implicit optimization of output validity. Moreover, since a part of the ELBO maximizes reconstruction of the observations, the novelty in the sampling process is not expected to be high since it is not optimized. However, in all reported methods novelty is and, in the case of CharacterVAE, . Though CharacterVAE can achieve a high novelty score, it underperforms in terms of validity. MolGAN, on the other hand, achieves both high validity and novelty scores.
Conclusions
In this work, we have introduced MolGAN: an implicit generative model for molecular graphs of small size. Through joint training with a GAN and an RL objective, our model is capable of generating molecular graphs with both higher validity and novelty than previous comparable VAE-based generative models, while not requiring a permutation-dependent likelihood function. Compared to a recent SMILES-based sequential GAN model for molecular generation, MolGAN can achieve higher chemical property scores (such as solubility) while allowing for at least 5x faster training time.
A central limitation of our current formulation of MolGANs is their susceptibility to mode collapse: both the GAN and the RL objective do not encourage generation of diverse and non-unique outputs whereby the model tends to be pulled towards a solution that only involves little sample variability. This ultimately results in the generation of only a handful of different molecules if training is not stopped early.
We think that this issue can be addressed in future work, for example via careful design of reward functions or some form of pretraining. The MolGAN framework taken together with established benchmark datasets for chemical synthesis offer a new test bed for improvements on GAN stability with respect to the issue of mode collapse. We believe that insights gained from such evaluations will be valuable to the community even outside of the scope of generating molecular graphs. Lastly, it will be promising to explore alternative generative architectures within the MolGAN framework, such as recurrent graph-based generative models (Johnson, 2017; Li et al., 2018b; You et al., 2018), as our current one-shot prediction of the adjacency tensor is most likely feasible only for graphs of small size.
Acknowledgements
The authors would like to thank Luca Falorsi, Tim R. Davidson, Herke van Hoof and Max Welling for helpful discussions and feedback. T.K. is supported by SAP SE Berlin.