Views
No views yet
1import torch
2from transformers import pipeline, MT5ForConditionalGeneration, MT5Tokenizer, Text2TextGenerationPipeline
3
4# Function to translate using the pipeline
5def translate_with_pipeline(text):
6 translator = Text2TextGenerationPipeline(model='NLPclass/mt5_en_fa_translation',tokenizer='NLPclass/mt5_en_fa_translation')
7 return translator(text,, max_length=128,num_beams=4)[0]['generated_text']
8
9
10# Example usage
11text = "Hello, how are you?"
12
13# Using pipeline
14print("Pipeline Translation:", translate_with_pipeline(text))1@misc{mt5_en_fa_translation,
2 author = {mansoorhamidzadeh},
3 title = {English to Persian Translation using MT5-Small},
4 year = {2024},
5 publisher = {Hugging Face},
6 howpublished = {\url{https://huggingface.co/mansoorhamidzadeh/mt5_en_fa_translation}},
7}