Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Workflow:Gretelai Gretel synthetics ACTGAN Tabular Synthesis

From Leeroopedia
Revision as of 11:04, 16 February 2026 by Admin (talk | contribs) (Auto-imported from workflows/Gretelai_Gretel_synthetics_ACTGAN_Tabular_Synthesis.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Synthetic_Data, Tabular_Data, GAN
Last Updated 2026-02-14 19:00 GMT

Overview

End-to-end process for training an ACTGAN (Anyway CTGAN) generative adversarial network on tabular data and sampling synthetic rows that preserve column distributions and correlations.

Description

This workflow uses ACTGAN, an extension of the CTGAN architecture, to generate synthetic tabular data. ACTGAN improves on CTGAN with better memory efficiency, automatic datetime detection, binary encoding for high-cardinality columns, and flexible conditional vector generation (ANYWAY mode). The model learns a joint distribution over all columns by transforming each column into a normalized representation, training a GAN with mode-specific normalization for continuous columns and conditional training for discrete columns, then inverse-transforming generated data back to the original space. It integrates with the SDV (Synthetic Data Vault) ecosystem for metadata detection and column type inference.

Key outputs:

  • A trained ACTGAN model (serializable via pickle)
  • Synthetic DataFrames sampled from the learned distribution

Usage

Execute this workflow when you have tabular data in a pandas DataFrame and need to generate synthetic rows using a GAN-based approach. ACTGAN is suitable for mixed-type tables containing both continuous and categorical columns, and handles high-cardinality categoricals efficiently through binary encoding. It is a good choice when you want fast, one-shot tabular synthesis without the LSTM overhead.

Execution Steps

Step 1: Model Initialization

Instantiate the ACTGAN model with desired hyperparameters. Key parameters include the GAN architecture dimensions (embedding, generator, discriminator layer sizes), learning rates and weight decay for both networks, batch size, number of discriminator steps per generator step, and the number of training epochs. Additional configuration controls binary encoding cutoff for high-cardinality columns, conditional vector type (SINGLE_DISCRETE or ANYWAY), and whether to auto-detect datetime columns.

Key considerations:

  • Set auto_transform_datetimes=True to automatically convert datetime columns to Unix timestamps
  • Use binary_encoder_cutoff to control when columns switch from one-hot to binary encoding
  • The ANYWAY conditional vector type enables more flexible conditional generation
  • Field types and transformers can be manually specified or auto-detected from the data

Step 2: Metadata Detection and Data Transformation

When fit is called, the model first detects column types and builds metadata. The SDVTableMetadata detector identifies datetime columns (if auto-detection is enabled), empty columns, and existing field type/transformer specifications. The DataTransformer then fits on the training data, learning per-column transformations: continuous columns are normalized using cluster-based normalization (fitting a variational Gaussian mixture model), and discrete columns are encoded via one-hot or binary encoding depending on cardinality.

Key considerations:

  • The ColumnarDF optimization avoids expensive DataFrame copy operations during metadata fitting
  • RDT (Reversible Data Transforms) is used under the hood with patches for float rounding bugs
  • Binary encoding reduces memory for columns with more unique values than the binary_encoder_cutoff
  • The DataSampler computes category frequencies for conditional vector sampling

Step 3: GAN Training

Train the generator and discriminator networks in an adversarial loop. Each training step: (1) samples a batch of real data with a conditional vector indicating which category to focus on, (2) generates a fake batch by passing random noise and the conditional vector through the generator, (3) updates the discriminator to distinguish real from fake samples, and (4) updates the generator to fool the discriminator while also minimizing a cross-entropy reconstruction loss on the conditional columns.

Key considerations:

  • The discriminator uses PacGAN (packing multiple samples per discriminator input) for training stability
  • The discriminator applies a gradient penalty for regularization
  • The generator uses residual layers for better gradient flow
  • An optional epoch_callback receives EpochInfo with generator loss, discriminator loss, and training duration

Step 4: Synthetic Data Sampling

Generate synthetic rows by feeding random noise vectors through the trained generator. The output is passed through column-specific activation functions (tanh for continuous, sigmoid for binary, Gumbel-softmax for one-hot columns), then inverse-transformed back to the original data space using the fitted DataTransformer. Optionally, conditions can be specified to generate data where certain columns match requested values.

Key considerations:

  • Sampling runs in evaluation mode with no gradient computation
  • Conditional generation supports specifying values for discrete columns
  • The force_conditioning option directly sets condition columns in output, bypassing rejection sampling for speed
  • The inverse transform reverses cluster-based normalization and decodes categorical encodings

Step 5: Model Persistence

Save the trained ACTGAN model to disk using pickle serialization for later reuse. The model can be loaded back on either CPU or GPU using the load_v2 class method, which handles cross-device weight mapping automatically.

Key considerations:

  • Epoch callbacks are temporarily removed during save since they cannot be pickled
  • The load_v2 method automatically detects the available device (CPU or CUDA)
  • Saved models contain the full DataTransformer state for inverse transformation during sampling

Execution Diagram

GitHub URL

Workflow Repository