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()