| 32 | |
| 33 | |
| 34 | def transform_json(input_path, output_path): |
| 35 | # Read the input JSON file |
| 36 | with open(input_path, 'r', encoding='utf-8') as f: |
| 37 | data = json.load(f) |
| 38 | |
| 39 | # Transform the data |
| 40 | transformed_data = [] |
| 41 | for item in data: |
| 42 | transformed_item = { |
| 43 | 'prompt': item['sentence'], |
| 44 | 'answer': item['label'] |
| 45 | } |
| 46 | transformed_data.append(transformed_item) |
| 47 | |
| 48 | # Write the transformed data to output file |
| 49 | with open(output_path, 'w', encoding='utf-8') as f: |
| 50 | json.dump(transformed_data, f, ensure_ascii=False, indent=2) |
| 51 | |
| 52 | |
| 53 | def process_directory(directory_path): |