File size: 1,160 Bytes
9cd8c76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from datasets import load_dataset
from huggingface_hub import create_repo, Repository, upload_file
import os
import typer

def main(language_label):
	raw_data = load_dataset("AmazonScience/massive", language_label)
	raw_data = raw_data.rename_column("utt", "text")
	raw_data = raw_data.rename_column("intent", "label")
	raw_data = raw_data.remove_columns(["locale", "partition", "scenario", "annot_utt", 
    									"slot_method", "worker_id", "judgments"])

	#to get labels
	labels = raw_data["train"].features["label"]
	
	#for uploading to hub
	repo_name = "amazon_massive_intent_" + language_label
	create_repo(repo_name, organization="SetFit", repo_type="dataset")

	for split, dataset in raw_data.items():
		dataset = dataset.map(lambda x: {"label_text": labels.int2str(x["label"])}, num_proc=4)
		dataset.to_json(f"{split}.jsonl")
		upload_file(f"{split}.jsonl", path_in_repo=f"{split}.jsonl", repo_id="SetFit/" + repo_name, repo_type="dataset")
		os.system(f"rm {split}.jsonl")

	upload_file("create_dataset.py", path_in_repo="create_dataset.py", repo_id="SetFit/" + repo_name, repo_type="dataset")
	
	


if __name__ == "__main__":
	typer.run(main)