Update README.md
Browse files
README.md
CHANGED
|
@@ -28,32 +28,34 @@ This is the model card of a 🤗 transformers model that has been pushed on the
|
|
| 28 |
- **Finetuned from model [google-t5-small]:** [More Information Needed]
|
| 29 |
|
| 30 |
|
| 31 |
-
|
|
|
|
| 32 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 33 |
|
| 34 |
tokenizer = AutoTokenizer.from_pretrained("onlysainaa/cyrillic_to_script-t5-model")
|
| 35 |
model = AutoModelForSeq2SeqLM.from_pretrained("onlysainaa/cyrillic_to_script-t5-model")
|
| 36 |
|
| 37 |
-
|
| 38 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 39 |
|
| 40 |
-
|
| 41 |
model.to(device)
|
| 42 |
|
| 43 |
-
|
| 44 |
-
input_text = "сайн уу"
|
| 45 |
|
| 46 |
-
|
| 47 |
inputs = tokenizer(input_text, return_tensors="pt")
|
| 48 |
|
| 49 |
-
|
| 50 |
inputs = {k: v.to(device) for k, v in inputs.items() if k in ['input_ids', 'attention_mask']}
|
| 51 |
|
| 52 |
-
|
| 53 |
outputs = model.generate(**inputs)
|
| 54 |
|
| 55 |
-
|
| 56 |
translated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 57 |
|
| 58 |
-
|
| 59 |
-
print(f"Translated Text: {translated_text}")
|
|
|
|
|
|
| 28 |
- **Finetuned from model [google-t5-small]:** [More Information Needed]
|
| 29 |
|
| 30 |
|
| 31 |
+
```
|
| 32 |
+
#Load model directly
|
| 33 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 34 |
|
| 35 |
tokenizer = AutoTokenizer.from_pretrained("onlysainaa/cyrillic_to_script-t5-model")
|
| 36 |
model = AutoModelForSeq2SeqLM.from_pretrained("onlysainaa/cyrillic_to_script-t5-model")
|
| 37 |
|
| 38 |
+
#Check if CUDA (GPU) is available
|
| 39 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 40 |
|
| 41 |
+
#Move the model to the same device (GPU or CPU)
|
| 42 |
model.to(device)
|
| 43 |
|
| 44 |
+
#Prepare text input
|
| 45 |
+
input_text = "сайн уу" #Mongolian greeting
|
| 46 |
|
| 47 |
+
#Tokenize the input text
|
| 48 |
inputs = tokenizer(input_text, return_tensors="pt")
|
| 49 |
|
| 50 |
+
#Move the input tensors to the same device as the model
|
| 51 |
inputs = {k: v.to(device) for k, v in inputs.items() if k in ['input_ids', 'attention_mask']}
|
| 52 |
|
| 53 |
+
#Generate translation
|
| 54 |
outputs = model.generate(**inputs)
|
| 55 |
|
| 56 |
+
#Decode the output to human-readable text
|
| 57 |
translated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 58 |
|
| 59 |
+
#Print the translated text
|
| 60 |
+
print(f"Translated Text: {translated_text}")
|
| 61 |
+
```
|