Views
No views yet
1#Load model directly
2from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
4tokenizer = AutoTokenizer.from_pretrained("onlysainaa/cyrillic_to_script-t5-model")
5model = AutoModelForSeq2SeqLM.from_pretrained("onlysainaa/cyrillic_to_script-t5-model")
6
7#Check if CUDA (GPU) is available
8device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
9
10#Move the model to the same device (GPU or CPU)
11model.to(device)
12
13#Prepare text input
14input_text = "сайн уу" #Mongolian greeting
15
16#Tokenize the input text
17inputs = tokenizer(input_text, return_tensors="pt")
18
19#Move the input tensors to the same device as the model
20inputs = {k: v.to(device) for k, v in inputs.items() if k in ['input_ids', 'attention_mask']}
21
22#Generate translation
23outputs = model.generate(**inputs)
24
25#Decode the output to human-readable text
26translated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
27
28#Print the translated text
29print(f"Translated Text: {translated_text}")