Download prepare_data.py from SetFit/hate_speech_offensive: direct link, hf CLI and curl.
- Browser
- Download file 568 Bytes
-
https://huggingface.co/datasets/SetFit/hate_speech_offensive/resolve/main/prepare_data.py
- Command line
-
hf download hf://datasets/SetFit/hate_speech_offensive/prepare_data.py
-
curl -L -o prepare_data.py https://huggingface.co/datasets/SetFit/hate_speech_offensive/resolve/main/prepare_data.py
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") |