File size: 776 Bytes
c715a2b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_ru-RU')
    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='russian').text
            translations.append(translation)
        dset = dset.add_column("label_text_ru", translations)        
        dset.to_json(f"{split}.jsonl")

if __name__ == "__main__":
    main()