| import pandas as pd | |
| from collections import Counter | |
| import json | |
| import random | |
| df = pd.read_csv("original.csv") | |
| print(df) | |
| rows = [{'qid': row['qid'], | |
| 'text': row['question_text'].strip(), | |
| 'label': row['target'], | |
| 'label_text': "insincere question" if row['target'] else "valid question", | |
| } for idx, row in df.iterrows()] | |
| random.seed(42) | |
| random.shuffle(rows) | |
| num_test = 50000 | |
| splits = {'test': rows[0:num_test], 'train': rows[num_test:]} | |
| print("Train:", len(splits['train'])) | |
| print("Test:", len(splits['test'])) | |
| num_labels = Counter() | |
| for row in splits['test']: | |
| num_labels[row['label']] += 1 | |
| print(num_labels) | |
| for split in ['train', 'test']: | |
| with open(f'{split}.jsonl', 'w') as fOut: | |
| for row in splits[split]: | |
| fOut.write(json.dumps(row)+"\n") |