|
import os |
|
import json |
|
from datasets import load_dataset |
|
|
|
os.makedirs("data/tweet_topic", exist_ok=True) |
|
data = load_dataset("cardiffnlp/tweet_topic_multi") |
|
|
|
|
|
def process(tmp): |
|
tmp.pop("id") |
|
tmp.pop("label_name") |
|
tmp = [i.to_dict() for _, i in tmp.iterrows()] |
|
for i in tmp: |
|
i['gold_label_list'] = i.pop('label').tolist() |
|
return tmp |
|
|
|
train = process(data["train_2020"].to_pandas()) |
|
val = process(data["validation_2020"].to_pandas()) |
|
test = process(data["test_2021"].to_pandas()) |
|
with open("data/tweet_topic/train.jsonl", "w") as f: |
|
f.write("\n".join([json.dumps(i) for i in train])) |
|
with open("data/tweet_topic/validation.jsonl", "w") as f: |
|
f.write("\n".join([json.dumps(i) for i in val])) |
|
with open("data/tweet_topic/test.jsonl", "w") as f: |
|
f.write("\n".join([json.dumps(i) for i in test])) |
|
|
|
|
|
|
|
|