Generating Realistic Synthetic Relational Data through Graph Variational Autoencoders
Abstract
Synthetic data generation has recently gained widespread attention as a more reliable alternative to traditional data anonymization.
The involved methods are originally developed for image synthesis.
Hence, their application to the typically tabular and relational datasets from healthcare, finance and other industries is nontrivial.
While substantial research has been devoted to the generation of realistic tabular datasets, the study of synthetic relational databases is still in its infancy.
In this paper, we combine the variational autoencoder framework with graph neural networks to generate realistic synthetic relational databases.
We then apply the obtained method to two publicly available databases in computational experiments.
The results indicate that real databases’ structures are accurately preserved in the resulting synthetic datasets, even for large datasets with advanced data types. ∗
Introduction
Increases in computational power as well as general awareness have brought data sciences to the forefront of modern business management.
However, with the upsurge in data usage came an upsurge in privacy concerns and protocols.
Since the introduction of the General Data Protection Regulation (GDPR) in the European Union, over 1,100 fines have been issued [1], a number that grows steadily.
Legal (see, e.g. [2, 3]), scientific (see, e.g., [4, 5]) and anecdotal evidence indicate that traditional anonymization techniques offer insufficient protection against data breaches.
A famous example is the 2014 New York City Taxi and Limousine Commission data breach [6], in which hackers could infer drivers’ addresses and incomes.
Deep-learning generative models (DLGMs) have gained attention as a more reliable alternative to anonymization [7, 8, 9].
Rather than distorting existing datasets to mask its subjects, these methods create entirely synthetic new datasets.
However, these synthetic datasets retain all the intricate patterns of the real datasets used in the DLGM’s training.
DGLMs such as variational autoencoders (VAE) have been applied succesfully for realistic image generation [10, 11] and more recently for generating realistic tabular data with statistically independent rows [12, 13, 14, 15, 16, 17].
However, the lack of methods for more advanced database structures such as relational databases limits the use cases to which DLGMs can be applied.
Some methods for relational databases with single main tables and multiple secondary tables have been proposed (see, e.g. [18]).
However, these methods do not generalize to more complex database, lacking the ability to process many interconnected tables.
In this paper, we introduce graph-VAE, a method based on graph neural networks and VAE to generate realistic synthetic relational data.
We also evaluate the effectiveness of the method using publicly available datasets through model compatibility metrics and a privacy assessment.
Results indicate that graph-VAE generates relational databases that accurately securely preserve real databases’ structures, even for large datasets with advanced data types.
Background 2.1 Variational autoencoders
Given a table of data T , the objective of a deep-learning generative model (DLGM) is to construct a new dataset T ′ such that T and T ′ have the same distribution.
A variational autoencoder (VAE) does this by connecting encoder and decoder neural networks [12, 16].
Encoder q ϕ ( z | x ) , x ∈ T , parameterized by ϕ , maps T to a probability distribution (“code”).
Decoder p ψ ( x | z ) , parameterized by ψ , maps latent variables z to the data space.
Training a VAE is maximizing the (log-)likelihood that code samples are taken from the original data’s distribution.
Structure is imposed on the encoder by minimizing its KL-divergence with a prior P (typically Gaussian).
This gives the loss function in expression (1), for D KL the KL-divergence and β a hyperparameter.
[Equation]
2.2 Graph neural networks
Graph neural networks (GNN) are structures designed to reconcile neural networks with advances data types modeled through graph theory.
GNN models typically involve a message passing step [19, 20].
Such a step distributes information contained in feature values of a specific vertex to its neighborhood, allowing subsequent neural network layers to infer patterns on a larger structural level than that of mere individual node features.
Several layers of message passing can be cascaded.
Let G =
( V, E ) be a graph, in which each vertex t ∈ V has a set of vertex features X t and each edge { s, t } ∈ E has a set of edge features X { s,t } .
Additionally, a collection H ls of hidden vertex variables is associated with each vertex t ∈ V .
Let N ( t ) denote the neighborhood of vertex t ∈ V , that is:
N ( t ) :
= { s ∈ V : { s, t } ∈ E } .
Suppose there are L message layers.
In each layer l and for each vertex s ∈ V , vertex features h ls ∈ H ls are updated through a differentiable message function M l and a differentiable update function U l according to equation (2).
[Equation]
For a given vertex, the message function computes messages from adjacent vertices, which are then aggregated over the vertex’ neighborhood.
We aggregate through summation, though other aggregation operations may also be chosen.
The update function uses the aggregated messages to update the vertex attributes.
Graph Variational Autoencoders for Realistic Synthetic Relational Data 3.1 Relational data
Our graph variational autoencoder (graphVAE) combines VAE with GNN to generate realistic tabular data.
A dataset D is a collection of one or more tables { T 1 , T 2 , . . . } .
A table T is a collection of rows { t 1 , . . .
, t n } .
A row t is a tuple defined over a sequence of attributes A ( T ) =
( a 1 , . .
. , a p ) and represents an entity in the real world: we denote by v ( t, a ) ∈ V ( T, a ) ∪ ∅ the value of the attribute a for the row t , with V ( T, a ) being the domain of the attribute a and ∅ representing the undefined value (i.e., v ( t, a ) = ∅ means that a is missing for t ).
We say that an attribute a is unique for a table
T
if and only if the mapping t i (cid:55)→ v ( t i , a ) is injective for all t i ∈ T and a is always defined in T .
We say that a dataset D is relational if the following conditions hold:
it contains at least two tables; 2.
at least one primary table T ⋆ has a unique attribute a ⋆ ; 3.
for each other secondary table T in the dataset, A ( T ) ∋ a ⋆ and ∀ t ∈ T, ∃ t ⋆ ∈ T ⋆ : v ( t, a ⋆ )
= v ( t ⋆ , a ⋆ ) .
Intuitively, a relational dataset is a dataset with a primary table T ⋆ describing some entities, one row per entity, and other tables describing some other entities, each one linked to one specific entity of
T ⋆ .
For example, a primary table may contain information about customers, and a secondary table may contain data about specific purchases.
We refer to the attribute a ∗ as the identifier attribute .
3.2 Graph theoretic representation of relational data
To model relational databases as graphs, we follow [21].
Consider a relational dataset D with a primary table T ∗ and special attribute a ∗ .
Define the relational graph G ( D ) =
( V ( D ) , E ( D ))
according to equation (3).
[Equation]
so that the identifier attribute a ∗ (unique in T ∗ ) links records in secondary tables back to the specific row in the primary table with the corresponding identifier value.
We note that the definition of a relational graph also applies to relational databases with multiple primary tables and identifier attributes, by computing the edge set for all identifier attributes (including nested structures where a table T may serve as a primary table to a table T ′ , but as a secondary table to a table T ′′ ).
For a relational graph G ( D ) of a relational dataset D , we define the edge list attribute , denoted by a † for all T ∈ D according to equation (4)
[Equation]
3.3 GraphVAE architecture
Let D be a relational dataset with a primary table T ∗ , secondary tables T 1 , T 2 , ... and relational graph
G ( D ) =
( V ( D ) , E ( D )) .
Let ϕ † be the mapping such that ϕ † ( G ( D ))
= a † , for a † the edge list of
G ( D ) .
Use this mapping to obtain and store a † .
Next, follow the preprocessing steps detailed in [18] for each table T ∈ D .
Particularly, an invertible function ϕ type maps tables containing numeric, ϕ type ϕ † ϕ v
MP ϕ enc
N −
N ϕ dec
MP ϕ − 1 v ϕ − 1 type T ⋆ ,T l a †
X ∗ ,X l
X
X ′
Y ′ µ, Σ ˆ Y ′
ˆ X ′ ˆ X
ˆ X ∗ , ˆ X l ˆ T ∗ , ˆ T l a † n kk categorical and date-time attributes to normalized tables of only numeric attributes.
Subsequently, an invertible function ϕ v maps all tables T ∈ D to a single table as follows. First, add the edge list attribute a † to all tables. Next, initialize a table X with attribute set A ( X ) = (cid:83) T ∈
D A ( T ) ∪ (cid:8) a † (cid:9) . Note that, as each table contains the special attribute a ∗ , we have | A ( X ) | = (cid:80) T ∈ D A ( T ) − | D |
+ 2 .
Subsequently, all rows of all tables T ∈ D are added to X through vertical concatenation, where ∀ a ∈ A ( X ) : v ( x, a ) = (cid:26) v ( t, a ) , if a ∈ A ( T ) ∪ (cid:8) a † (cid:9) 0 , otherwise , (5) and v ( t, a † ) is the adjacency list of the vertex corresponding to vertex (row of some table) t .
The table X is a representation of a graph with vertex features and adjacency lists.
Subsequently, k 1 message passing layers are applied to the graph represented by X .
The number kis a hyperparameter determined by the user.
Larger values of k 1 result in information being more distributed throughout the graph.
The message and update functions are provided in equations (6).
[Equation]
where GRU is a gated recurrent unit (cf.
[21]); A is a a matrix of learned parameters that map edge features to the appropriate dimensions; and h lt is the value v ( t, a ) for t ∈ X in message passing layer l .
After the message passing phase, attribute a † is discarded and the remaining table, say X ′ , is fed into a variational autoencoder with a standard multivariate normal Gaussian prior, the dimension of which is a hyperparameter chosen by the user.
Random samples ˆ Y ′ in the latent space are taken and transferred back to the data space by the decoder.
Subsequently, a user-specified number k 2 of additional message passing layers are applied before the data is transferred to the original primary and secondary table structure through the inverse preprocessing functions.
A standard VAE loss function is invoked during training (see equation (1)).
This is illustrated in a computational diagram in Figure 1.
Experimental Results 4.1 Datasets
We applied our method to two publicly available datasets: the BasketballMen dataset from the
Relational Dataset Repository [22] and the Rossmann Store Sales dataset from Kaggle [23].
These sets have a single primary table and two and one secondary tables, respectively.
All attribute types (numeric, categorical, date-time) are represented in these sets.
Both secondary tables of the
BasketballMen dataset are linked to the primary dataset through the same identifier attribute.
While the Rossmann dataset has only one child table, it has a large data volume and a more complex mixture of datatypes.
Table 1 summarizes the salient information of the datasets. [Table]
4.2 Experimental set-up
We used the architecture from Figure 1 to generate synthetic data with each of the two datasets as input.
Hyperparameters are initiated based on available domain knowledge.
They are then optimized manually by repeating the experiments with slightly altered values.
The obtained hyperparameters are provided in Table 2.
To measure the degree to which generated synthetic data preserves the structure of the input data, we use model compatibility (MC) through the following procedure: 1) we divide the input dataset into a training set (80%) and a test set (20%); 2) We train the graphVAE using the training set; 3)
We use the trained model to construct the synthetic dataset; 4) We train two gradient boosted trees (XGBoost) classifiers: one on the on the join of the primary and secondary tables of the training set; and one on the join of the synthetic primary and secondary tables.
Both classifiers have the same target column based on domain knowledge: “position” (categorical, position of a player) for the basketball dataset and “Promo” (Boolean, whether or not there was a promotion in the store) for the Rossman store dataset); 5) We apply both models to the same test set (20% of the original dataset) and evaluate standard machine learning metrics (ROC AUC and F1-score) of the trained models; 6) We compare the performance metrics of the model built on the training set to those built on the test set.
If the synthetic data accurately mimics the properties of the input dataset, the performances of both models should be roughly equal.
As a quantitative indicator of model compatibility, we use the metric
[Equation]
where D and ˆ D are the real and synthetic datasets, respectively; m and ˆ m are the model built on the training and synthetic datasets, respectively; and e is the effectiveness metric (ROC AUC or F1-score).
The closer MC ( D, ˆ D ) is to zero, the more similar the performance of the two models is on the test data: it indicates that patterns learned from the original dataset are also learned from the synthetic data.
To quantify the degree to which synthetic data protects the privacy of individuals contained in the original dataset, we follow [18, 24, 17] in using nearest neighbor distance-based metrics.
Intuitively, these metrics measure whether synthetic records are too close to real records, making it possible to re-identify a real individual, or their characteristics.
In particular, define the nearest neighbor distribution NN X,Y : X
→ R of two datasets X and Y through
[Equation]
for d the Euclidean distance measure.
We partition the original dataset D into two sets D 1 , D 2 of the same cardinality.
We then compute the fifth percentile α of the distribution NN D 1 ,D 2 / NN D 1 ,D 1 .
The privacy score P ( ˆ D ) of synthetic dataset ˆ D is then defined as
[Equation]
Param
Description
Basketball
Rossmann n
VAE latent space dimensionality [8, 10, 10] [8, 8] k# message passing layers  k
# message passing layers  β
VAE loss terms tradeoff [1,1,1] [5,5,5] with synthetic dataset ˆ D considered sufficiently private
if P ( ˆ D ) ≤ 0 . 05 and insufficiently private otherwise.
Intuitively, the metric assesses the proportion of original records that are closer to synthetic records, than the 5% of smallest distances between records from D 1 and D 2 .
4.3 Results and discussion
The model compatibilitiies for the BasketballMen dataset are 0.07 (ROC AUC) and 0.24 (F1-score).
For the Rossmann Store Sales dataset, they are 0 .
03 (ROC AUC) and 0.07 (F1-score).
Figure 2 shows the performance metrics of the models evaluated on the test dataset.
In both experiments, the value
P ( ˆ D ) is significantly below 0 .
(BasketballMen: 0.02; Rossman Store Sales: 0.00), indicating that the synthetic data does not pose a privacy risk to real individuals.
Results indicate that the method can generate accurate synthetic relational data whilst preserving privacy.
The model compatability metric value is significantly smaller for the Rossman data (especially the F1-score).
This indicates that the number of secondary tables has a bigger impact on the results than the volume of the data and the complexity of its datatypes.
Nonetheless, the metric value is sufficiently small for the synthetic data to be of use in testing, analytic and machine learning contexts.
Conclusion
We propose a novel deep learning method for the generation of realistic synthetic relational data based on graph neural networks and variational autoencoders.
By treating links between tables in a relational database as edges in a graph, message passing layers enable information to propagate through the database.
Subsequently, the encoder can infer inter-table patterns, which are reproduced during synthesis.
Computational experiments on publicly available datasets indicate that our method creates highly realistic synthetic relational data that does not disclose sensitive information of individuals in the original database.
The proposed method works well, even for a database with a large data volume and complex data types.
The quantity of tables in the relational database may render synthesis more problematic, though the results were promising also for a set with two secondary tables.
Improved hyperparameter optimization may improve the results further.
Future research should inspect whether there is a correlation between the number of tables in the database and the performance of graphVAE.
Dedicated heuristics for hyperparameter optimization should also be explored