| | |
| | """ |
| | Fix dataset format for training - ensure consistent structure |
| | """ |
| |
|
| | import json |
| | from pathlib import Path |
| |
|
| | def fix_dataset_format(file_path): |
| | """Ensure all examples have consistent message format""" |
| | fixed_data = [] |
| | |
| | with open(file_path, 'r') as f: |
| | for line in f: |
| | try: |
| | data = json.loads(line) |
| | |
| | |
| | if 'messages' not in data: |
| | print(f"Skipping entry without 'messages': {data}") |
| | continue |
| | |
| | |
| | valid_messages = [] |
| | for msg in data['messages']: |
| | if 'role' in msg and 'content' in msg: |
| | valid_messages.append(msg) |
| | else: |
| | print(f"Skipping invalid message: {msg}") |
| | |
| | if valid_messages: |
| | data['messages'] = valid_messages |
| | |
| | |
| | if 'metadata' not in data: |
| | data['metadata'] = { |
| | 'category': 'unknown', |
| | 'source': 'fixed_format' |
| | } |
| | |
| | fixed_data.append(data) |
| | |
| | except json.JSONDecodeError as e: |
| | print(f"JSON decode error: {e}") |
| | continue |
| | |
| | |
| | fixed_path = file_path.replace('.jsonl', '_fixed.jsonl') |
| | with open(fixed_path, 'w') as f: |
| | for entry in fixed_data: |
| | f.write(json.dumps(entry, ensure_ascii=False) + '\n') |
| | |
| | print(f"Fixed {len(fixed_data)} examples in {fixed_path}") |
| | return fixed_path |
| |
|
| | |
| | train_fixed = fix_dataset_format("/home/x/adaptai/aiml/e-train-1/combined_training_data.jsonl") |
| | val_fixed = fix_dataset_format("/home/x/adaptai/aiml/e-train-1/combined_val.jsonl") |
| |
|
| | print(f"✅ Fixed training data: {train_fixed}") |
| | print(f"✅ Fixed validation data: {val_fixed}") |