File size: 715 Bytes
7c163db 3fdf5d7 7c163db 3fdf5d7 7c163db |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
from datasets import DatasetDict, load_dataset
def main():
label2id = {"positive": 2, "neutral": 1, "negative": 0}
train_dset = load_dataset("csv", data_files="raw_data/train_csv", split="train")
train_dset = train_dset.remove_columns(["selected_text"])
test_dset = load_dataset("csv", data_files="raw_data/train_csv", split="train")
raw_dset = DatasetDict()
raw_dset["train"] = train_dset
raw_dset["test"] = test_dset
for split, dset in raw_dset.items():
dset = dset.rename_column("sentiment", "label_text")
dset = dset.map(lambda x: {"label": label2id[x["label_text"]]}, num_proc=8)
dset.to_json(f"{split}.jsonl")
if __name__ == "__main__":
main()
|