luketheduke commited on
Commit
40b091e
·
1 Parent(s): 7b2530f

Upload add_translation.py

Browse files
Files changed (1) hide show
  1. add_translation.py +26 -0
add_translation.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_de-DE')
7
+ for split, dset in raw_ds.items():
8
+ if split =='validation':
9
+ label_text = dset['label_text']
10
+ translations = []
11
+ progress = 0
12
+ for text in label_text:
13
+ progress+=1
14
+ if progress%1000 == 0:
15
+ print(progress)
16
+ print(translation)
17
+ text = text.replace("_", " ")
18
+ translation = translator.translate(text, dest='german').text
19
+ translations.append(translation)
20
+ dset = dset.add_column("label_text_de", translations)
21
+ dset.to_json(f"{split}.jsonl")
22
+
23
+ if __name__ == "__main__":
24
+ main()
25
+
26
+