Spaces:
Runtime error
Runtime error
File size: 742 Bytes
58de6bb 48501ce 58de6bb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# import gradio as gr
# gr.load("models/balaramas/mbart-large-finetune-eng-hin").launch()
from transformers import MBartForConditionalGeneration, MBart50TokenizerFast
article_en = "The head of the United Nations says there is no military solution in Syria"
model = MBartForConditionalGeneration.from_pretrained("facebook/mbart-large-50-one-to-many-mmt")
tokenizer = MBart50TokenizerFast.from_pretrained("facebook/mbart-large-50-one-to-many-mmt", src_lang="en_XX")
model_inputs = tokenizer(article_en, return_tensors="pt")
# translate from English to Hindi
generated_tokens = model.generate(
**model_inputs,
forced_bos_token_id=tokenizer.lang_code_to_id["hi_IN"]
)
tokenizer.batch_decode(generated_tokens, skip_special_tokens=True) |