Download load_data.py from lhnjames/space020: direct link, hf CLI and curl.
- Browser
- Download file 595 Bytes
-
https://huggingface.co/spaces/lhnjames/space020/resolve/main/load_data.py
- Command line
-
hf download hf://spaces/lhnjames/space020/load_data.py
-
curl -L -o load_data.py https://huggingface.co/spaces/lhnjames/space020/resolve/main/load_data.py
595 Bytes
| import json | |
| def load_data(file_path='train.json',num_samples=2000): | |
| data = [] | |
| with open(file_path, 'r', encoding='utf-8') as file: | |
| for line in file: | |
| try: | |
| data.append(json.loads(line)) | |
| except json.JSONDecodeError as e: | |
| print(f"Error decoding JSON: {e}") | |
| return data[:num_samples] | |
| if __name__ == '__main__': | |
| #数据集切分 | |
| dataset = load_data() | |
| with open('train_2000.json', 'w', encoding='utf-8') as file: | |
| for item in dataset: | |
| file.write(json.dumps(item, ensure_ascii=False) + '\n') |