Open msgonzaga opened 3 years ago
Update, when running the smaller example (with up to 10 rows), I got the following:
MemoryError: Unable to allocate 14.7 GiB for an array with shape (44413, 44413) and data type float64
These are the shapes of the csvs being used for this case (rows, columns): (10, 10), (3, 5), (10, 6), (8, 3), (10, 4), (10, 9), (10, 8), (10, 4), (8, 5), (10, 4), (6, 6)
I'm clearly doing something wrong here.
Hi @msgonzaga
I don't think you are doing anything wrong. It's just a combination of two things: (1) there are a lot of nested levels, which makes the problem big and (2) the default parameters from SDV 0.4.5 are not optimal for such scenarios.
I just made a release candidate for v0.5.0 a few minutes ago which should be able to handle this better. Would you mind installing it and trying again?
To install it run pip install -U --pre sdv
and then make sure that you have sdv==0.5.0.dev0
installed.
I will also try to reproduce this on my side to explore it a bit more.
Hi @csala, thanks for your attention.
I tried using the sdv==0.5.0.dev0
version and unfortunately got an error:
Traceback (most recent call last):
File "example_sdv.py", line 59, in <module>
sample = multi_table_gen(folder)
File "example_sdv.py", line 41, in multi_table_gen
model.fit(tables)
File "/usr/local/lib/python3.8/dist-packages/sdv/relational/base.py", line 63, in fit
self._fit(tables)
File "/usr/local/lib/python3.8/dist-packages/sdv/relational/hma.py", line 199, in _fit
self._model_table(table_name, tables)
File "/usr/local/lib/python3.8/dist-packages/sdv/relational/hma.py", line 164, in _model_table
table = self._extend_table(table, tables, table_name)
File "/usr/local/lib/python3.8/dist-packages/sdv/relational/hma.py", line 103, in _extend_table
extension = self._get_extension(child_name, child_table, child_key)
File "/usr/local/lib/python3.8/dist-packages/sdv/relational/hma.py", line 90, in _get_extension
model.fit(child_rows.reset_index(drop=True))
File "/usr/local/lib/python3.8/dist-packages/sdv/tabular/base.py", line 112, in fit
transformed = self._metadata.transform(data)
File "/usr/local/lib/python3.8/dist-packages/sdv/metadata/table.py", line 515, in transform
return self._hyper_transformer.transform(data)
File "/usr/local/lib/python3.8/dist-packages/rdt/hyper_transformer.py", line 155, in transform
transformed = transformer.transform(column)
File "/usr/local/lib/python3.8/dist-packages/rdt/transformers/categorical.py", line 174, in transform
return data.fillna(np.nan).apply(self._get_value).to_numpy()
File "/usr/local/lib/python3.8/dist-packages/pandas/core/series.py", line 4212, in apply
mapped = lib.map_infer(values, f, convert=convert_dtype)
File "pandas/_libs/lib.pyx", line 2403, in pandas._libs.lib.map_infer
File "/usr/local/lib/python3.8/dist-packages/rdt/transformers/categorical.py", line 147, in _get_value
mean, std = self.intervals[category][2:]
KeyError: nan
Update: I tried it again with the new 0.5.0 stable version and apparently got an error in the reverse_transform operation:
Traceback (most recent call last):
File "example_sdv.py", line 59, in <module>
sample = multi_table_gen(folder)
File "example_sdv.py", line 46, in multi_table_gen
sample = model.sample()
File "/usr/local/lib/python3.8/dist-packages/sdv/relational/base.py", line 186, in sample
return self._sample(table_name, num_rows, sample_children)
File "/usr/local/lib/python3.8/dist-packages/sdv/relational/hma.py", line 408, in _sample
sampled = self._sample_table(table, num_rows)
File "/usr/local/lib/python3.8/dist-packages/sdv/relational/hma.py", line 371, in _sample_table
return self._finalize(sampled_data)
File "/usr/local/lib/python3.8/dist-packages/sdv/relational/hma.py", line 229, in _finalize
parent_ids = self._find_parent_ids(table_name, parent_name, sampled_data)
File "/usr/local/lib/python3.8/dist-packages/sdv/relational/hma.py", line 348, in _find_parent_ids
parent_rows = self._sample_rows(parent_model, parent_name, num_parent_rows)
File "/usr/local/lib/python3.8/dist-packages/sdv/relational/hma.py", line 268, in _sample_rows
sampled = model.sample(num_rows)
File "/usr/local/lib/python3.8/dist-packages/sdv/tabular/base.py", line 153, in sample
sampled = self._metadata.reverse_transform(sampled)
File "/usr/local/lib/python3.8/dist-packages/sdv/metadata/table.py", line 570, in reverse_transform
reversed_data[name] = field_data[field_data.notnull()].astype(self._dtypes[name])
File "/usr/local/lib/python3.8/dist-packages/pandas/core/generic.py", line 5548, in astype
new_data = self._mgr.astype(dtype=dtype, copy=copy, errors=errors,)
File "/usr/local/lib/python3.8/dist-packages/pandas/core/internals/managers.py", line 604, in astype
return self.apply("astype", dtype=dtype, copy=copy, errors=errors)
File "/usr/local/lib/python3.8/dist-packages/pandas/core/internals/managers.py", line 409, in apply
applied = getattr(b, f)(**kwargs)
File "/usr/local/lib/python3.8/dist-packages/pandas/core/internals/blocks.py", line 595, in astype
values = astype_nansafe(vals1d, dtype, copy=True)
File "/usr/local/lib/python3.8/dist-packages/pandas/core/dtypes/cast.py", line 997, in astype_nansafe
return arr.astype(dtype, copy=True)
ValueError: could not convert string to float: 'East Hannah'
Hello @msgonzaga , we managed to reproduce the following error that you had using your metadata
and generating some dummy values. We will keep you updated on it once we find what causes this problem.
Traceback (most recent call last): File "example_sdv.py", line 59, in <module> sample = multi_table_gen(folder) File "example_sdv.py", line 41, in multi_table_gen model.fit(tables) File "/usr/local/lib/python3.8/dist-packages/sdv/relational/base.py", line 63, in fit self._fit(tables) File "/usr/local/lib/python3.8/dist-packages/sdv/relational/hma.py", line 199, in _fit self._model_table(table_name, tables) File "/usr/local/lib/python3.8/dist-packages/sdv/relational/hma.py", line 164, in _model_table table = self._extend_table(table, tables, table_name) File "/usr/local/lib/python3.8/dist-packages/sdv/relational/hma.py", line 103, in _extend_table extension = self._get_extension(child_name, child_table, child_key) File "/usr/local/lib/python3.8/dist-packages/sdv/relational/hma.py", line 90, in _get_extension model.fit(child_rows.reset_index(drop=True)) File "/usr/local/lib/python3.8/dist-packages/sdv/tabular/base.py", line 112, in fit transformed = self._metadata.transform(data) File "/usr/local/lib/python3.8/dist-packages/sdv/metadata/table.py", line 515, in transform return self._hyper_transformer.transform(data) File "/usr/local/lib/python3.8/dist-packages/rdt/hyper_transformer.py", line 155, in transform transformed = transformer.transform(column) File "/usr/local/lib/python3.8/dist-packages/rdt/transformers/categorical.py", line 174, in transform return data.fillna(np.nan).apply(self._get_value).to_numpy() File "/usr/local/lib/python3.8/dist-packages/pandas/core/series.py", line 4212, in apply mapped = lib.map_infer(values, f, convert=convert_dtype) File "pandas/_libs/lib.pyx", line 2403, in pandas._libs.lib.map_infer File "/usr/local/lib/python3.8/dist-packages/rdt/transformers/categorical.py", line 147, in _get_value mean, std = self.intervals[category][2:] KeyError: nan
I'm trying to create a HMA1 model with the Pubs dataset (https://relational.fit.cvut.cz/dataset/Pubs), but the fitting method is taking too long (over 30 min). I limited the tables to a maximum of 100 rows and the number of columns vary from 3 to 10. I saved the Metadata in json format to make it easier to reproduce.
Here is the metadata.json:
Heres the code I'm using:
I even tried a smaller example, with up to 10 rows for each table, but it is also taking a lot of time. What can I change to make this run faster?
Thank you for your attention