* HSASynthesizer

*SDV Enterprise Feature. This feature is only available for licensed, enterprise users. To learn more about the SDV Enterprise features and purchasing a license, visit our website.

The HSA Synthesizer uses a segment-based algorithm to learn from your real data and generate synthetic data. This synthesizer offers fast performance for unlimited tables.

from sdv.multi_table import HSASynthesizer

synthesizer = HSASynthesizer(metadata)

synthetic_data = synthesizer.sample()

Creating a synthesizer

When creating your synthesizer, you are required to pass in a Multi Table Metadata object as the first argument.

synthesizer = HSASynthesizer(metadata)

All other parameters are optional. You can include them to customize the synthesizer.

Parameter Reference

locales: A list of locale strings. Any PII columns will correspond to the locales that you provide.

(default) ['en_US']

Generate PII values in English corresponding to US-based concepts (eg. addresses, phone numbers, etc.)


Create data from the list of locales. Each locale string consists of a 2-character code for the language and 2-character code for the country, separated by an underscore.

For example ["en_US", "fr_CA"].

For all options, see the Faker docs.

synthesizer = HSASynthesizer(
    locales=['en_US', 'en_CA', 'fr_CA']

default_num_clusters: The number of clusters to segment each table into

(default) 3

Split each table into 3 clusters for the purposes of capturing correlations between parent and child tables


Split each table into the desired number of clusters. A smaller number of clusters makes the fit and sampling more efficient, and generally noises the data. A large number of clusters allows the model to learn more specific correlations across parent/child tables.


The HSA Synthesizer is a multi-table algorithm that models each individual table as well as the connections between them. You can get and set the parameters for each individual table.


  • (required) table_name: A string describing the name of the table

  • table_synthesizer: The single table synthesizer to use for modeling the table

    • (default) 'GaussianCopulaSynthesizer': Use the GaussianCopulaSynthesizer to model the single table

    • Other available options: 'GaussianCopulaSynthesizer', 'CTGANSynthesizer', 'TVAESynthesizer', 'CopulaGANSynthesizer'. For more information, see Single Table Synthesizers.

  • table_parameters: A dictionary mapping the name of the parameter (string) to the value of the parameter (various). These parameters are different for each synthesizer. For more information, see Single Table Synthesizers.

Output (None)

        'enforce_min_max_values': True,
        'default_distribution': 'truncnorm',
        'numerical_distributions': { 
            'checkin_date': 'uniform',
            'amenities_fee': 'beta' 


Use this function to access the all parameters your synthesizer uses -- those you have provided as well as the default ones.

Parameters (None)

Output A dictionary with the table names and parameters for each table.

These parameters are only for the multi-table synthesizer. To get individual table-level parameters, use the get_table_parameters function.

The returned parameters are a copy. Changing them will not affect the synthesizer.

    'locales': ['en_US', 'fr_CA'],


Use this function to access the all parameters a table synthesizer uses -- those you have provided as well as the default ones.


  • (required) table_name: A string describing the name of the table

Output A dictionary with the parameter names and the values

    'synthesizer_name': 'GaussianCopulaSynthesizer',
    'synthesizer_parameters': {
        'default_distribution': 'beta',


Use this function to access the metadata object that you have included for the synthesizer

Parameters None

Output A MultiTableMetadata object

metadata = synthesizer.get_metadata()

The returned metadata is a copy. Changing it will not affect the synthesizer.

Learning from your data

To learn a machine learning model based on your real data, use the fit method.



  • (required) data: A dictionary mapping each table name to a pandas DataFrame containing the real data that the machine learning model will learn from

Output (None)

Technical Details: HSA, which stands for Hierarchical Segmentation Algorithm, uses a segment-based approach to model the parent-child relationships of a multi-table datasets. At a base level, it can model individual tables using any single table synthesizer.


After fitting this synthesizer, you can access the marginal distributions that were learned to estimate the shape of each column.


  • (required) table_name: A string with the name of the table

Output A dictionary that maps the name of each learned column to the distribution that estimates its shape

    'amenities_fee': {
        'distribution': 'beta',
        'learned_parameters': { 'a': 2.22, 'b': 3.17, 'loc': 0.07, 'scale': 48.5 }
    'checkin_date': { 

For more information about the distributions and their parameters, visit the Copulas library.

Learned parameters are only available for parametric models and distributions. For eg. you will not be able to access learned distributions for GAN-based synthesizers (such as CTGAN) or the 'gaussian_kde' technique.

In some cases, the synthesizer may not be able to fit the exact distribution shape you requested, so you may see another distribution shape (eg. 'truncnorm' instead of 'beta').


After fitting, you can access the loss values computed during each epoch for both the numerator and denominator.


  • (required) table_name: A string with the name of the table

Output A pandas.DataFrame object containing epoch number, generator loss value and discriminator loss value.

Epoch  Generator Loss  Discriminator Loss
1      1.7863          -0.3639
2      1.5484          0.2260
3      1.3633          -0.0441

Loss values are only available for tables that use neural network-based models. such as CTGAN, TVAE or CopulaGAN.

Saving your synthesizer

Save your trained synthesizer for future use.


Use this function to save your trained synthesizer as a Python pickle file.


  • (required) filepath: A string describing the filepath where you want to save your synthesizer. Make sure this ends in .pkl

Output (None) The file will be saved at the desired location



Use this function to load a trained synthesizer from a Python pickle file


  • (required) filepath: A string describing the filepath of your saved synthesizer

Output Your synthesizer, as a HMASynthesizer object

from sdv.multi_table import HSASynthesizer

synthesizer = HSASynthesizer.load(

What's next?

After training your synthesizer, you can now sample synthetic data. See the Sampling section for more details.

Want to improve your synthesizer? Input logical rules in the form of constraints, and customize the transformations used for pre- and post-processing the data.

For more details, see Advanced Features.


What happens if the columns don't contain numerical data?

This synthesizer models non-numerical columns, including columns with missing values.

Although the HSA algorithm is designed for only numerical data, this synthesizer converts other data types using Reversible Data Transforms (RDTs). To access and modify the transformations, see Advanced Features.

Last updated

Copyright (c) 2023, DataCebo, Inc.