Download combine.py from rombodawg/data_processing_code: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/datasets/rombodawg/data_processing_code/resolve/main/combine.py
- Command line
-
hf download hf://datasets/rombodawg/data_processing_code/combine.py
-
curl -L -o combine.py https://huggingface.co/datasets/rombodawg/data_processing_code/resolve/main/combine.py
1.12 kB
| import json | |
| import multiprocessing | |
| # Define the input files | |
| input_files = [ | |
| 'OpenHermes-2.5-Uncensored.json', | |
| 'code_bagel.json' | |
| ] | |
| # Define the output file | |
| output_file = 'code_bagel_hermes-2.5.json' | |
| def process_file(file, output_data): | |
| with open(file, 'r', encoding='utf-8') as f: | |
| for line in f: | |
| data = json.loads(line) | |
| instruction = data['instruction'] | |
| input_data = data['input'] | |
| output = data['output'] | |
| output_data.append({ | |
| "instruction": instruction, | |
| "input": input_data, | |
| "output": output | |
| }) | |
| if __name__ == '__main__': | |
| with multiprocessing.Manager() as manager: | |
| output_data = manager.list() | |
| with multiprocessing.Pool(processes=12) as pool: | |
| pool.starmap(process_file, [(file, output_data) for file in input_files]) | |
| with open(output_file, 'w') as f: | |
| for obj in output_data: | |
| json.dump(obj, f) | |
| f.write('\n') # Write a newline character after each object |