Unso commited on
Commit
9cd8c76
1 Parent(s): 625e2d0

Upload create_dataset.py

Browse files
Files changed (1) hide show
  1. create_dataset.py +34 -0
create_dataset.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset
2
+ from huggingface_hub import create_repo, Repository, upload_file
3
+ import os
4
+ import typer
5
+
6
+ def main(language_label):
7
+ raw_data = load_dataset("AmazonScience/massive", language_label)
8
+ raw_data = raw_data.rename_column("utt", "text")
9
+ raw_data = raw_data.rename_column("intent", "label")
10
+ raw_data = raw_data.remove_columns(["locale", "partition", "scenario", "annot_utt",
11
+ "slot_method", "worker_id", "judgments"])
12
+
13
+ #to get labels
14
+ labels = raw_data["train"].features["label"]
15
+
16
+ #for uploading to hub
17
+ repo_name = "amazon_massive_intent_" + language_label
18
+ create_repo(repo_name, organization="SetFit", repo_type="dataset")
19
+
20
+ for split, dataset in raw_data.items():
21
+ dataset = dataset.map(lambda x: {"label_text": labels.int2str(x["label"])}, num_proc=4)
22
+ dataset.to_json(f"{split}.jsonl")
23
+ upload_file(f"{split}.jsonl", path_in_repo=f"{split}.jsonl", repo_id="SetFit/" + repo_name, repo_type="dataset")
24
+ os.system(f"rm {split}.jsonl")
25
+
26
+ upload_file("create_dataset.py", path_in_repo="create_dataset.py", repo_id="SetFit/" + repo_name, repo_type="dataset")
27
+
28
+
29
+
30
+
31
+ if __name__ == "__main__":
32
+ typer.run(main)
33
+
34
+