File size: 613 Bytes
8383564
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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()