risha_testing / translation.py
rishach's picture
Upload full fitnetuned model + tokenizer +generation config
2133a03 verified
Raw
History Blame Contribute Delete
1.14 kB
from transformers import pipeline
# ────────────────────────────────────────────────────────────────
# 6. Translation (example: English β†’ Hindi)
# ────────────────────────────────────────────────────────────────
# No universal default β†’ always specify model
#
# Popular choice: Helsinki-NLP/opus-mt-en-hi
# → Used for: good quality general-domain English→Hindi translation
# fast & reliable for everyday sentences
#
# Better alternative (2025+): facebook/mbart-large-50-many-to-many-mmt
# β†’ Used for: many-to-many (50 languages), better with low-resource pairs
pipe = pipeline("translation_en_to_hi", model="Helsinki-NLP/opus-mt-en-hi")
# pipe = pipeline("translation", model="facebook/mbart-large-50-many-to-many-mmt", src_lang="en_XX", tgt_lang="hi_IN")
print(pipe("Hello from Ludhiana, the city of cycles!")[0]["translation_text"])