Generating Realistic Tabular Data using Large Language Models
Project description
Generation of Realistic Tabular data
with pretrained Transformer-based language models
Our GReaT framework leverages the power of advanced pretrained Transformer language models to produce high-quality synthetic tabular data. Generate new data samples effortlessly with our user-friendly API in just a few lines of code. Please see our publication for more details.
GReaT Installation
The GReaT framework can be easily installed using with pip - requires a Python version >= 3.9:
pip install be-great
GReaT Quickstart
In the example below, we show how the GReaT approach is used to generate synthetic tabular data for the California Housing dataset.
from be_great import GReaT
from sklearn.datasets import fetch_california_housing
data = fetch_california_housing(as_frame=True).frame
model = GReaT(llm='distilgpt2', batch_size=32, epochs=50, fp16=True)
model.fit(data)
synthetic_data = model.sample(n_samples=100)
Imputing a sample
GReaT also features an interface to impute, i.e., fill in, missing values in arbitrary combinations. This requires a trained model
, for instance one obtained using the code snippet above, and a pd.DataFrame
where missing values are set to NaN.
A minimal example is provided below:
# test_data: pd.DataFrame with samples from the distribution
# model: GReaT trained on the data distribution that should be imputed
# Drop values randomly from test_data
import numpy as np
for clm in test_data.columns:
test_data[clm]=test_data[clm].apply(lambda x: (x if np.random.rand() > 0.5 else np.nan))
imputed_data = model.impute(test_data, max_length=200)
Saving and Loading
GReaT provides methods for saving a model checkpoint (besides the checkpoints stored by the huggingface transformers Trainer) and loading the checkpoint again.
model = GReaT(llm='distilgpt2', batch_size=32, epochs=50, fp16=True)
model.fit(data)
model.save("my_directory") # saves a "model.pt" and a "config.json" file
model = GReaT.load_from_dir("my_directory") # loads the model again
# supports remote file systems via fsspec
model.save("s3://my_bucket")
model = GReaT.load_from_dir("s3://my_bucket")
GReaT Citation
If you use GReaT, please link or cite our work:
@inproceedings{borisov2023language,
title={Language Models are Realistic Tabular Data Generators},
author={Vadim Borisov and Kathrin Sessler and Tobias Leemann and Martin Pawelczyk and Gjergji Kasneci},
booktitle={The Eleventh International Conference on Learning Representations },
year={2023},
url={https://openreview.net/forum?id=cEygmQNOeI}
}
GReaT Acknowledgements
We sincerely thank the HuggingFace :hugs: framework.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file be_great-0.0.8.tar.gz
.
File metadata
- Download URL: be_great-0.0.8.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c50cbba8ac512f38c35814add41565ba24361c641cd669fe210dc120fa60dd1 |
|
MD5 | 294c4e8d6f742d5bcf1a78d3adf96aab |
|
BLAKE2b-256 | c679244bc593c4854264c866d6d7078c29cdddf7e23ce325e0aeb220153ed066 |
File details
Details for the file be_great-0.0.8-py3-none-any.whl
.
File metadata
- Download URL: be_great-0.0.8-py3-none-any.whl
- Upload date:
- Size: 16.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68e515b388254ef930bca272b929156fb901873fcdbcfeef56d7ad3d78d4c2b0 |
|
MD5 | 8dee7b1ee850080890277c334ac5283e |
|
BLAKE2b-256 | 224d61db5b59f132221334927e1845fe63fbcb97be62aaa01a68c086919b9445 |