Skip to main content

The tool uncovers patterns, trends, and correlations hidden within your production datasets.

Project description

EPAM Syngen

EPAM Syngen is an unsupervised tabular data generation tool. It is useful for generation of test data with a given table as a template. Most datatypes including floats, integers, datetime, text, categorical, binary are supported. The linked tables i.e., tables sharing a key can also be generated using the simple statistical approach. The source of data might be in CSV, Avro format and should be located locally and be in UTF-8 encoding.

The tool is based on the variational autoencoder model (VAE). The Bayesian Gaussian Mixture model is used to further detangle the latent space.

Getting started

Use pip to install the library:

pip install syngen

The training and inference processes are separated with two cli entry points. The training one receives paths to the original table, metadata json file or table name and used hyperparameters.

To start training with defaults parameters run:

train --source PATH_TO_ORIGINAL_CSV \
    --table_name TABLE_NAME

This will train a model and save the model artifacts to disk.

To generate with defaults parameters data simply call:

infer --table_name TABLE_NAME

Please notice that the name should match the one you used in the training process.
This will create a csv file with the synthetic table in ./model_artifacts/tmp_store/TABLE_NAME/merged_infer_TABLE_NAME.csv.

Here is a quick example:

pip install syngen
train --source ./example-data/housing.csv –-table_name Housing
infer --table_name Housing

As the example you can use the dataset "Housing" in example-data/housing.csv. In this example, our real-world data is "Housing" from Kaggle.

Features

Training

You can add flexibility to the training and inference processes using additional hyperparameters.
For training of single table call:

train --source PATH_TO_ORIGINAL_CSV \
    --table_name TABLE_NAME \
    --epochs INT \
    --row_limit INT \
    --drop_null BOOL \
    --print_report BOOL \
    --batch_size INT

For training of the multiple linked tables call:

train --metadata_path PATH_TO_METADATA_YAML

The parameters which you can set up for training process:

  • source – required parameter for training of single table, a path to the file that you want to use as a reference
  • table_name – required parameter for training of single table, an arbitrary string to name the directories
  • epochs – a number of training epochs. Since the early stopping mechanism is implemented the bigger value of epochs is the better
  • row_limit – a number of rows to train over. A number less than the original table length will randomly subset the specified number of rows
  • drop_null – whether to drop rows with at least one missing value
  • batch_size – if specified, the training is split into batches. This can save the RAM
  • print_report - whether to generate plots of accuracy report and sample report
  • metadata_path – a path to the metadata file containing the metadata for linked tables
  • column_types - might include the section categorical which contains the listed columns defined as categorical by a user

Requirements for parameters of training process:

  • source - data type - string
  • table_name - data type - string
  • epochs - data type - integer, must be equal to or more than 1, default value is 10
  • row_limit - data type - integer
  • drop_null - data type - boolean, default value - False
  • batch_size - data type - integer, must be equal to or more than 1, default value - 32
  • print_report - data type - boolean, default value is False
  • metadata_path - data type - string
  • column_types - data type - dictionary with the key categorical - the list of columns (data type - string)

Inference (generation)

You can customize the inference processes by calling for one table:

infer --size INT \
    --table_name STR \
    --run_parallel BOOL \
    --batch_size INT \
    --random_seed INT \
    --print_report BOOL

For linked tables you can simply call:

infer --metadata_path PATH_TO_METADATA

The parameters which you can set up for generation process:

  • size - the desired number of rows to generate
  • table_name – required parameter for inference of single table, the name of the table, same as in training
  • run_parallel – whether to use multiprocessing (feasible for tables > 5000 rows)
  • batch_size – if specified, the generation is split into batches. This can save the RAM
  • random_seed – if specified, generates a reproducible result
  • print_report – whether to generate plots of accuracy report, sample report
  • metadata_path – a path to metadata file to generate linked tables

Requirements for parameters of generation process:

  • size - data type - integer, must be equal to or more than 1, default value is 100
  • table_name - data type - string
  • run_parallel - data type - boolean, default value is False
  • batch_size - data type - integer, must be equal to or more than 1
  • random_seed - data type - integer, must be equal to or more than 0
  • print_report - data type - boolean, default value is False
  • metadata_path - data type - string

The metadata can contain any of the arguments above for each table. If so, the duplicated arguments from the CLI will be ignored.

Linked tables generation

To generate linked tables, you should provide metadata in yaml format. It is used to handle complex relations for any number of tables. You can also specify additional parameters needed for training and inference in the metadata file and in this case, they will be ignored in the CLI call.

The yaml metadata file should match the following template:

CUSTOMER:                                       # Table name
    source: "./files/customer.csv"              # Supported formats include local files in CSV, Avro formats
             
    train_settings:                             # Settings for training process
        epochs: 10                              # Number of epochs if different from the default in the command line options
        drop_null: False                        # Drop rows with NULL values
        row_limit: None                         # Number of rows to train over. A number less than the original table length will randomly subset the specified rows number
        batch_size: 32                          # If specified, the training is split into batches. This can save the RAM
        print_report: False                     # Turn on or turn off generation of the report
        column_types:
            categorical:                        # Force listed columns to have categorical type (use dictionary of values)
                - gender
                - marital_status
             
    infer_settings:                             # Settings for infer process
        size: 100                               # Size for generated data
        run_parallel: False                     # Turn on or turn off parallel training process
        print_report: False                     # Turn on or turn off generation of the report
        batch_size: None                        # If specified, the generation is split into batches. This can save the RAM
        random_seed: None                       # If specified, generates a reproducible result
    keys:
        PK_CUSTOMER_ID:                         # Name of a key. Only one PK per table.
            type: "PK"                          # The key type. Supported: PK - primary key, FK - foreign key, TKN - token key
            columns:                            # Array of column names
                - customer_id
 
        UQ1:                                    # Name of a key
            type: "UQ"                          # One or many unique keys
            columns:
                - e_mail
 
        FK1:                                    # One or many foreign keys
            type: "FK"
            columns:                            # Array of columns in the current table
                - e_mail
                - alias
            references:
                table: "PROFILE"                # Name of the parent table
                columns:                        # Array of columns in the parent table
                    - e_mail
                    - alias
   
        FK2:
            type: "FK"
            columns:
                - address_id
            references:
                table: "ADDRESS"
                columns:
                    - address_id

 
ORDER:
    source: "./files/order.csv"
 
    train_settings:
        epochs: 10                              # Number of epochs if different from the default in the command line options
        drop_null: False                        # Drop rows with NULL values
        row_limit: None                         # Number of rows to train over. A number less than the original table length will randomly subset the specified rows number
        batch_size: 32                          # If specified, the training is split into batches. This can save the RAM
        print_report: False                     # Turn on or turn off generation of the report
        column_types:
            categorical:                        # Force listed columns to have categorical type (use dictionary of values)
                - gender
                - marital_status
 
    infer_settings:                             # Settings for infer process
        size: 100                               # Size for generated data
        run_parallel: False                     # Turn on or turn off parallel training process
        print_report: False                     # Turn on or turn off generation of the report
        batch_size: None                        # If specified, the generation is split into batches. This can save the RAM
        random_seed: None                       # If specified, generates a reproducible result
    keys:
        pk_order_id:
            type: "PK"
            columns:
                - order_id
 
        FK1:
            type: "FK"
            columns:
                - customer_id
            references:
                table: "CUSTOMER"
                columns:
                    - customer_id

You can find the example of metadata file in example-metadata/housing_metadata.yaml

For related tables training you can use the commands:

train --metadata_path=PATH_TO_YAML_METADATA_FILE
infer --metadata_path=PATH_TO_YAML_METADATA_FILE

Here is a quick example:

train --metadata_path="./example-metadata/housing_metadata.yaml"
infer --metadata_path="./example-metadata/housing_metadata.yaml"

If --metadata_path is present and the metadata contains the necessary parameters, other CLI parameters will be ignored.

Docker images

The train and inference components of syngen is available as public docker images:

https://hub.docker.com/r/tdspora/syngen-train

https://hub.docker.com/r/tdspora/syngen-infer

To run dockerized code (see parameters description in Training and Inference sections) for one table call:

docker pull tdspora/syngen-train:latest
docker run --rm \
  -v PATH_TO_LOCAL_FOLDER:/src/model_artifacts tdspora/syngen-train \
  --table_name=TABLE_NAME \
  --source=./model_artifacts/YOUR_CSV_FILE.csv

docker pull tdspora/syngen-infer:latest
docker run --rm \
  -v PATH_TO_LOCAL_FOLDER:/src/model_artifacts tdspora/syngen-infer \
  --table_name=TABLE_NAME

PATH_TO_LOCAL_FOLDER is an absolute path to the folder where your original csv is stored.

You can add any arguments listed in the corresponding sections for infer and training processes in the CLI call.

To run dockerized code for linked tables simply call:

docker pull tdspora/syngen-train:latest
docker run --rm \
  -v PATH_TO_LOCAL_FOLDER:/src/model_artifacts tdspora/syngen-train \
  --metadata_path=./model_artifacts/PATH_TO_METADATA_YAML

docker pull tdspora/syngen-infer:latest
docker run --rm \
  -v PATH_TO_LOCAL_FOLDER:/src/model_artifacts tdspora/syngen-infer \
  --metadata_path=./model_artifacts/PATH_TO_METADATA_YAML

You can add any arguments listed in the corresponding sections for infer and training processes in the CLI call, however, they will be overwritten by corresponding arguments in the metadata file.

Contribution

We welcome contributions from the community to help us improve and maintain our public GitHub repository. We appreciate any feedback, bug reports, or feature requests, and we encourage developers to submit fixes or new features using issues.

If you have found a bug or have a feature request, please submit an issue to our GitHub repository. Please provide as much detail as possible, including steps to reproduce the issue or a clear description of the feature request. Our team will review the issue and work with you to address any problems or discuss any potential new features.

If you would like to contribute a fix or a new feature, please submit a pull request to our GitHub repository. Please make sure your code follows our coding standards and best practices. Our team will review your pull request and work with you to ensure that it meets our standards and is ready for inclusion in our codebase.

We appreciate your contributions and thank you for your interest in helping us maintain and improve our public GitHub repository.

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

syngen-0.0.76.tar.gz (1.2 MB view hashes)

Uploaded Source

Built Distribution

syngen-0.0.76-py3-none-any.whl (1.2 MB view hashes)

Uploaded Python 3

Supported by

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