Create create_tiny_dataset.py
Browse files- create_tiny_dataset.py +28 -0
create_tiny_dataset.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from datasets import load_dataset
|
2 |
+
from datasets import Dataset
|
3 |
+
|
4 |
+
# 1. Load the en split of C4 with streaming
|
5 |
+
ds = load_dataset("allenai/c4", "en", split="train", streaming=True)
|
6 |
+
|
7 |
+
# 2. Take first 10k examples and convert to regular dataset
|
8 |
+
ds_small = list(ds.take(10000)) # take first 10k examples
|
9 |
+
ds_small = Dataset.from_list(ds_small) # convert to regular Dataset
|
10 |
+
assert len(ds_small) == 10000
|
11 |
+
print("Sample example:", ds_small[0])
|
12 |
+
|
13 |
+
# 4. Push to the Hub
|
14 |
+
repo_name = "boom-project/c4-en-10k-debug"
|
15 |
+
|
16 |
+
ds_small.push_to_hub(
|
17 |
+
repo_id=repo_name,
|
18 |
+
token=True, # uses the token from `huggingface-cli login`
|
19 |
+
private=False,
|
20 |
+
)
|
21 |
+
|
22 |
+
print(f"✅ Pushed 10,000-example C4 subset to https://huggingface.co/{repo_name}")
|
23 |
+
|
24 |
+
# After pushing to the Hub, verify the dataset size and inspect one example
|
25 |
+
# from datasets import load_dataset
|
26 |
+
# ds = load_dataset("boom-project/c4-en-10k-debug", split="train")
|
27 |
+
# assert len(ds) == 10000
|
28 |
+
# print("Sample example:", ds[0])
|