Skip to main content

Synthetic Data Generation with optional Differential Privacy

Project description

Gretel Synthetics

Gobs the Gretel.ai cat
An open source synthetic data library from Gretel.ai

gretel-synthetics workflows Documentation Status GitHub PyPI Python Downloads GitHub stars Slack

Documentation

Try it out now!

If you want to quickly discover gretel-synthetics, simply click the button below and follow the tutorials!

Open in Colab

Check out additional examples here.

Getting Started

By default, we do not install Tensorflow via pip as many developers and cloud services such as Google Colab are running customized versions for their hardware.

pip install -U .

or

pip install gretel-synthetics

then...

$ pip install jupyter
$ jupyter notebook

When the UI launches in your browser, navigate to examples/synthetic_records.ipynb and get generating!

If you want to install gretel-synthetics locally and use a GPU (recommended):

  1. Create a virtual environment (e.g. using conda)
$ conda create --name tf python=3.9
  1. Activate the virtual environment
$ conda activate tf
  1. Run the setup script ./setup-utils/setup-gretel-synthetics-tensorflow24-with-gpu.sh

The last step will install all the necessary software packages for GPU usage, tensorflow=2.8 and gretel-synthetics. Note that this script works only for Ubuntu 18.04. You might need to modify it for other OS versions.

Getting started with the timeseries DGAN model

The timeseries DGAN module contains a PyTorch implementation of a DoppelGANger model that is optimized for timeseries data. Similar to tensorflow, you will need to manually install pytorch

pip install torch==1.11.0

Overview

This package allows developers to quickly get immersed with synthetic data generation through the use of neural networks. The more complex pieces of working with libraries like Tensorflow and differential privacy are bundled into friendly Python classes and functions. There are two high level modes that can be utilized.

Simple Mode

The simple mode will train line-per-line on an input file of text. When generating data, the generator will yield a custom object that can be used a variety of different ways based on your use case. This notebook demonstrates this mode.

DataFrame Mode

This library supports CSV / DataFrames natively using the DataFrame "batch" mode. This module provided a wrapper around our simple mode that is geared for working with tabular data. Additionally, it is capabable of handling a high number of columns by breaking the input DataFrame up into "batches" of columns and training a model on each batch. This notebook shows an overview of using this library with DataFrames natively.

Components

There are four primary components to be aware of when using this library.

  1. Configurations. Configurations are classes that are specific to an underlying ML engine used to train and generate data. An example would be using TensorFlowConfig to create all the necessary parameters to train a model based on TF. LocalConfig is aliased to TensorFlowConfig for backwards compatability with older versions of the library. A model is saved to a designated directory, which can optionally be archived and utilized later.

  2. Tokenizers. Tokenizers convert input text into integer based IDs that are used by the underlying ML engine. These tokenizers can be created and sent to the training input. This is optional, and if no specific tokenizer is specified then a default one will be used. You can find an example here that uses a simple char-by-char tokenizer to build a model from an input CSV. When training in a non-differentially private mode, we suggest using the default SentencePiece tokenizer, an unsupervised tokenizer that learns subword units (e.g., byte-pair-encoding (BPE) [Sennrich et al.]) and unigram language model [Kudo.]) for faster training and increased accuracy of the synthetic model.

  3. Training. Training a model combines the configuration and tokenizer and builds a model, which is stored in the designated directory, that can be used to generate new records.

  4. Generation. Once a model is trained, any number of new lines or records can be generated. Optionally, a record validator can be provided to ensure that the generated data meets any constraints that are necessary. See our notebooks for examples on validators.

Utilities

In addition to the four primary components, the gretel-synthetics package also ships with a set of utilities that are helpful for training advanced synthetics models and evaluating synthetic datasets.

Some of this functionality carries large dependencies, so they are shipped as an extra called utils. To install these dependencies, you may run

pip install gretel-synthetics[utils]

For additional details, please refer to the Utility module API docs.

Differential Privacy

Differential privacy support for our TensorFlow mode is built on the great work being done by the Google TF team and their TensorFlow Privacy library.

When utilizing DP, we currently recommend using the character tokenizer as it will only create a vocabulary of single tokens and removes the risk of sensitive data being memorized as actual tokens that can be replayed during generation.

There are also a few configuration options that are notable such as:

  • predict_batch_size should be set to 1
  • dp should be enabled
  • learning_rate, dp_noise_multiplier, dp_l2_norm_clip, and dp_microbatches can be adjusted to achieve various epsilon values.
  • reset_states should be disabled

Please see our example Notebook for training a DP model based on the Netflix Prize dataset.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gretel-synthetics-0.18.0rc1.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

gretel_synthetics-0.18.0rc1-py3-none-any.whl (83.0 kB view details)

Uploaded Python 3

File details

Details for the file gretel-synthetics-0.18.0rc1.tar.gz.

File metadata

  • Download URL: gretel-synthetics-0.18.0rc1.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.13

File hashes

Hashes for gretel-synthetics-0.18.0rc1.tar.gz
Algorithm Hash digest
SHA256 64c827173bce51fa954980297567bb753fc241b51ff72e2addf85c73150c4dfe
MD5 9adef9e3bfbbbd6ac41e6ffd5002e6f4
BLAKE2b-256 bef1097993477438477b1e0e0829cc7878d0dcbf18e048168c15b6d0859348e4

See more details on using hashes here.

File details

Details for the file gretel_synthetics-0.18.0rc1-py3-none-any.whl.

File metadata

File hashes

Hashes for gretel_synthetics-0.18.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 1f295ed849f610f98770192341f71b7e22af8c55e8846e8fff59607b1ddc0eff
MD5 0418688ee31bf6ca7e29d2c02789a29b
BLAKE2b-256 a9aca5d09d0b83fff0068cf5db2a9d3ef2df589f8d7df484c07cf66c51483f0c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page