File size: 770 Bytes
93dfb48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from datasets import load_dataset
from googletrans import Translator

def main():
    translator = Translator()
    raw_ds = load_dataset('SetFit/amazon_massive_intent_es-ES')
    for split, dset in raw_ds.items():  
        label_text = dset['label_text']
        translations = []
        progress = 0
        for text in label_text:
            progress+=1
            if progress%1000 == 0:
                print(progress)
                print(translation)
            text = text.replace("_", " ")
            translation = translator.translate(text, dest='spanish').text
            translations.append(translation)
        dset = dset.add_column("label_text_es", translations)        
        dset.to_json(f"{split}.jsonl")

if __name__ == "__main__":
	main()