Upload upload.py
Browse files
upload.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import json
|
| 3 |
+
import random
|
| 4 |
+
from datasets import Dataset, DatasetDict
|
| 5 |
+
|
| 6 |
+
# Configuration
|
| 7 |
+
input_folder = "./Raw" # Replace with the path to your folder containing .jsonl files
|
| 8 |
+
train_ratio = 0.8 # 80% for training, 20% for validation
|
| 9 |
+
output_repo = "BXYMartin/OpenHearthstoneLLM" # Replace with your Hugging Face dataset repository name
|
| 10 |
+
|
| 11 |
+
# Load all .jsonl files from the folder
|
| 12 |
+
data = []
|
| 13 |
+
for filename in os.listdir(input_folder):
|
| 14 |
+
if filename.endswith(".jsonl"):
|
| 15 |
+
with open(os.path.join(input_folder, filename), "r", encoding="utf-8") as f:
|
| 16 |
+
for line in f:
|
| 17 |
+
blob = json.loads(line)
|
| 18 |
+
entry = {key: str(value) for key, value in blob.items()}
|
| 19 |
+
data.append(entry)
|
| 20 |
+
|
| 21 |
+
# Shuffle the data
|
| 22 |
+
random.shuffle(data)
|
| 23 |
+
|
| 24 |
+
# Split the data into train and validation sets
|
| 25 |
+
train_size = int(len(data) * train_ratio)
|
| 26 |
+
train_data = data[:train_size]
|
| 27 |
+
val_data = data[train_size:]
|
| 28 |
+
|
| 29 |
+
# Convert to Hugging Face Dataset
|
| 30 |
+
train_dataset = Dataset.from_list(train_data)
|
| 31 |
+
val_dataset = Dataset.from_list(val_data)
|
| 32 |
+
|
| 33 |
+
# Create a DatasetDict
|
| 34 |
+
dataset_dict = DatasetDict({
|
| 35 |
+
"train": train_dataset,
|
| 36 |
+
"validation": val_dataset
|
| 37 |
+
})
|
| 38 |
+
|
| 39 |
+
# Push to Hugging Face Hub
|
| 40 |
+
dataset_dict.push_to_hub(output_repo)
|
| 41 |
+
|
| 42 |
+
print(f"Dataset pushed to Hugging Face Hub: {output_repo}")
|