luketheduke commited on
Commit
64527c2
1 Parent(s): 9cd8c76

Upload add_translation.py

Browse files
Files changed (1) hide show
  1. add_translation.py +25 -0
add_translation.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_zh-CN')
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
+ print(translation)
16
+ text = text.replace("_", " ")
17
+ translation = translator.translate(text, dest='zh-cn').text
18
+ translations.append(translation)
19
+ dset = dset.add_column("label_text_ch", translations)
20
+ dset.to_json(f"{split}.jsonl")
21
+
22
+ if __name__ == "__main__":
23
+ main()
24
+
25
+