hate_speech_offensive / prepare_data.py
nreimers's picture
upload
d0dafd0
raw
history blame contribute delete
568 Bytes
from datasets import load_dataset
import json
import random
dataset = load_dataset("hate_speech_offensive")
id2label = dataset['train'].features['class'].names
rows = [{'text': row['tweet'], 'label': row['class'], 'label_text': id2label[row['class']]} for row in dataset['train']]
random.shuffle(rows)
num_test = 2000
data_splits = {'test': rows[0:num_test], 'train': rows[num_test:]}
for split in data_splits.keys():
with open(f'{split}.jsonl', 'w') as fOut:
for row in data_splits[split]:
fOut.write(json.dumps(row)+"\n")