Unso commited on
Commit
8383564
·
1 Parent(s): f469625

Upload create_dataset.py

Browse files
Files changed (1) hide show
  1. create_dataset.py +21 -0
create_dataset.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset
2
+ import numpy as np
3
+
4
+
5
+ def main():
6
+
7
+ raw_data = load_dataset("xglue", "nc")
8
+ raw_data = raw_data.rename_column("news_body", "text")
9
+ raw_data = raw_data.remove_columns(["news_title"])
10
+ raw_data = raw_data.rename_column("news_category", "label")
11
+ labels = raw_data["train"].features["label"]
12
+
13
+ for split, dataset in raw_data.items():
14
+ len_data = len(dataset)
15
+ dataset = dataset.add_column("id", np.arange(len_data))
16
+ dataset = dataset.map(lambda x: {"label_text": labels.int2str(x["label"])}, num_proc=4)
17
+ dataset.to_json(f"{split}.jsonl")
18
+
19
+ if __name__ == "__main__":
20
+ main()
21
+