sdv-dev / SDV

Synthetic data generation for tabular data
https://docs.sdv.dev/sdv
Other
2.21k stars 287 forks source link

PARSynthesizer: Duplicate sequence index values when `sequence_length` is higher than real data #2031

Closed srinify closed 4 weeks ago

srinify commented 1 month ago

Environment Details

Error Description

When the desired sequence length is higher than the real data's sequence length and min-max enforcement is enabled, PARSynthesizer can generate duplicate values. This seems to happen especially when the sequence index column is a datetime column. When synthesizing values for the sequence key column, PARSynthesizer runs into the max value and repeats it.

Steps to reproduce

Original Data

2 sequences, each with 5 unique values for the visits column (the sequence index)

Screenshot 2024-05-28 at 6 38 57 PM

Synthetic Data

Synthetic Data example when you set sequence_length parameter to 25:

Screenshot 2024-05-28 at 5 14 50 PM

Synthetic Data example when you set sequence_length parameter to 7:

Screenshot 2024-05-28 at 5 15 32 PM

Full code in Internal Colab Notebook here

Workarounds

Original Discussion here: https://github.com/sdv-dev/SDV/issues/2004

Scit3ch commented 1 month ago

@srinify Thank you very much for investigating further and providing a minimum working example.

A thought about your second workaround which would be a good solution for my problem with one addition. If I limit the sequence length via the parameter sequence_length of the synthesizer all sequences will have the same length, which doesn't represent the real data I have and others may also have very well. What about a parameter to limit the maximum sequence length to a defined value, but still allow sequences to be shorter. This could be achieved by finding the longest sequence in the training data lets say it's 100 and the maximum sequence length should be 50. So this means a 50% decrease for this sequence. This percentage could then be applied to all sequences (e.g. a sequence of 30 of the real data becomes 15). This would preserve the relative ratio of the sequence lengths between the training and generated data.

Regarding your first workaround: Setting enforce_min_max_values to false will effect all columns. An option to exclude certain user definable columns (like sequence_index column in this case) would be beneficial.

srinify commented 1 month ago

@Scit3ch all great ideas! In this case, it may be faster for the team to fix the core issue than add workarounds :) Stay tuned! 📺