xglue_nc / create_dataset.py
Unso's picture
Upload create_dataset.py
8383564
raw
history blame
613 Bytes
from datasets import load_dataset
import numpy as np
def main():
raw_data = load_dataset("xglue", "nc")
raw_data = raw_data.rename_column("news_body", "text")
raw_data = raw_data.remove_columns(["news_title"])
raw_data = raw_data.rename_column("news_category", "label")
labels = raw_data["train"].features["label"]
for split, dataset in raw_data.items():
len_data = len(dataset)
dataset = dataset.add_column("id", np.arange(len_data))
dataset = dataset.map(lambda x: {"label_text": labels.int2str(x["label"])}, num_proc=4)
dataset.to_json(f"{split}.jsonl")
if __name__ == "__main__":
main()