Download add_translation.py from SetFit/amazon_massive_intent_ja-JP: direct link, hf CLI and curl.
- Browser
- Download file 774 Bytes
-
https://huggingface.co/datasets/SetFit/amazon_massive_intent_ja-JP/resolve/main/add_translation.py
- Command line
-
hf download hf://datasets/SetFit/amazon_massive_intent_ja-JP/add_translation.py
-
curl -L -o add_translation.py https://huggingface.co/datasets/SetFit/amazon_massive_intent_ja-JP/resolve/main/add_translation.py
774 Bytes
| from datasets import load_dataset | |
| from googletrans import Translator | |
| def main(): | |
| translator = Translator() | |
| raw_ds = load_dataset('SetFit/amazon_massive_intent_ja-JP') | |
| 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='japanese').text | |
| translations.append(translation) | |
| dset = dset.add_column("label_text_jp", translations) | |
| dset.to_json(f"{split}.jsonl") | |
| if __name__ == "__main__": | |
| main() | |