luketheduke
commited on
Commit
•
93dfb48
1
Parent(s):
2c96056
Upload add_translation.py
Browse files- 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_es-ES')
|
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='spanish').text
|
18 |
+
translations.append(translation)
|
19 |
+
dset = dset.add_column("label_text_es", translations)
|
20 |
+
dset.to_json(f"{split}.jsonl")
|
21 |
+
|
22 |
+
if __name__ == "__main__":
|
23 |
+
main()
|
24 |
+
|
25 |
+
|