File size: 620 Bytes
927ee68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = AutoTokenizer.from_pretrained("rudrashah/RLM-hinglish-translator")
model = AutoModelForCausalLM.from_pretrained("rudrashah/RLM-hinglish-translator")

text = "mere paas 100 rupaye hain"

template = "Hinglish:\n{hi_en}\n\nEnglish:\n{en}"
input_text = tokenizer(template.format(hi_en=text,en=""),return_tensors="pt")

output = model.generate(**input_text, max_length=250)
english = tokenizer.decode(output[0])
english = english.replace("<bos>","").replace("<eos>","")
english = english[len(template.format(hi_en=text,en="")):]
print(english.strip())