from datasets import Dataset
# Prepare your dataset as a dictionary
dataset_dict = {
"text": ["Example sentence 1", "Example sentence 2"],
"label": [0, 1] # Example labels
}
# Create a Hugging Face Dataset object
dataset = Dataset.from_dict(dataset_dict)
# Save the dataset
dataset.save_to_disk("path/to/save/dataset")
# Optionally, you can upload the dataset to the Hugging Face Hub
# First, install the huggingface_hub library: pip install huggingface_hub
from huggingface_hub import HfApi, Repository
api = HfApi()
repo_url = api.create_repo(token="YOUR_HUB_TOKEN", name="my_dataset_name")
repository = Repository(repo_url)
repository.push_from_folder("path/to/save/dataset")