Download data_split.py from lsy641/reddit_mhp: direct link, hf CLI and curl.
- Browser
- Download file 585 Bytes
-
https://huggingface.co/datasets/lsy641/reddit_mhp/resolve/main/data_split.py
- Command line
-
hf download hf://datasets/lsy641/reddit_mhp/data_split.py
-
curl -L -o data_split.py https://huggingface.co/datasets/lsy641/reddit_mhp/resolve/main/data_split.py
585 Bytes
| import json | |
| import random | |
| random.seed(42) | |
| def split_data(): | |
| f = open("./mhp_full.json") | |
| lines = json.load(f) | |
| random.shuffle(lines) | |
| train_data = lines[:int(len(lines)*0.8)] | |
| valid_data = lines[int(len(lines)*0.8):int(len(lines)*0.9)] | |
| test_data = lines[int(len(lines)*0.9):] | |
| print(len(train_data), len(valid_data), len(test_data)) | |
| with open("train.json", "w") as f: | |
| json.dump(train_data, f) | |
| with open("valid.json", "w") as f: | |
| json.dump(valid_data, f) | |
| with open("test.json", "w") as f: | |
| json.dump(test_data, f) | |
| split_data() |