Save processed data to output directory
(data_splits: Dict[str, List[Dict]], output_dir: str)
| 110 | |
| 111 | |
| 112 | def save_data(data_splits: Dict[str, List[Dict]], output_dir: str): |
| 113 | """Save processed data to output directory""" |
| 114 | os.makedirs(output_dir, exist_ok=True) |
| 115 | |
| 116 | for split_name, split_data in data_splits.items(): |
| 117 | if not split_data: # Skip empty splits |
| 118 | continue |
| 119 | |
| 120 | # Save as JSON |
| 121 | json_path = os.path.join(output_dir, f"{split_name}.json") |
| 122 | with open(json_path, 'w') as f: |
| 123 | json.dump(split_data, f, indent=2, ensure_ascii=False) |
| 124 | |
| 125 | # Save as Parquet (compatible with existing data format) |
| 126 | parquet_path = os.path.join(output_dir, f"{split_name}.parquet") |
| 127 | df = pd.DataFrame(split_data) |
| 128 | df.to_parquet(parquet_path, index=False) |
| 129 | |
| 130 | print(f"Saved {len(split_data)} {split_name} samples to {json_path} and {parquet_path}") |
| 131 | |
| 132 | |
| 133 | def analyze_data(data: List[Dict]): |