GraphNVP: an Invertible Flow-based Model for Generating Molecular Graphs

1 INTRODUCTION . Generation of molecules with certain desirable properties is a crucial problem in computational drug discovery . Recently , deep learning approaches are being actively studied for generating promising candidate molecules quickly . Earlier models ( Kusner et al. , 2017 ; Gómez-Bombarelli et al. , 2018 ) depend on a string-based representation of molecules . However , recent models ( Jin et al. , 2018 ; You et al. , 2018a ; De Cao & Kipf , 2018 ) directly work on molecular graph representations and record impressive experimental results . In these studies , either variational autoencoder ( VAE ) ( Kingma & Welling , 2014 ) or generative adversarial network ( GAN ) ( Goodfellow et al. , 2014 ; Radford et al. , 2015 ) are used mainly to learn mappings between the graphs and their latent vector representations . In this paper , we propose GraphNVP , yet another framework for molecular graph generation based on the invertible normalizing flow , which was mainly adopted for image generation tasks ( Dinh et al. , 2017 ; Kingma & Dhariwal , 2018 ) . To capture distributions of irregular graph structure of molecules into a latent representation , we propose a novel two-step generation scheme . Specifically , GraphNVP is equipped with two latent representations for a molecular graph : first for the graph structure represented by an adjacency tensor , and second for node ( atom ) attributes . We introduce two types of reversible flows that work for the aforementioned two latent representations of graphs . Recent work by Liu et al . ( 2019 ) proposes a flow-based invertible model for transforming the node attribute matrix . However , they use a non-invertible encoder for transforming the adjacency tensor making the complete model non-invertible . Our model is the first fully invertible model for the whole graph components : both adjacency tensor and node attributes are converted into latent vectors through two novel invertible flows . To sample a graph , we develop a novel two-step generation process . During the generation process , GraphNVP first generates the graph structure . Then node attributes are generated according to this structure . This two-step generation enables efficient generation of valid molecular graphs . The full reversibility of our model on graphs contributes to two major benefits : a simple architecture and precise log-likelihood maximization . A major advantage of invertible models is that we do not need to design a separate decoder for sample generation : new graph samples can be generated by simply feeding a latent vector into the same model but in the reverse order . In contrast , VAE models require an encoder and a separated decoder . Decoding processes of several VAE graph generators are often quite complicated to assure valid generations ( Kusner et al. , 2017 ; Jin et al. , 2018 ; Ma et al. , 2018 ) , and computing a graph reconstruction loss may require expensive graph matching ( Simonovsky & Komodakis , 2018 ) . The lack of an encoder in GAN models makes it challenging to manipulate the sample generation . For example , it is not straightforward to use a GAN model to generate graph samples that are similar to a query graph ( e.g. , lead optimization for drug discovery ) , while it is easy for flow-based models . Unlike VAEs and GANs , invertible models are capable of precise log-likelihood evaluation . We believe precise optimization is crucial in molecule generation for drugs , which are highly sensitive to a minor replacement of a single atom ( node ) . In the experiments , we compare the proposed flow model with several existing graph generation models using two popular molecular datasets . The proposed flow model generates molecular graphs with almost 100 % uniqueness ratio : namely , the results contain almost no duplicated molecular graphs without ingrained domain expert knowledge and extra validity checks . The proposed model enjoys fast graph samplings ; faster in orders of magnitude than other graph generation models in our implementation . Additionally , we show that the learned latent space can be utilized to generate molecular graphs with desired chemical properties , even though we do not encode domain expert knowledge into the model . Finally we list open problems for the development of this new direction of fully invertible graph generation researches . 2 RELATED WORK . 2.1 MOLECULAR GRAPH GENERATION . We can classify the existing molecular graph generation models based on how the data distribution is learned . Most current models belong to two categories . First , VAE-based models assume a simple variational distribution for latent representation vectors ( Jin et al. , 2018 ; Liu et al. , 2018 ; Ma et al. , 2018 ) . Second , some models implicitly learn the empirical distribution , especially based on the GAN architecture ( e.g. , ( De Cao & Kipf , 2018 ; You et al. , 2018a ; Guimaraes et al. , 2017 ) ) . Some may resort to reinforcement learning ( You et al. , 2018a ) to alleviate the difficulty of direct optimization of the objective function . We also observe an application of autoregressive recurrent neural networks ( RNN ) for graphs ( You et al. , 2018b ) . In this paper , we will add a new category to this list : namely , the invertible flow . Additionally , we can classify the existing models based on the process they use for generating a graph . There are mainly two choices in the generation process . One is a sequential iterative process , which generates a molecule in a step-by-step fashion by adding nodes and edges one by one ( Jin et al. , 2018 ; You et al. , 2018a ) . The alternative is one-shot generation of molecular graphs , when the graph is generated in a single step . This process resembles commonly used image generation models ( e.g. , ( Kingma & Dhariwal , 2018 ) ) . The former process is advantageous in ( i ) dealing with large molecules and ( ii ) forcing validity constraints on the graph ( e.g. , a valency condition of molecule atoms ) . The latter approach has a major advantage : the model is simple to formulate and implement . This is because the one-shot approach does not have to consider arbitrary permutations of the sequential steps , which can grow exponentially with the number of nodes in the graph . Combining these two types of classification , we summarize the current status of molecular graph generation in Table 1 . In this paper , we propose the first graph generation model based on the invertible flow , with one-shot generation strategy . 2.2 INVERTIBLE FLOW MODELS . To the best of our knowledge , the invertible flow was first introduced to the machine learning community by ( Tabak & Vanden-Eijnden , 2010 ; Tabak & Turner , 2013 ) . Later , Rezende & Mohamed ( 2015 ) and Dinh et al . ( 2015 ) leveraged deep neural networks in defining tractable invertible flows . Dinh et al . ( 2015 ) introduced reversible transformations for which the log-determinant calculation is tractable . These transformations , known as coupling layers , serve as the basis of recent flow-based image generation models ( Dinh et al. , 2017 ; Kingma & Dhariwal , 2018 ; Grathwohl et al. , 2019 ) Readers are referred to the latest survey ( Kobyzev et al. , 2019 ) for the general flow methodologies . So far , the application of flow-based models is mostly limited to the image domain . As a few exceptions , Kumar et al . ( 2018 ) proposed flow-based invertible transformations on graphs . However , their model is only capable of modeling the node assignments and can not learn a latent representation of the adjacency tensor ; therefore , it can not generate a graph structure . Liu et al . ( 2019 ) proposed to plug a non-invertible decoder for the adjacency tensor to this flow model afterwards , giving up training the entire graph generator in a single unified estimator . We overcome this issue by introducing two latent representations , one for node assignments and another for the adjacency tensor , to capture the unknown distributions of the graph structure and its node assignments . Thus , we consider our proposed model to be the first invertible flow-based model that can generate attributed graphs including the adjacency structure . 3 GRAPHNVP : FLOW-BASED GRAPH GENERATION MODEL . 3.1 FORMULATION . We use the notation G = ( A , X ) to represent a graph G consisting of an adjacency tensor A and a feature matrix X . Let there be N nodes in the graph . Let M be the number of types of nodes and R be the number of types of edges . Then A ∈ { 0 , 1 } N×N×R and X ∈ { 0 , 1 } N×M . In the case of molecular graphs , G = ( A , X ) represents a molecule with R types of bonds ( single , double , etc . ) and M types of atoms ( e.g. , oxygen , carbon , etc. ) . Our objective is to learn an invertible model fθ with parameters θ that maps G into a latent point z = fθ ( G ) ∈ RD= ( N×N×R ) + ( N×M ) . We describe fθ as a normalizing flow composed of multiple invertible functions . Let z be a latent vector drawn from a known prior distribution pz ( z ) ( e.g. , Gaussian ) : z ∼ pz ( z ) . With the change of variable formula , the log probability of a given graph G can be calculated as : log ( pG ( G ) ) = log ( pz ( z ) ) + log ( ∣∣∣∣det ( ∂z∂G ) ∣∣∣∣ ) , ( 1 ) where ∂z∂G is the Jacobian of fθ at G . 3.2 GRAPH REPRESENTATION . Directly applying a continuous density model on discrete components may result in degenerate probability distributions . Therefore , we can not directly employ the change of variable formula ( Eq . 1 ) for these components . The same issue , especially modeling the discrete structure of the adjacency A , has been a problem in existing one-shot generators based on GAN ( De Cao & Kipf , 2018 ) and VAE ( Ma et al. , 2018 ) . They resort to an ad-hoc workaround ; treating the adjacency tensor as a real-valued continuous tensor . In this paper we take another approach , dequantization ( Theis et al. , 2016 ) , following the flow-based image generation models ( Dinh et al. , 2017 ; Kingma & Dhariwal , 2018 ) . The dequantization process adds uniform noises to A and X and yield the dequantized graph component G′ = ( A′ , X ′ ) . Specifically , A′ = A+ cu ; u ∼ U [ 0 , 1 ) N×N×R and X ′ = X + cu ; u ∼ U [ 0 , 1 ) N×M , where 0 < c < 1 is a scaling hyperparameter ( c = 0.9 is adopted for our experiment ) . This G′ is used as the input in Eq . 1 . Note that the original discrete inputs A and X can be recovered by quantization : simply applying floor operation on each continuous value in A′ and X ′ . Hereafter , all the transformations consisting fθ are performed on dequantized inputs A′ and X ′ , not on A and X . It means fθ is a bijective function that maps G′ → z : thus f−1 ( z ) returns the dequantized G′ , not the original G. However , our generative model can recover the original discrete G by performing the postprocessing quantization to inverted G′ . There are a few works related to discrete invertible flows such as ( Hoogeboom et al. , 2019 ; Tran et al. , 2019 ) . The former maps discrete data x to a discrete latent space . However , we prefer a smoothly distributed continuous latent space for molecule decoration and optimization applications ( see Sec . 4.3 ) . The latter can map discrete data x to a continuous z , but computation includes approximation . Approximated likelihood evaluations decreases the significance of the invertible flows against VAEs . So we do not adopt these options in this paper .

Summary: This paper presents a new reversible flow-based graph generative model wherein the whole graph i.e., representative attributes such as node features and adjacency tensor is modeled using seperate streams of invertible flow model. This allows training of generative model using exact likelihood maximization over the underlying graph dataset.The model avoids encoding any domain specific heuristics and thus can be applied to any structured graph data. The paper focusses it applicability for molecular graphs. Given that this approach avoids sequential generation of graph, it is faster by an order of magnitude than prior models for molecular generation. Empirical experiments on couple of molecular graph data suggets that GraphNVP approach performs as well as prior approach but albeit without any rule checker.