luketheduke commited on
Commit
88c4768
·
1 Parent(s): 33917f7

Upload add_translation.py

Browse files
Files changed (1) hide show
  1. add_translation.py +24 -0
add_translation.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset
2
+ from googletrans import Translator
3
+
4
+ def main():
5
+ translator = Translator()
6
+ raw_ds = load_dataset('SetFit/amazon_massive_intent_ar-SA')
7
+ for split, dset in raw_ds.items():
8
+ label_text = dset['label_text']
9
+ translations = []
10
+ progress = 0
11
+ for text in label_text:
12
+ progress+=1
13
+ if progress%1000 == 0:
14
+ print(progress)
15
+ text = text.replace("_", " ")
16
+ translation = translator.translate(text, dest='arabic').text
17
+ translations.append(translation)
18
+ dset = dset.add_column("label_text_ar", translations)
19
+ dset.to_json(f"{split}.jsonl")
20
+
21
+ if __name__ == "__main__":
22
+ main()
23
+
24
+